aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-25 18:02:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-25 18:02:16 +0200
commit65e8ed3aaf9ed05bc1bc99d9e5111b0c7d6cadb4 (patch)
treec3034c2385fc9336f95a2cd4a187c5e7eda4191e
parent7c97f36e205941163584484d2d933bf9cf41df47 (diff)
Add support for searching subprojects of amalgamation for imported projects
Currently only top-level subproject are considered.
-rw-r--r--build2/file.cxx84
1 files changed, 51 insertions, 33 deletions
diff --git a/build2/file.cxx b/build2/file.cxx
index 9a5ab80..45c3a5e 100644
--- a/build2/file.cxx
+++ b/build2/file.cxx
@@ -780,7 +780,6 @@ namespace build2
// Figure out this project's out_root.
//
dir_path out_root;
- dir_path fallback_src_root; // We have seen this already, haven't we..?
// First search subprojects, starting with our root and then trying
// outer roots for as long as we are inside an amalgamation.
@@ -792,7 +791,6 @@ namespace build2
if (r != &iroot && as<string> (*r->vars["project"]) == project)
{
out_root = r->out_path ();
- fallback_src_root = r->src_path ();
break;
}
@@ -805,7 +803,6 @@ namespace build2
{
const dir_path& d ((*i).second);
out_root = r->out_path () / d;
- fallback_src_root = r->src_path () / d;
break;
}
}
@@ -859,48 +856,69 @@ namespace build2
}
}
- // Bootstrap the imported root scope. This is pretty similar to
- // what we do in main() except that here we don't try to guess
- // src_root.
+ // Bootstrap the imported root scope. This is pretty similar to what we do
+ // in main() except that here we don't try to guess src_root.
//
- dir_path src_root (is_src_root (out_root) ? out_root : dir_path ());
- scope& root (create_root (out_root, src_root));
-
- bootstrap_out (root);
-
- // Check that the bootstrap process set src_root.
+ // The user can also specify the out_root of the amalgamation that contains
+ // our project. For now we only consider top-level sub-projects.
//
- if (auto l = root.vars["src_root"])
- {
- const dir_path& p (as<dir_path> (*l));
+ dir_path src_root;
+ scope* root;
- if (!src_root.empty () && p != src_root)
- fail (loc) << "bootstrapped src_root " << p << " does not match "
- << "discovered " << src_root;
- }
- // Otherwise, use fallback if available.
- //
- else if (!fallback_src_root.empty ())
+ for (;;)
{
- value& v (root.assign ("src_root"));
- v = move (fallback_src_root);
- }
- else
- fail (loc) << "unable to determine src_root for imported " << project <<
- info << "consider configuring " << out_root;
+ src_root = is_src_root (out_root) ? out_root : dir_path ();
+ root = &create_root (out_root, src_root);
- setup_root (root);
+ bootstrap_out (*root);
- bootstrap_src (root);
+ // Check that the bootstrap process set src_root.
+ //
+ if (auto l = root->vars["src_root"])
+ {
+ const dir_path& p (as<dir_path> (*l));
+
+ if (!src_root.empty () && p != src_root)
+ fail (loc) << "bootstrapped src_root " << p << " does not match "
+ << "discovered " << src_root;
+ }
+ else
+ fail (loc) << "unable to determine src_root for imported "
+ << project <<
+ info << "consider configuring " << out_root;
+
+ setup_root (*root);
+ bootstrap_src (*root);
+
+ // Now we know this project's name as well as all its subprojects.
+ //
+ if (as<string> (*root->vars["project"]) == project)
+ break;
+
+ if (auto l = root->vars["subprojects"])
+ {
+ const auto& m (as<subprojects> (*l));
+ auto i (m.find (project));
+
+ if (i != m.end ())
+ {
+ const dir_path& d ((*i).second);
+ out_root = root->out_path () / d;
+ continue;
+ }
+ }
+
+ fail (loc) << out_root << " is not out_root for " << project;
+ }
// Bootstrap outer roots if any. Loading will be done by
// load_root_pre() below.
//
- create_bootstrap_outer (root);
+ create_bootstrap_outer (*root);
// Load the imported root scope.
//
- load_root_pre (root);
+ load_root_pre (*root);
// Create a temporary scope so that the export stub does not mess
// up any of our variables.
@@ -926,7 +944,7 @@ namespace build2
// stub will normally switch to the imported root scope at some
// point.
//
- path es (root.src_path () / path ("build/export.build"));
+ path es (root->src_path () / path ("build/export.build"));
try
{