aboutsummaryrefslogtreecommitdiff
path: root/build2/file.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-01-23 08:21:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-01-23 08:21:53 +0200
commit91495e646c688eade6b46f21bb40e3da8b8d6f1a (patch)
tree6cfafe23d2ca8a3d2c889961c8df0fffc128c4f7 /build2/file.cxx
parent699e3bc87d1cbb3c2b19ddaf5db37909cb49f47b (diff)
Implement automatic loading of directory buildfiles
Now instead of explicitly writing: d = foo/ bar/ ./: $d include $d We can (usually) just write: ./: foo/ bar/
Diffstat (limited to 'build2/file.cxx')
-rw-r--r--build2/file.cxx49
1 files changed, 46 insertions, 3 deletions
diff --git a/build2/file.cxx b/build2/file.cxx
index 2889cf7..527f752 100644
--- a/build2/file.cxx
+++ b/build2/file.cxx
@@ -114,10 +114,10 @@ namespace build2
void
source (const path& bf, scope& root, scope& base)
{
- return source (bf, root, base, false);
+ source (bf, root, base, false);
}
- void
+ bool
source_once (const path& bf, scope& root, scope& base, scope& once)
{
tracer trace ("source_once");
@@ -125,10 +125,11 @@ namespace build2
if (!once.buildfiles.insert (bf).second)
{
l5 ([&]{trace << "skipping already sourced " << bf;});
- return;
+ return false;
}
source (bf, root, base);
+ return true;
}
scope&
@@ -253,6 +254,48 @@ namespace build2
return s;
}
+ pair<scope&, scope*>
+ switch_scope (scope& root, const dir_path& p)
+ {
+ // First, enter the scope into the map and see if it is in any project. If
+ // it is not, then there is nothing else to do.
+ //
+ auto i (scopes.insert (p, false));
+ scope& base (i->second);
+ scope* rs (base.root_scope ());
+
+ if (rs != nullptr)
+ {
+ // Path p can be src_base or out_base. Figure out which one it is.
+ //
+ dir_path out_base (p.sub (rs->out_path ()) ? p : src_out (p, *rs));
+
+ // Create and bootstrap root scope(s) of subproject(s) that this scope
+ // may belong to. If any were created, load them. Note that we need to
+ // do this before figuring out src_base since we may switch the root
+ // project (and src_root with it).
+ //
+ {
+ scope* nrs (&create_bootstrap_inner (*rs, out_base));
+
+ if (rs != nrs)
+ rs = nrs;
+ }
+
+ // Switch to the new root scope.
+ //
+ if (rs != &root)
+ load_root_pre (*rs); // Load new root(s) recursively.
+
+ // Now we can figure out src_base and finish setting the scope.
+ //
+ dir_path src_base (src_out (out_base, *rs));
+ setup_base (i, move (out_base), move (src_base));
+ }
+
+ return pair<scope&, scope*> (base, rs);
+ }
+
void
bootstrap_out (scope& root)
{