From 87a284335715301fa2cea695386bfcd21a2fe781 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 26 Oct 2023 19:37:02 +0300 Subject: Load both user and dependent configurations in (pre-)reevaluate modes --- bpkg/package-skeleton.cxx | 45 +++++++++++++++++++++++++++++++++++++-------- bpkg/package-skeleton.hxx | 12 +++++++++++- bpkg/pkg-build-collect.cxx | 15 +++++++++------ bpkg/pkg-build-collect.hxx | 3 ++- bpkg/pkg-configure.cxx | 3 ++- 5 files changed, 61 insertions(+), 17 deletions(-) (limited to 'bpkg') diff --git a/bpkg/package-skeleton.cxx b/bpkg/package-skeleton.cxx index 567f2e7..7effca0 100644 --- a/bpkg/package-skeleton.cxx +++ b/bpkg/package-skeleton.cxx @@ -157,10 +157,12 @@ namespace bpkg db_ (v.db_), var_prefix_ (move (v.var_prefix_)), config_vars_ (move (v.config_vars_)), + config_var_srcs_ (move (v.config_var_srcs_)), disfigure_ (v.disfigure_), config_srcs_ (v.config_srcs_), src_root_ (move (v.src_root_)), out_root_ (move (v.out_root_)), + load_old_dependent_config_ (v.load_old_dependent_config_), created_ (v.created_), verified_ (v.verified_), loaded_old_config_ (v.loaded_old_config_), @@ -194,10 +196,12 @@ namespace bpkg db_ = v.db_; var_prefix_ = move (v.var_prefix_); config_vars_ = move (v.config_vars_); + config_var_srcs_ = move (v.config_var_srcs_); disfigure_ = v.disfigure_; config_srcs_ = v.config_srcs_; src_root_ = move (v.src_root_); out_root_ = move (v.out_root_); + load_old_dependent_config_ = v.load_old_dependent_config_; created_ = v.created_; verified_ = v.verified_; loaded_old_config_ = v.loaded_old_config_; @@ -231,10 +235,12 @@ namespace bpkg db_ (v.db_), var_prefix_ (v.var_prefix_), config_vars_ (v.config_vars_), + config_var_srcs_ (v.config_var_srcs_), disfigure_ (v.disfigure_), config_srcs_ (v.config_srcs_), src_root_ (v.src_root_), out_root_ (v.out_root_), + load_old_dependent_config_ (v.load_old_dependent_config_), created_ (v.created_), verified_ (v.verified_), loaded_old_config_ (v.loaded_old_config_), @@ -296,7 +302,8 @@ namespace bpkg bool df, const vector* css, optional src_root, - optional out_root) + optional out_root, + bool load_old_dependent_config) : package (move (pk)), system (sys), available (move (ap)), @@ -305,21 +312,28 @@ namespace bpkg var_prefix_ ("config." + package.name.variable ()), config_vars_ (move (cvs)), disfigure_ (df), - config_srcs_ (df ? nullptr : css) + config_srcs_ (df ? nullptr : css), + load_old_dependent_config_ (load_old_dependent_config) { if (available != nullptr) assert (available->bootstrap_build); // Should have skeleton info. else assert (system); + if (!config_vars_.empty ()) + config_var_srcs_ = vector (config_vars_.size (), + config_source::user); + // We are only interested in old user configuration variables. // if (config_srcs_ != nullptr) { if (find_if (config_srcs_->begin (), config_srcs_->end (), - [] (const config_variable& v) + [this] (const config_variable& v) { - return v.source == config_source::user; + return v.source == config_source::user || + (load_old_dependent_config_ && + v.source == config_source::dependent); }) == config_srcs_->end ()) config_srcs_ = nullptr; } @@ -1896,8 +1910,10 @@ namespace bpkg // First comes the user configuration. // - for (const string& v: config_vars_) + for (size_t i (0); i != config_vars_.size (); ++i) { + const string& v (config_vars_[i]); + size_t vn; if (project_override (v, var_prefix_, &vn)) { @@ -1911,8 +1927,17 @@ namespace bpkg continue; } + const char* s (nullptr); + + switch (config_var_srcs_[i]) + { + case config_source::user: s = "user"; break; + case config_source::dependent: s = "dependent"; break; + case config_source::reflect: assert (false); // Must never be loaded. + } + print (v) << " (" << (system ? "expected " : "") - << "user configuration)"; + << s << " configuration)"; } } @@ -2253,12 +2278,15 @@ namespace bpkg { assert (!disfigure_); - auto i (config_vars_.begin ()); // Insert position, see below. + auto i (config_vars_.begin ()); // Insert position, see below. + auto j (config_var_srcs_.begin ()); // Insert position, see below. names storage; for (const config_variable& v: *config_srcs_) { - if (v.source != config_source::user) + if (!(v.source == config_source::user || + (load_old_dependent_config_ && + v.source == config_source::dependent))) continue; using config::variable_origin; @@ -2288,6 +2316,7 @@ namespace bpkg i, serialize_cmdline (v.name, *ol.second, storage)) + 1; + j = config_var_srcs_.insert (j, v.source) + 1; break; } case variable_origin::undefined: diff --git a/bpkg/package-skeleton.hxx b/bpkg/package-skeleton.hxx index bc5d25c..04abc0e 100644 --- a/bpkg/package-skeleton.hxx +++ b/bpkg/package-skeleton.hxx @@ -68,7 +68,8 @@ namespace bpkg bool disfigure, const vector* config_srcs, optional src_root, - optional out_root); + optional out_root, + bool load_old_dependent_config); package_key package; @@ -253,6 +254,13 @@ namespace bpkg string var_prefix_; // config. strings config_vars_; + + // Configuration sources for variables in config_vars_ (parallel). Can + // only contain config_source::{user,dependent} entries (see + // load_old_config() for details). + // + vector config_var_srcs_; + bool disfigure_; const vector* config_srcs_; // NULL if nothing to do or // already done. @@ -260,6 +268,8 @@ namespace bpkg dir_path src_root_; // Must be absolute and normalized. dir_path out_root_; // If empty, the same as src_root_. + bool load_old_dependent_config_; + bool created_ = false; bool verified_ = false; bool loaded_old_config_; diff --git a/bpkg/pkg-build-collect.cxx b/bpkg/pkg-build-collect.cxx index b1306b5..f664bf7 100644 --- a/bpkg/pkg-build-collect.cxx +++ b/bpkg/pkg-build-collect.cxx @@ -366,7 +366,8 @@ namespace bpkg init_skeleton (const common_options& options, const shared_ptr& override, optional src_root, - optional out_root) + optional out_root, + bool load_old_dependent_config) { shared_ptr ap (override != nullptr ? override @@ -406,7 +407,8 @@ namespace bpkg disfigure, (selected != nullptr ? &selected->config_variables : nullptr), move (src_root), - move (out_root)); + move (out_root), + load_old_dependent_config); return *skeleton; } @@ -2108,15 +2110,16 @@ namespace bpkg if (!pkg.skeleton) { - // In the pre-reevaluation mode make sure that the user-specified - // configuration is loaded by the skeleton. + // In the (pre-)reevaluation mode make sure that the user-specified + // and the dependent configurations are both loaded by the skeleton. // - if (pre_reeval) + if (pre_reeval || reeval) { pkg.init_skeleton (options, nullptr /* override */, sp->effective_src_root (pdb.config), - sp->effective_out_root (pdb.config)); + sp->effective_out_root (pdb.config), + true /* load_old_dependent_config */); } else pkg.init_skeleton (options); diff --git a/bpkg/pkg-build-collect.hxx b/bpkg/pkg-build-collect.hxx index e34fc25..d64abc5 100644 --- a/bpkg/pkg-build-collect.hxx +++ b/bpkg/pkg-build-collect.hxx @@ -455,7 +455,8 @@ namespace bpkg init_skeleton (const common_options&, const shared_ptr& override = nullptr, optional src_root = nullopt, - optional out_root = nullopt); + optional out_root = nullopt, + bool load_old_dependent_config = false); }; using build_package_list = std::list>; diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index c145b28..0850001 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -1108,7 +1108,8 @@ namespace bpkg false /* disfigure */, &p->config_variables, move (src_root), - move (out_root)), + move (out_root), + true /* load_old_dependent_config */), nullptr /* prerequisites */, false /* disfigured */, false /* simulate */); -- cgit v1.1