aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-02-14 11:15:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-02-14 11:15:36 +0200
commit4c1b2f072bcc41c00990331245e479a55b0990ff (patch)
tree1c63a4d02a464ed0e5a6a182780619b1899574b5
parent5fc7471c034c367ff5ad776c2b9d7698678266c9 (diff)
Factor reusable code to contex::enter_project_overrides()
-rw-r--r--build2/b.cxx57
-rw-r--r--libbuild2/context.cxx61
-rw-r--r--libbuild2/context.hxx7
3 files changed, 69 insertions, 56 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index bb09675..c094523 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -1580,62 +1580,7 @@ main (int argc, char* argv[])
// boundaries (specifically, amalgamation) are only known after
// bootstrap.
//
- // The mildly tricky part here is to distinguish the situation where
- // we are bootstrapping the same project multiple times. The first
- // override that we set cannot already exist (because the override
- // variable names are unique) so if it is already set, then it can
- // only mean this project is already bootstrapped.
- //
- // This is further complicated by the project vs amalgamation logic
- // (we may have already done the amalgamation but not the project).
- // So we split it into two passes.
- //
- {
- auto& sm (ctx.scopes.rw ());
-
- for (const variable_override& o: ctx.var_overrides)
- {
- if (o.ovr.visibility != variable_visibility::global)
- continue;
-
- // If we have a directory, enter the scope, similar to how we do
- // it in the context ctor.
- //
- scope& s (
- o.dir
- ? *sm.insert_out ((out_base / *o.dir).normalize ())->second.front ()
- : *rs.weak_scope ());
-
- auto p (s.vars.insert (o.ovr));
-
- if (!p.second)
- break;
-
- value& v (p.first);
- v = o.val;
- }
-
- for (const variable_override& o: ctx.var_overrides)
- {
- // Ours is either project (%foo) or scope (/foo).
- //
- if (o.ovr.visibility == variable_visibility::global)
- continue;
-
- scope& s (
- o.dir
- ? *sm.insert_out ((out_base / *o.dir).normalize ())->second.front ()
- : rs);
-
- auto p (s.vars.insert (o.ovr));
-
- if (!p.second)
- break;
-
- value& v (p.first);
- v = o.val;
- }
- }
+ ctx.enter_project_overrides (rs, out_base, ctx.var_overrides);
ts.root_scope = &rs;
ts.out_base = move (out_base);
diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx
index c016a40..b7cfa42 100644
--- a/libbuild2/context.cxx
+++ b/libbuild2/context.cxx
@@ -606,6 +606,67 @@ namespace build2
}
void context::
+ enter_project_overrides (scope& rs,
+ const dir_path& out_base,
+ const variable_overrides& ovrs)
+ {
+ // The mildly tricky part here is to distinguish the situation where we
+ // are bootstrapping the same project multiple times. The first override
+ // that we set cannot already exist (because the override variable names
+ // are unique) so if it is already set, then it can only mean this project
+ // is already bootstrapped.
+ //
+ // This is further complicated by the project vs amalgamation logic (we
+ // may have already done the amalgamation but not the project). So we
+ // split it into two passes.
+ //
+ auto& sm (scopes.rw ());
+
+ for (const variable_override& o: ovrs)
+ {
+ if (o.ovr.visibility != variable_visibility::global)
+ continue;
+
+ // If we have a directory, enter the scope, similar to how we do
+ // it in the context ctor.
+ //
+ scope& s (
+ o.dir
+ ? *sm.insert_out ((out_base / *o.dir).normalize ())->second.front ()
+ : *rs.weak_scope ());
+
+ auto p (s.vars.insert (o.ovr));
+
+ if (!p.second)
+ break;
+
+ value& v (p.first);
+ v = o.val;
+ }
+
+ for (const variable_override& o: ovrs)
+ {
+ // Ours is either project (%foo) or scope (/foo).
+ //
+ if (o.ovr.visibility == variable_visibility::global)
+ continue;
+
+ scope& s (
+ o.dir
+ ? *sm.insert_out ((out_base / *o.dir).normalize ())->second.front ()
+ : rs);
+
+ auto p (s.vars.insert (o.ovr));
+
+ if (!p.second)
+ break;
+
+ value& v (p.first);
+ v = o.val;
+ }
+ }
+
+ void context::
current_meta_operation (const meta_operation_info& mif)
{
if (current_mname != mif.name)
diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx
index 9df7a88..3563c16 100644
--- a/libbuild2/context.hxx
+++ b/libbuild2/context.hxx
@@ -353,6 +353,13 @@ namespace build2
const variable_overrides& var_overrides; // Project and relative scope.
function_map& functions;
+ // Enter project-wide (as opposed to global) variable overrides.
+ //
+ void
+ enter_project_overrides (scope& rs,
+ const dir_path& out_base,
+ const variable_overrides&);
+
// Global scope.
//
const scope& global_scope;