aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/context.cxx
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 /libbuild2/context.cxx
parent5fc7471c034c367ff5ad776c2b9d7698678266c9 (diff)
Factor reusable code to contex::enter_project_overrides()
Diffstat (limited to 'libbuild2/context.cxx')
-rw-r--r--libbuild2/context.cxx61
1 files changed, 61 insertions, 0 deletions
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)