From a4f2f99f23575a6cdcde5f18b8778ba2827ceb42 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 21 Mar 2023 06:53:03 +0200 Subject: Allow multiple values for --archive-lang* pkg-bindist option --- bpkg/pkg-bindist.cli | 12 +++++----- bpkg/system-package-manager-archive.cxx | 40 ++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 21 deletions(-) (limited to 'bpkg') diff --git a/bpkg/pkg-bindist.cli b/bpkg/pkg-bindist.cli index 7116e7d..0ea51f9 100644 --- a/bpkg/pkg-bindist.cli +++ b/bpkg/pkg-bindist.cli @@ -531,7 +531,7 @@ namespace bpkg defaults may change in the future." } - std::map --archive-lang + std::multimap --archive-lang { "=", "Map interface language name to runtime id . If no mapping is @@ -540,18 +540,20 @@ namespace bpkg fail. If the information about an interface language is unimportant and should be ignored, then empty runtime id can be specified. Note that 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)." + 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." } - std::map --archive-lang-impl + std::multimap --archive-lang-impl { "=", "Map implementation language name to runtime id . If no mapping is found for an implementation language in this map, then assume the information about this implementation language is unimportant and ignore it (examples of such cases include static linking as well - as a language runtime that is always present)." + as a language runtime that is always present). See \cb{--archive-lang} + for background." } string --archive-build-meta diff --git a/bpkg/system-package-manager-archive.cxx b/bpkg/system-package-manager-archive.cxx index 384a0d5..79d4ca4 100644 --- a/bpkg/system-package-manager-archive.cxx +++ b/bpkg/system-package-manager-archive.cxx @@ -522,24 +522,23 @@ 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. @@ This - // is TODO (need cli support for std::multimap). + // cases like --archive-lang cc=gcc12 --archive-lang cc=g++12. // vector>> langrt; - auto find = [] (const std::map& m, const string& n) + auto find = [] (const std::multimap& m, const string& n) { - auto i (m.find (n)); + auto p (m.equal_range (n)); - if (i == m.end ()) + if (p.first == p.second) { // If no mapping for c/c++, fallback to cc. // if (n == "c" || n == "c++") - i = m.find ("cc"); + p = m.equal_range ("cc"); } - return i != m.end () ? &*i : nullptr; + return p; }; auto add = [&langrt] (const pair& p) @@ -573,20 +572,23 @@ namespace bpkg if (l.impl) continue; - const pair* p (find (intfm, l.name)); + auto p (find (intfm, l.name)); - if (p == nullptr) + if (p.first == p.second) p = find (implm, l.name); - if (p == nullptr) + if (p.first == p.second) fail << "no runtime mapping for language " << l.name << info << "consider specifying with --archive-lang[-impl]" << info << "or alternatively specify --archive-build-meta"; - if (p->second.empty ()) - continue; // Unimportant. + for (auto i (p.first); i != p.second; ++i) + { + if (i->second.empty ()) + continue; // Unimportant. - add (*p); + add (*i); + } } } @@ -595,12 +597,18 @@ namespace bpkg if (lib && !l.impl) continue; - const pair* p (find (implm, l.name)); + auto p (find (implm, l.name)); - if (p == nullptr || p->second.empty ()) + if (p.first == p.second) continue; // Unimportant. - add (*p); + for (auto i (p.first); i != p.second; ++i) + { + if (i->second.empty ()) + continue; // Unimportant. + + add (*i); + } } for (const pair& p: langrt) -- cgit v1.1