Fix duplicate suppression to handle same name with and without prefix

This commit is contained in:
Boris Kolpackov 2022-09-13 10:33:41 +02:00
parent 950c00d571
commit 3a41d19323
2 changed files with 47 additions and 35 deletions

View File

@ -498,3 +498,24 @@ cat config.h >>EOO
#undef PREFIX_TEST_DUMMY3_H
#define PREFIX_TEST_DUMMY3_H zzz_TEST_DUMMY3_H
EOO
: alias-map-prefix-same-name
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build build/;
cat <<EOI >=config.h.cmake;
#cmakedefine PREFIX_zzz_TEST_DUMMY3_H
EOI
$* <<EOI &config.h &config.h.d;
./: h{config}: in{config.h.cmake}
{
autoconf.prefix = PREFIX_
autoconf.aliases = PREFIX_zzz_TEST_DUMMY3_H@zzz_TEST_DUMMY3_H
}
EOI
cat config.h >>EOO
#define zzz_TEST_DUMMY3_H 1
#undef PREFIX_zzz_TEST_DUMMY3_H
#define PREFIX_zzz_TEST_DUMMY3_H zzz_TEST_DUMMY3_H
EOO

View File

@ -32,7 +32,7 @@ namespace build2
autoconf::flavor flavor;
string prefix;
const alias_map* aliases;
map<string, string> checks; // Checks already seen.
set<string> checks; // Checks already seen.
const autoconf::rule& rule;
@ -499,13 +499,6 @@ namespace build2
// 1. Suppress if a duplicate (we do it regardless of whether it is
// from the catalog or custom).
//
// Which name should we store, prefixed or prefixless? If we store
// prefixed, then it won't be easy to match bases which are
// specified without a prefix: we will have to add the prefix
// unless the check is unprefixable, which we can only know by
// looking it up. So we store prefixless. Actually, it's convenient
// to store both.
//
// 2. Check for a custom value falling through if found.
//
// Here things get a bit tricky: while a stray HAVE_* buildfile
@ -520,6 +513,16 @@ namespace build2
// 3. Look in the catalog and fall through if not found.
//
// 4. Return the build-in value from the catalog.
// Note: this line must be recognizable by substitute_special().
//
if (md.checks.find (n) != md.checks.end ())
return "/* " + n + " already defined. */";
md.checks.insert (n);
// Note that if there is no prefix in the name, then we only look for
// an unprefixable built-in check.
//
auto deprefix = [&md] (const string& n) -> const char*
{
@ -535,19 +538,9 @@ namespace build2
return n.c_str ();
};
// Note that if there is no prefix in the name, then we only look for
// an unprefixable built-in check.
//
const char* pn (deprefix (n)); // Prefixless name.
const char* en (pn != nullptr ? pn : n.c_str ()); // Effective name.
// Note: this line must be recognizable by substitute_special().
//
if (md.checks.find (en) != md.checks.end ())
return "/* " + n + " already defined. */";
md.checks.emplace (en, n);
// If up is true, only look for an unprefixable check.
//
auto find = [] (const char* n, bool up = false) -> const check*
@ -664,23 +657,9 @@ namespace build2
{
string pn (bs, b, e - b); // Prefixless name.
// First supress duplicates.
// We have to look it up before suppressing duplicates to know
// whether it should be prefixed.
//
{
auto i (md.checks.find (pn));
if (i != md.checks.end ())
{
append (("/* Base " +
i->second +
" already defined. */").c_str ());
if (pn != i->second)
ns.push_back (move (pn));
continue;
}
}
const check* c (find (pn.c_str ()));
// While it may be overridden by the user, we should also have
@ -696,7 +675,19 @@ namespace build2
string n ((up ? string () : md.prefix) + pn);
md.checks.emplace (pn, n);
// Supress duplicates.
//
if (md.checks.find (n) != md.checks.end ())
{
append (("/* Base " + n + " already defined. */").c_str ());
if (!up)
ns.push_back (move (pn));
continue;
}
md.checks.insert (n);
if (custom (n))
append (this->in::rule::lookup (