From ffe4e19c91e9290dd4737e3a1e601adf6ae08461 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 25 Sep 2023 09:12:34 +0200 Subject: Treat empty --archive-lang* values as request to clear previous entries --- bpkg/pkg-bindist.cli | 3 +- bpkg/system-package-manager-archive.cxx | 50 ++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/bpkg/pkg-bindist.cli b/bpkg/pkg-bindist.cli index 59a98f7..1401723 100644 --- a/bpkg/pkg-bindist.cli +++ b/bpkg/pkg-bindist.cli @@ -698,7 +698,8 @@ namespace bpkg the mapping specified with this option is only considered if the package type is a library (for other package types all languages used are implementation). Note also that multiple runtime ids specified for - the same language are combined." + the same language are combined except for an empty id, which is treated + as a request to clear previous entries." } std::multimap --archive-lang-impl diff --git a/bpkg/system-package-manager-archive.cxx b/bpkg/system-package-manager-archive.cxx index 311893b..d46e6d6 100644 --- a/bpkg/system-package-manager-archive.cxx +++ b/bpkg/system-package-manager-archive.cxx @@ -546,7 +546,9 @@ namespace bpkg // @@ Maybe we should just do "soft" version like in ? // // Note that we allow multiple values for the same language to support - // cases like --archive-lang cc=gcc12 --archive-lang cc=g++12. + // cases like --archive-lang cc=gcc12 --archive-lang cc=g++12. But + // we treat an empty value as a request to clear all the previous + // entries. // auto find = [] (const std::multimap& m, const string& n) @@ -564,18 +566,36 @@ namespace bpkg return p; }; - auto add = [&langrt] (const pair& p) + // We don't want to clear entries specified with --*-lang with an empty + // value specified with --*-lang-impl. + // + size_t clear_limit (0); + + auto add = [&langrt, &clear_limit] (const pair& p) { // Suppress duplicates. // - if (find_if (langrt.begin (), langrt.end (), - [&p] (const pair& x) - { - // @@ TODO: keep highest version. - return p.second == x.second; - }) == langrt.end ()) + if (!p.second.empty ()) + { + if (find_if (langrt.begin (), langrt.end (), + [&p] (const pair& x) + { + // @@ TODO: keep highest version. + return p.second == x.second; + }) == langrt.end ()) + { + langrt.push_back (p); + } + } + else if (clear_limit != langrt.size ()) { - langrt.push_back (p); + for (auto i (langrt.begin () + clear_limit); i != langrt.end (); ) + { + if (i->get ().first == p.first) + i = langrt.erase (i); + else + ++i; + } } }; @@ -605,13 +625,10 @@ namespace bpkg info << "or alternatively specify --archive-build-meta"; for (auto i (p.first); i != p.second; ++i) - { - if (i->second.empty ()) - continue; // Unimportant. - add (*i); - } } + + clear_limit = langrt.size (); } for (const language& l: langs) @@ -625,12 +642,7 @@ namespace bpkg continue; // Unimportant. for (auto i (p.first); i != p.second; ++i) - { - if (i->second.empty ()) - continue; // Unimportant. - add (*i); - } } } -- cgit v1.1