From 97913b6fb268f327ee1a689779cb9b0621f72ff2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 29 Jul 2016 09:19:37 +0200 Subject: Fix duplicate config.build variable issue --- build2/config/module | 18 +++++++++++++++++- build2/config/operation.cxx | 11 +++-------- build2/config/utility.cxx | 11 +++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/build2/config/module b/build2/config/module index 5becfd4..7360cf6 100644 --- a/build2/config/module +++ b/build2/config/module @@ -5,6 +5,8 @@ #ifndef BUILD2_CONFIG_MODULE #define BUILD2_CONFIG_MODULE +#include // find_if() + #include #include @@ -29,7 +31,21 @@ namespace build2 uint64_t flags; }; - using saved_variables = vector; + struct saved_variables: vector + { + // Normally each module only have a handful of config variables and we + // only do this during configuration so for now we do linear search + // instead of adding a map. + // + const_iterator + find (const variable& var) const + { + return std::find_if ( + begin (), + end (), + [&var] (const saved_variable& v) {return var == v.var;}); + } + }; struct saved_modules: butl::prefix_map { diff --git a/build2/config/operation.cxx b/build2/config/operation.cxx index faeb570..0773f00 100644 --- a/build2/config/operation.cxx +++ b/build2/config/operation.cxx @@ -143,7 +143,7 @@ namespace build2 { if (l.belongs (*r)) { - // Find config module. + // Find the config module. // if (auto* m = r->modules.lookup (module::name)) { @@ -153,15 +153,10 @@ namespace build2 if (i != m->saved_modules.end ()) { - // Find the variable. For now we do linear search. + // Find the variable. // const saved_variables& sv (i->second); - - found = find_if ( - sv.begin (), - sv.end (), - [&var] (const saved_variable& v) { - return var == v.var;}) != sv.end (); + found = sv.find (var) != sv.end (); // Handle that other case: if this is an override but // the outer project itself is not being configured, diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx index a24f7b3..b73e852 100644 --- a/build2/config/utility.cxx +++ b/build2/config/utility.cxx @@ -158,9 +158,16 @@ namespace build2 i = sm.insert (string (n, 0, n.find ('.', 7))); } - // We assume each variable is saved/configured once. + // Don't insert duplicates. The config.import vars are particularly + // susceptible to duplication. // - i->second.push_back (saved_variable {var, flags}); + saved_variables& sv (i->second); + auto j (sv.find (var)); + + if (j == sv.end ()) + sv.push_back (saved_variable {var, flags}); + else + assert (j->flags == flags); } } } -- cgit v1.1