aboutsummaryrefslogtreecommitdiff
path: root/build2/config
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-07-21 10:04:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-07-21 10:04:18 +0200
commitd8f26e8402bbe19820545db90394f657ae42e598 (patch)
treea1430c3077de2053ef32013c2eef5e50b840a43a /build2/config
parentde15b95d09d00821aa23e96a0c3e827689c27a58 (diff)
Save default/hinted ar/ld/rc values as commented out
This way, when we, for example, change the C++ compiler (which hinted these values), they will be automatically adjusted as well.
Diffstat (limited to 'build2/config')
-rw-r--r--build2/config/module7
-rw-r--r--build2/config/operation.cxx18
-rw-r--r--build2/config/utility20
-rw-r--r--build2/config/utility.txx8
4 files changed, 40 insertions, 13 deletions
diff --git a/build2/config/module b/build2/config/module
index adc9b05..aed85a5 100644
--- a/build2/config/module
+++ b/build2/config/module
@@ -19,9 +19,10 @@ namespace build2
{
struct module: module_base
{
- // A sorted list of config.* variables and flags (currently unused) that
- // are used (as opposed to just specified) in this configuration.
- // Populated by the config utility functions (required(), optional())
+ // A sorted list of config.* variables and their "save flags" (see
+ // save_variable()) that are used (as opposed to just being specified)
+ // in this configuration. Populated by the config utility functions
+ // (required(), optional())
//
butl::prefix_map<variable_cref, uint64_t, '.'> vars;
diff --git a/build2/config/operation.cxx b/build2/config/operation.cxx
index 4a5b39c..c3868ab 100644
--- a/build2/config/operation.cxx
+++ b/build2/config/operation.cxx
@@ -16,6 +16,7 @@
#include <build2/diagnostics>
#include <build2/config/module>
+#include <build2/config/utility>
using namespace std;
using namespace butl;
@@ -86,14 +87,16 @@ namespace build2
ofs << "# Created automatically by the config module, but feel " <<
"free to edit." << endl
- << "#" << endl;
+ << "#" << endl
+ << endl;
if (auto l = root.vars["amalgamation"])
{
const dir_path& d (cast<dir_path> (l));
ofs << "# Base configuration inherited from " << d << endl
- << "#" << endl;
+ << "#" << endl
+ << endl;
}
// Separate variables for modules with blank lines.
@@ -135,6 +138,7 @@ namespace build2
{
const auto& p (*i);
const variable& var (p.first);
+ uint64_t sflags (p.second);
pair<lookup, size_t> org (root.find_original (var));
pair<lookup, size_t> ovr (var.override == nullptr
@@ -249,6 +253,16 @@ namespace build2
if (next_module (var))
ofs << endl;
+ // Handle the save_commented flag.
+ //
+ if (org.first->extra && // Default value.
+ org.first == ovr.first && // Not overriden.
+ (sflags & save_commented) == save_commented)
+ {
+ ofs << '#' << n << " =" << endl;
+ continue;
+ }
+
if (v)
{
storage.clear ();
diff --git a/build2/config/utility b/build2/config/utility
index c47cecf..c1ccc0f 100644
--- a/build2/config/utility
+++ b/build2/config/utility
@@ -22,6 +22,7 @@ namespace build2
// If override is true and the variable doesn't come from this root scope
// or from the command line (i.e., it is inherited from the amalgamtion),
// then its value is "overridden" to the default value on this root scope.
+ // See save_variable() for more information on save_flags.
//
// Return the reference to the value as well as the indication of whether
// the value is "new", that is, it was set to the default value (inherited
@@ -34,25 +35,30 @@ namespace build2
required (scope& root,
const variable&,
const T& default_value,
- bool override = false);
+ bool override = false,
+ uint64_t save_flags = 0);
template <typename T>
inline pair<reference_wrapper<const value>, bool>
required (scope& root,
const string& name,
const T& default_value,
- bool override = false)
+ bool override = false,
+ uint64_t save_flags = 0)
{
- return required (root, var_pool.find (name), default_value, override);
+ return required (
+ root, var_pool.find (name), default_value, override, save_flags);
}
inline pair<reference_wrapper<const value>, bool>
required (scope& root,
const string& name,
const char* default_value,
- bool override = false)
+ bool override = false,
+ uint64_t save_flags = 0)
{
- return required (root, name, string (default_value), override);
+ return required (
+ root, name, string (default_value), override, save_flags);
}
// As above, but leave the unspecified value as undefined (and return
@@ -116,8 +122,10 @@ namespace build2
unconfigured (scope& root, const string& ns, bool);
// Enter the variable so that it is saved during configuration. See
- // config::module.
+ // config::module for details.
//
+ const uint64_t save_commented = 0x01; // Save default value as commented.
+
void
save_variable (scope& root, const variable&, uint64_t flags = 0);
}
diff --git a/build2/config/utility.txx b/build2/config/utility.txx
index 5ebd261..4e6747b 100644
--- a/build2/config/utility.txx
+++ b/build2/config/utility.txx
@@ -11,13 +11,17 @@ namespace build2
{
template <typename T>
pair<reference_wrapper<const value>, bool>
- required (scope& root, const variable& var, const T& def_val, bool def_ovr)
+ required (scope& root,
+ const variable& var,
+ const T& def_val,
+ bool def_ovr,
+ uint64_t save_flags)
{
// Note: see also the other required() version if changing anything
// here.
if (current_mif->id == configure_id)
- save_variable (root, var);
+ save_variable (root, var, save_flags);
pair<lookup, size_t> org (root.find_original (var));