aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-08-18 08:04:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-08-18 08:04:07 +0200
commitb2df0b0663d0537dd3b4f2d28d145ccd90417cab (patch)
treeb58ff44bfa5a8423721d6b865541a2e3a3d27d60 /libbuild2
parent5521a0edd9a2ba8429f7d2e48f754c9d6f66cc3b (diff)
Add ability to mark config.* variables as "unsaved" (always transient)
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/config/module.cxx6
-rw-r--r--libbuild2/config/module.hxx25
-rw-r--r--libbuild2/config/operation.cxx12
-rw-r--r--libbuild2/config/utility.cxx2
-rw-r--r--libbuild2/config/utility.hxx14
5 files changed, 40 insertions, 19 deletions
diff --git a/libbuild2/config/module.cxx b/libbuild2/config/module.cxx
index 6b0c82a..bf68c4e 100644
--- a/libbuild2/config/module.cxx
+++ b/libbuild2/config/module.cxx
@@ -12,7 +12,7 @@ namespace build2
namespace config
{
bool module::
- save_variable (const variable& var, uint64_t flags)
+ save_variable (const variable& var, optional<uint64_t> flags)
{
const string& n (var.name);
@@ -39,7 +39,7 @@ namespace build2
if (j != sv.end ())
{
- assert (j->flags == flags);
+ assert (!j->flags == !flags && (!flags || *j->flags == *flags));
return false;
}
@@ -48,7 +48,7 @@ namespace build2
}
void module::
- save_variable (scope& rs, const variable& var, uint64_t flags)
+ save_variable (scope& rs, const variable& var, optional<uint64_t> flags)
{
if (module* m = rs.find_module<module> (module::name))
m->save_variable (var, flags);
diff --git a/libbuild2/config/module.hxx b/libbuild2/config/module.hxx
index 96220ac..857a30c 100644
--- a/libbuild2/config/module.hxx
+++ b/libbuild2/config/module.hxx
@@ -25,12 +25,13 @@ namespace build2
// 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()) and
- // saved in the order populated.
+ // saved in the order populated. If flags are absent, then this variable
+ // was marked as "unsaved" (always transient).
//
struct saved_variable
{
reference_wrapper<const variable> var;
- uint64_t flags;
+ optional<uint64_t> flags;
};
struct saved_variables: vector<saved_variable>
@@ -75,10 +76,10 @@ namespace build2
// Return true if variable/module were newly inserted.
//
bool
- save_variable (const variable&, uint64_t flags = 0);
+ save_variable (const variable&, optional<uint64_t> flags);
static void
- save_variable (scope&, const variable&, uint64_t);
+ save_variable (scope&, const variable&, optional<uint64_t>);
bool
save_module (const char* name, int prio = 0);
@@ -86,14 +87,18 @@ namespace build2
static void
save_module (scope&, const char*, int);
- // Return true if the variable is already saved.
- //
- bool
- saved (const variable& var)
+ const saved_variable*
+ find_variable (const variable& var)
{
auto i (saved_modules.find_sup (var.name));
- return i != saved_modules.end () &&
- i->second.find (var) != i->second.end ();
+ if (i != saved_modules.end ())
+ {
+ auto j (i->second.find (var));
+ if (j != i->second.end ())
+ return &*j;
+ }
+
+ return nullptr;
}
// Configure/disfigure hooks.
diff --git a/libbuild2/config/operation.cxx b/libbuild2/config/operation.cxx
index b07df42..963a3e1 100644
--- a/libbuild2/config/operation.cxx
+++ b/libbuild2/config/operation.cxx
@@ -236,7 +236,7 @@ namespace build2
var->name.compare (0, 14, "config.config.") == 0)
continue;
- if (mod->saved (*var))
+ if (mod->find_variable (*var)) // Saved or unsaved.
continue;
const value& v (p.first->second);
@@ -247,7 +247,7 @@ namespace build2
true /* unused */));
if (r.first) // save
{
- mod->save_variable (*var);
+ mod->save_variable (*var, 0);
if (r.second) // warn
{
@@ -291,7 +291,11 @@ namespace build2
bool first (true); // Separate modules with a blank line.
for (const saved_variable& sv: svars)
{
+ if (!sv.flags) // unsaved
+ continue;
+
const variable& var (sv.var);
+ uint64_t flags (*sv.flags);
pair<lookup, size_t> org (rs.lookup_original (var));
pair<lookup, size_t> ovr (var.overrides == nullptr
@@ -304,7 +308,7 @@ namespace build2
// inherited. We might also not have any value at all (see
// unconfigured()).
//
- if (!l.defined () || (l->null && sv.flags & save_null_omitted))
+ if (!l.defined () || (l->null && flags & save_null_omitted))
continue;
// Handle inherited from outer scope values.
@@ -451,7 +455,7 @@ namespace build2
//
if ((org.first.defined () && org.first->extra) && // Default value.
org.first == ovr.first && // Not overriden.
- (sv.flags & save_default_commented) != 0)
+ (flags & save_default_commented) != 0)
{
os << '#' << n << " =" << endl;
continue;
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx
index b10c980..12ec1fe 100644
--- a/libbuild2/config/utility.cxx
+++ b/libbuild2/config/utility.cxx
@@ -7,7 +7,7 @@ using namespace std;
namespace build2
{
- void (*config_save_variable) (scope&, const variable&, uint64_t);
+ void (*config_save_variable) (scope&, const variable&, optional<uint64_t>);
void (*config_save_module) (scope&, const char*, int);
const string& (*config_preprocess_create) (context&,
values&,
diff --git a/libbuild2/config/utility.hxx b/libbuild2/config/utility.hxx
index 209ef5c..7d3e18b 100644
--- a/libbuild2/config/utility.hxx
+++ b/libbuild2/config/utility.hxx
@@ -33,7 +33,7 @@ namespace build2
// attribute). Such flags should start from 0x100000000.
//
LIBBUILD2_SYMEXPORT extern void
- (*config_save_variable) (scope&, const variable&, uint64_t);
+ (*config_save_variable) (scope&, const variable&, optional<uint64_t>);
LIBBUILD2_SYMEXPORT extern void
(*config_save_module) (scope&, const char*, int);
@@ -65,6 +65,18 @@ namespace build2
config_save_variable (rs, var, flags);
}
+ // Mark the variable as "unsaved" (always transient).
+ //
+ // Such variables are not very common and are usually used to control the
+ // process of configuration itself.
+ //
+ inline void
+ unsave_variable (scope& rs, const variable& var)
+ {
+ if (config_save_variable != nullptr)
+ config_save_variable (rs, var, nullopt);
+ }
+
// Establish module save order/priority with INT32_MIN being the highest.
// Modules with the same priority are saved in the order inserted.
//