aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-03-18 08:25:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-03-18 08:25:19 +0200
commit7d0c4c5ab6760e4487230f9eda87c352609be553 (patch)
treecec71d00d5186aa6aa03244b143858d5bb2f54de
parentee36f1d58484479a2fa3547fad1eb1cc34c51c3e (diff)
Pattern-type config.** variables with global visibility by default
-rw-r--r--libbuild2/config/init.cxx29
-rw-r--r--libbuild2/config/utility.cxx4
-rw-r--r--libbuild2/context.cxx85
3 files changed, 62 insertions, 56 deletions
diff --git a/libbuild2/config/init.cxx b/libbuild2/config/init.cxx
index ca34d52..f15bfc5 100644
--- a/libbuild2/config/init.cxx
+++ b/libbuild2/config/init.cxx
@@ -37,15 +37,21 @@ namespace build2
l5 ([&]{trace << "for " << rs;});
- // Note that the config.<name>* variables belong to the module <name>.
- // So the only "special" variables we can allocate in config.* are
- // config.config.*, names that have been "gifted" to us by other modules
- // (like config.version below) as well as names that we have reserved to
- // not be valid module names (`build`). We also currently treat `import`
- // as special.
+ // Note that the config.<name>* variables belong to the module/project
+ // <name>. So the only "special" variables we can allocate in config.**
+ // are config.config.**, names that have been "gifted" to us by other
+ // modules (like config.version below) as well as names that we have
+ // reserved to not be valid module names (`build`). We also currently
+ // treat `import` as special.
+ //
+ // NOTE: all config.** variables are by default made (via a pattern) to
+ // be overridable with global visibility. So we must override this if a
+ // different semantics is required.
//
auto& vp (rs.var_pool ());
+ const auto v_p (variable_visibility::project);
+
// While config.config.load (see below) could theoretically be specified
// in a buildfile, config.config.save is expected to always be specified
// as a command line override.
@@ -88,9 +94,7 @@ namespace build2
// Use the NULL value to clear.
//
auto& c_p (vp.insert<vector<pair<string, string>>> (
- "config.config.persist",
- true /* ovr */,
- variable_visibility::project));
+ "config.config.persist", true /* ovr */, v_p));
// Only create the module if we are configuring or creating or if it was
// requested with config.config.module (useful if we need to call
@@ -99,7 +103,7 @@ namespace build2
// Detecting the former (configuring/creating) is a bit tricky since the
// build2 core may not yet know if this is the case. But we know.
//
- auto& c_m (vp.insert<bool> ("config.config.module", false /*ovr*/));
+ auto& c_m (vp.insert<bool> ("config.config.module", false /*ovr*/, v_p));
const string& mname (ctx.current_mname);
const string& oname (ctx.current_oname);
@@ -161,8 +165,11 @@ namespace build2
l5 ([&]{trace << "for " << rs;});
auto& vp (rs.var_pool ());
+
+ const auto v_p (variable_visibility::project);
+
auto& c_l (vp.insert<paths> ("config.config.load", true /* ovr */));
- auto& c_v (vp.insert<uint64_t> ("config.version", false /*ovr*/));
+ auto& c_v (vp.insert<uint64_t> ("config.version", false /*ovr*/, v_p));
// Load config.build if one exists followed by extra files specified in
// config.config.load (we don't need to worry about disfigure since we
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx
index 7415085..cf0f73b 100644
--- a/libbuild2/config/utility.cxx
+++ b/libbuild2/config/utility.cxx
@@ -84,7 +84,7 @@ namespace build2
bool
unconfigured (scope& rs, const string& n)
{
- // Pattern-typed in boot() as bool.
+ // Pattern-typed as bool.
//
const variable& var (
rs.var_pool ().insert ("config." + n + ".configured"));
@@ -98,7 +98,7 @@ namespace build2
bool
unconfigured (scope& rs, const string& n, bool v)
{
- // Pattern-typed in boot() as bool.
+ // Pattern-typed as bool.
//
const variable& var (
rs.var_pool ().insert ("config." + n + ".configured"));
diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx
index 827894b..724a16e 100644
--- a/libbuild2/context.cxx
+++ b/libbuild2/context.cxx
@@ -476,65 +476,64 @@ namespace build2
// Enter builtin variables and patterns.
//
+ const auto v_g (variable_visibility::normal); // Global.
+ const auto v_p (variable_visibility::project);
+ const auto v_t (variable_visibility::target);
+ const auto v_q (variable_visibility::prereq);
- // All config.* variables are by default overridable.
+ // All config.** variables are by default overridable with global
+ // visibility.
//
- vp.insert_pattern ("config.**", nullopt, true, nullopt, true, false);
+ // For the config.**.configured semantics, see config::unconfigured().
+ //
+ vp.insert_pattern ("config.**", nullopt, true, v_g, true, false);
+ vp.insert_pattern<bool> ("config.**.configured", false, v_p);
// file.cxx:import() (note that order is important; see insert_pattern()).
//
- vp.insert_pattern<abs_dir_path> (
- "config.import.*", true, variable_visibility::normal, true);
- vp.insert_pattern<path> (
- "config.import.**", true, variable_visibility::normal, true);
+ vp.insert_pattern<abs_dir_path> ("config.import.*", true, v_g, true);
+ vp.insert_pattern<path> ("config.import.**", true, v_g, true);
// module.cxx:boot/init_module().
//
- {
- auto v_p (variable_visibility::project);
-
- vp.insert_pattern<bool> ("**.booted", false, v_p);
- vp.insert_pattern<bool> ("**.loaded", false, v_p);
- vp.insert_pattern<bool> ("**.configured", false, v_p);
- }
-
- {
- auto v_p (variable_visibility::project);
- auto v_t (variable_visibility::target);
- auto v_q (variable_visibility::prereq);
+ // Note that we also have the config.<module>.configured variable (see
+ // above).
+ //
+ vp.insert_pattern<bool> ("**.booted", false /* overridable */, v_p);
+ vp.insert_pattern<bool> ("**.loaded", false, v_p);
+ vp.insert_pattern<bool> ("**.configured", false, v_p);
- var_src_root = &vp.insert<dir_path> ("src_root");
- var_out_root = &vp.insert<dir_path> ("out_root");
- var_src_base = &vp.insert<dir_path> ("src_base");
- var_out_base = &vp.insert<dir_path> ("out_base");
+ var_src_root = &vp.insert<dir_path> ("src_root");
+ var_out_root = &vp.insert<dir_path> ("out_root");
+ var_src_base = &vp.insert<dir_path> ("src_base");
+ var_out_base = &vp.insert<dir_path> ("out_base");
- var_forwarded = &vp.insert<bool> ("forwarded", v_p);
+ var_forwarded = &vp.insert<bool> ("forwarded", v_p);
- // Note that subprojects is not typed since the value requires
- // pre-processing (see file.cxx).
- //
- var_project = &vp.insert<project_name> ("project", v_p);
- var_amalgamation = &vp.insert<dir_path> ("amalgamation", v_p);
- var_subprojects = &vp.insert ("subprojects", v_p);
- var_version = &vp.insert<string> ("version", v_p);
+ // Note that subprojects is not typed since the value requires
+ // pre-processing (see file.cxx).
+ //
+ var_project = &vp.insert<project_name> ("project", v_p);
+ var_amalgamation = &vp.insert<dir_path> ("amalgamation", v_p);
+ var_subprojects = &vp.insert ("subprojects", v_p);
+ var_version = &vp.insert<string> ("version", v_p);
- var_project_url = &vp.insert<string> ("project.url", v_p);
- var_project_summary = &vp.insert<string> ("project.summary", v_p);
+ var_project_url = &vp.insert<string> ("project.url", v_p);
+ var_project_summary = &vp.insert<string> ("project.summary", v_p);
- var_import_target = &vp.insert<name> ("import.target");
+ var_import_target = &vp.insert<name> ("import.target");
- var_extension = &vp.insert<string> ("extension", v_t);
- var_clean = &vp.insert<bool> ("clean", v_t);
- var_backlink = &vp.insert<string> ("backlink", v_t);
- var_include = &vp.insert<string> ("include", v_q);
+ var_extension = &vp.insert<string> ("extension", v_t);
+ var_clean = &vp.insert<bool> ("clean", v_t);
+ var_backlink = &vp.insert<string> ("backlink", v_t);
+ var_include = &vp.insert<string> ("include", v_q);
- // Backlink executables and (generated) documentation by default.
- //
- gs.target_vars[exe::static_type]["*"].assign (var_backlink) = "true";
- gs.target_vars[doc::static_type]["*"].assign (var_backlink) = "true";
+ // Backlink executables and (generated) documentation by default.
+ //
+ gs.target_vars[exe::static_type]["*"].assign (var_backlink) = "true";
+ gs.target_vars[doc::static_type]["*"].assign (var_backlink) = "true";
- var_build_meta_operation = &vp.insert<string> ("build.meta_operation");
- }
+ var_build_meta_operation = &vp.insert<string> ("build.meta_operation");
// Register builtin rules.
//