From 7a995b778ab86c8ae63ba8f86950fd25e3ab5162 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 19 Apr 2023 06:38:04 +0200 Subject: Clarify const-ness issues in configure implementation --- libbuild2/config/functions.cxx | 2 +- libbuild2/config/module.hxx | 2 +- libbuild2/config/operation.cxx | 30 ++++++++++++++++++++---------- libbuild2/config/operation.hxx | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/config/functions.cxx b/libbuild2/config/functions.cxx index 84c1b03..b1a61a2 100644 --- a/libbuild2/config/functions.cxx +++ b/libbuild2/config/functions.cxx @@ -95,7 +95,7 @@ namespace build2 // See save_config() for details. // assert (s->ctx.phase == run_phase::load); - module* mod (s->rw ().find_module (module::name)); + const module* mod (s->find_module (module::name)); if (mod == nullptr) fail << "config.save() called without config module"; diff --git a/libbuild2/config/module.hxx b/libbuild2/config/module.hxx index 82b79be..8d3ff67 100644 --- a/libbuild2/config/module.hxx +++ b/libbuild2/config/module.hxx @@ -160,7 +160,7 @@ namespace build2 save_module (scope&, const char*, int); const saved_variable* - find_variable (const variable& var) + find_variable (const variable& var) const { auto i (saved_modules.find_sup (var.name)); if (i != saved_modules.end ()) diff --git a/libbuild2/config/operation.cxx b/libbuild2/config/operation.cxx index c6f1c1b..aca6ce8 100644 --- a/libbuild2/config/operation.cxx +++ b/libbuild2/config/operation.cxx @@ -163,11 +163,18 @@ namespace build2 // and this function can be called from a buildfile (probably only // during serial execution but still). // + // We could also be configuring multiple projects (including from + // pkg_configure() in bpkg) but feels like we should be ok since we + // only modify this project's root scope data which should not affect + // any other project. + // + // See also save_environment() for a similar issue. + // void save_config (const scope& rs, ostream& os, const path_name& on, bool inherit, - module& mod, + const module& mod, const project_set& projects) { context& ctx (rs.ctx); @@ -259,7 +266,7 @@ namespace build2 true /* unused */)); if (r.first) // save { - mod.save_variable (*var, 0); + const_cast (mod).save_variable (*var, 0); if (r.second) // warn { @@ -560,7 +567,7 @@ namespace build2 save_config (const scope& rs, const path& f, bool inherit, - module& mod, + const module& mod, const project_set& projects) { path_name fn (f); @@ -588,6 +595,9 @@ namespace build2 // Update config.config.environment value for a hermetic configuration. // + // @@ We are modifying the module. See also save_config() for a similar + // issue. + // static void save_environment (scope& rs, module& mod) { @@ -660,9 +670,9 @@ namespace build2 static void configure_project (action a, - scope& rs, + const scope& rs, const variable* c_s, // config.config.save - module& mod, + const module& mod, project_set& projects) { tracer trace ("configure_project"); @@ -696,7 +706,7 @@ namespace build2 // for the other half of this logic). // if (cast_false (rs["config.config.hermetic"])) - save_environment (rs, mod); + save_environment (const_cast (rs), const_cast (mod)); // Save src-root.build unless out_root is the same as src. // @@ -759,14 +769,14 @@ namespace build2 { const dir_path& pd (p.second); dir_path out_nroot (out_root / pd); - scope& nrs (ctx.scopes.find_out (out_nroot).rw ()); + const scope& nrs (ctx.scopes.find_out (out_nroot)); // Skip this subproject if it is not loaded or doesn't use the // config module. // if (nrs.out_path () == out_nroot) { - if (module* m = nrs.find_module (module::name)) + if (const module* m = nrs.find_module (module::name)) { configure_project (a, nrs, c_s, *m, projects); } @@ -992,9 +1002,9 @@ namespace build2 } configure_project (a, - rs->rw (), + *rs, c_s, - *rs->rw ().find_module (module::name), + *rs->find_module (module::name), projects); } } diff --git a/libbuild2/config/operation.hxx b/libbuild2/config/operation.hxx index e3328c3..1662941 100644 --- a/libbuild2/config/operation.hxx +++ b/libbuild2/config/operation.hxx @@ -37,7 +37,7 @@ namespace build2 save_config (const scope& rs, ostream&, const path_name&, bool inherit, - module&, + const module&, const project_set&); // See config.config.hermetic.environment. -- cgit v1.1