From 9e6303e86dae25096ee62d74abfca4456be6a96f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Apr 2015 14:51:53 +0200 Subject: Initial support for amalgamation/subprojects For now both need to be manually specified in src bootstrap. At this stage main() loads any outer root scopes while include loads any inner. --- build/file.cxx | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 4 deletions(-) (limited to 'build/file.cxx') diff --git a/build/file.cxx b/build/file.cxx index 7bb8bb6..0b0220d 100644 --- a/build/file.cxx +++ b/build/file.cxx @@ -53,16 +53,111 @@ namespace build source (bf, root, base); } - void - root_pre (scope& root) + scope& + create_root (const path& out_root, const path& src_root) { - tracer trace ("root_pre"); + scope& rs (scopes.insert (out_root, true).first); + + // Enter built-in meta-operation and operation names. Note that + // the order of registration should match the id constants; see + // for details. Loading of modules (via the src + // bootstrap; see below) can result in additional names being + // added. + // + if (rs.meta_operations.empty ()) + { + assert (rs.meta_operations.insert (perform) == perform_id); - path bf (root.src_path () / path ("build/root.build")); + assert (rs.operations.insert (default_) == default_id); + assert (rs.operations.insert (update) == update_id); + assert (rs.operations.insert (clean) == clean_id); + } + + // If this is already a root scope, verify that things are + // consistent. + // + { + auto v (rs.variables["out_root"]); + + if (!v) + v = out_root; + else + { + const path& p (v.as ()); + + if (p != out_root) + fail << "new out_root " << out_root << " does not match " + << "existing " << p; + } + } + + if (!src_root.empty ()) + { + auto v (rs.variables["src_root"]); + + if (!v) + v = src_root; + else + { + const path& p (v.as ()); + + if (p != src_root) + fail << "new src_root " << src_root << " does not match " + << "existing " << p; + } + } + + return rs; + } + + void + bootstrap_out (scope& root) + { + path bf (root.path () / path ("build/bootstrap/src-root.build")); if (!file_exists (bf)) return; + //@@ TODO: if bootstrap files can source other bootstrap files + // (the way to express dependecies), then we need a way to + // prevent multiple sourcing. We handle it here but we still + // need something like source_once (once [scope] source). + // source_once (bf, root, root); } + + bool + bootstrap_src (scope& root) + { + tracer trace ("bootstrap_src"); + + path bf (root.src_path () / path ("build/bootstrap.build")); + + if (!file_exists (bf)) + return false; + + // We assume that bootstrap out cannot load this file explicitly. It + // feels wrong to allow this since that makes the whole bootstrap + // process hard to reason about. But we may try to bootstrap the + // same root scope multiple time. + // + source_once (bf, root, root); + return true; + } + + void + root_pre (scope& root) + { + tracer trace ("root_pre"); + + // First load outer roots, if any. + // + if (scope* rs = root.parent_scope ()->root_scope ()) + root_pre (*rs); + + path bf (root.src_path () / path ("build/root.build")); + + if (file_exists (bf)) + source_once (bf, root, root); + } } -- cgit v1.1