diff options
author | Julian Andres Klode <jak@debian.org> | 2021-10-18 13:36:00 +0000 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2021-10-18 13:36:00 +0000 |
commit | edf4b2169405e7ca6e21f408229e5fc4bbd4f4ed (patch) | |
tree | 864a13dbda22e3b4de7b69600521fb7e7d8b39a2 /apt-pkg | |
parent | 883a12310a4130370965eab0a710a2c8fae6cc09 (diff) | |
parent | 70c669e2566d119559d2986635bb6c1d0d368073 (diff) |
Merge branch 'feature/barbarianarchs' into 'main'
Streamline access to barbarian architecture functionality
See merge request apt-team/apt!184
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/aptconfiguration.cc | 22 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 17 | ||||
-rw-r--r-- | apt-pkg/deb/debmetaindex.cc | 20 | ||||
-rw-r--r-- | apt-pkg/edsp.cc | 43 | ||||
-rw-r--r-- | apt-pkg/pkgcache.cc | 5 | ||||
-rw-r--r-- | apt-pkg/pkgcache.h | 2 | ||||
-rw-r--r-- | apt-pkg/pkgcachegen.cc | 10 |
7 files changed, 67 insertions, 52 deletions
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 671c3d553..00a97a0e7 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -315,13 +315,11 @@ bool Configuration::checkLanguage(std::string Lang, bool const All) { /*}}}*/ // getArchitectures - Return Vector of preferred Architectures /*{{{*/ std::vector<std::string> const Configuration::getArchitectures(bool const &Cached) { - using std::string; - - std::vector<string> static archs; + std::vector<std::string> static archs; if (likely(Cached == true) && archs.empty() == false) return archs; - string const arch = _config->Find("APT::Architecture"); + std::string const arch = _config->Find("APT::Architecture"); archs = _config->FindVector("APT::Architectures"); if (archs.empty() == true && _system != nullptr) @@ -331,15 +329,13 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache std::find(archs.begin(), archs.end(), arch) == archs.end()) archs.insert(archs.begin(), arch); - // erase duplicates and empty strings - for (std::vector<string>::reverse_iterator a = archs.rbegin(); - a != archs.rend(); ++a) { - if (a->empty() == true || std::find(a + 1, archs.rend(), *a) != archs.rend()) - archs.erase(a.base()-1); - if (a == archs.rend()) - break; - } - + // erase duplicates, empty strings and very foreign architectures + auto newend = std::remove_if(archs.begin(), archs.end(), [](auto const &a) { return a.empty(); }); + for (auto a = archs.begin(); a != newend; ++a) + newend = std::remove(std::next(a), newend, *a); + for (auto const &f : _config->FindVector("APT::BarbarianArchitectures")) + newend = std::remove(archs.begin(), newend, f); + archs.erase(newend, archs.end()); return archs; } /*}}}*/ diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 966246ca7..2f0ebaa7b 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -823,6 +823,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver, return true; string const pkgArch = Ver.Arch(); + bool const barbarianArch = not APT::Configuration::checkArchitecture(pkgArch); while (1) { @@ -843,7 +844,14 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver, } else if (Package.substr(found) == ":any") { - if (NewDepends(Ver,Package,"any",Version,Op,Type) == false) + if (barbarianArch) + { + if (not NewDepends(Ver, Package, "any", Version, Op | pkgCache::Dep::Or, Type)) + return false; + if (not NewDepends(Ver, Package.substr(0, found), pkgArch, Version, Op, Type)) + return false; + } + else if (not NewDepends(Ver, Package, "any", Version, Op, Type)) return false; } else @@ -888,6 +896,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) } string const Arch = Ver.Arch(); + bool const barbarianArch = not APT::Configuration::checkArchitecture(Arch); const char *Start; const char *Stop; if (Section.Find(pkgTagSection::Key::Provides,Start,Stop) == true) @@ -914,7 +923,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) if (NewProvides(Ver, Package, "any", Version, pkgCache::Flag::ArchSpecific) == false) return false; } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) { - if (APT::Configuration::checkArchitecture(Arch)) + if (not barbarianArch) { if (NewProvidesAllArch(Ver, Package, Version, 0) == false) return false; @@ -922,7 +931,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) else if (NewProvides(Ver, Package, Arch, Version, 0) == false) return false; } else { - if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed) + if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed && not barbarianArch) { if (NewProvides(Ver, Package.to_string().append(":any"), "any", Version, pkgCache::Flag::MultiArchImplicit) == false) return false; @@ -945,7 +954,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) } while (Start != Stop); } - if (APT::Configuration::checkArchitecture(Arch)) + if (not barbarianArch) { if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed) { diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index f24a5e79e..d78cea758 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -18,6 +18,7 @@ #include <algorithm> #include <map> +#include <optional> #include <sstream> #include <string> #include <utility> @@ -966,13 +967,13 @@ pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool con class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ { - static std::vector<std::string> getDefaultSetOf(std::string const &Name, - std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues) + static std::optional<std::vector<std::string>> getDefaultSetOf(std::string const &Name, + std::map<std::string, std::string> const &Options) { auto const val = Options.find(Name); if (val != Options.end()) return VectorizeString(val->second, ','); - return defaultValues; + return {}; } static std::vector<std::string> applyPlusMinusOptions(std::string const &Name, std::map<std::string, std::string> const &Options, std::vector<std::string> &&Values) @@ -997,12 +998,21 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ static std::vector<std::string> parsePlusMinusOptions(std::string const &Name, std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues) { - return applyPlusMinusOptions(Name, Options, getDefaultSetOf(Name, Options, defaultValues)); + return applyPlusMinusOptions(Name, Options, getDefaultSetOf(Name, Options).value_or(defaultValues)); } static std::vector<std::string> parsePlusMinusArchOptions(std::string const &Name, std::map<std::string, std::string> const &Options) { - auto Values = getDefaultSetOf(Name, Options, APT::Configuration::getArchitectures()); + std::vector<std::string> Values; + if (auto opt = getDefaultSetOf(Name, Options); opt.has_value()) + Values = opt.value(); + else + { + Values = APT::Configuration::getArchitectures(); + auto veryforeign = _config->FindVector("APT::BarbarianArchitectures"); + Values.reserve(Values.size() + veryforeign.size()); + std::move(veryforeign.begin(), veryforeign.end(), std::back_inserter(Values)); + } // all is a very special architecture users shouldn't be concerned with explicitly // but if the user does, do not override the choice auto const val = Options.find(Name + "-"); diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 7e3993be4..b7c0d28d2 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -8,6 +8,7 @@ #include <config.h> #include <apt-pkg/algorithms.h> +#include <apt-pkg/aptconfiguration.h> #include <apt-pkg/cacheset.h> #include <apt-pkg/depcache.h> #include <apt-pkg/edsp.h> @@ -205,6 +206,25 @@ static bool WriteScenarioLimitedDependency(FileFd &output, return WriteOkay(Okay, output, "\n"); } /*}}}*/ +static bool checkKnownArchitecture(std::string const &arch) /*{{{*/ +{ + if (APT::Configuration::checkArchitecture(arch)) + return true; + static auto const veryforeign = _config->FindVector("APT::BarbarianArchitectures"); + return std::find(veryforeign.begin(), veryforeign.end(), arch) != veryforeign.end(); +} + /*}}}*/ +static bool WriteGenericRequestHeaders(FileFd &output, APT::StringView const head)/*{{{*/ +{ + bool Okay = WriteOkay(output, head, "Architecture: ", _config->Find("APT::Architecture"), "\n", + "Architectures:"); + for (auto const &a : APT::Configuration::getArchitectures()) + WriteOkay(Okay, output, " ", a); + for (auto const &a : _config->FindVector("APT::BarbarianArchitectures")) + WriteOkay(Okay, output, " ", a); + return WriteOkay(Okay, output, "\n"); +} + /*}}}*/ static bool SkipUnavailableVersions(pkgDepCache &Cache, pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver)/*{{{*/ { /* versions which aren't current and aren't available in @@ -266,11 +286,9 @@ bool EDSP::WriteScenario(pkgDepCache &Cache, FileFd &output, OpProgress *Progres Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver")); decltype(Cache.Head().VersionCount) p = 0; bool Okay = output.Failed() == false; - std::vector<std::string> archs = APT::Configuration::getArchitectures(); for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false && likely(Okay); ++Pkg) { - std::string const arch = Pkg.Arch(); - if (Pkg->CurrentVer == 0 && std::find(archs.begin(), archs.end(), arch) == archs.end()) + if (Pkg->CurrentVer == 0 && not checkKnownArchitecture(Pkg.Arch())) continue; for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false && likely(Okay); ++Ver, ++p) { @@ -341,15 +359,8 @@ bool EDSP::WriteRequest(pkgDepCache &Cache, FileFd &output, continue; req->append(" ").append(Pkg.FullName()); } - bool Okay = WriteOkay(output, "Request: EDSP 0.5\n"); - - std::vector<string> archs = APT::Configuration::getArchitectures(); - WriteOkay(Okay, output, "Architecture: ", _config->Find("APT::Architecture").c_str(), "\n", - "Architectures:"); - for (std::vector<string>::const_iterator a = archs.begin(); a != archs.end(); ++a) - WriteOkay(Okay, output, " ", *a); - WriteOkay(Okay, output, "\n"); + bool Okay = WriteGenericRequestHeaders(output, "Request: EDSP 0.5\n"); if (del.empty() == false) WriteOkay(Okay, output, "Remove:", del, "\n"); if (inst.empty() == false) @@ -863,15 +874,8 @@ bool EIPP::WriteRequest(pkgDepCache &Cache, FileFd &output, /*{{{*/ continue; req->append(" ").append(Pkg.FullName()); } - bool Okay = WriteOkay(output, "Request: EIPP 0.1\n"); - - std::vector<string> archs = APT::Configuration::getArchitectures(); - WriteOkay(Okay, output, "Architecture: ", _config->Find("APT::Architecture").c_str(), "\n", - "Architectures:"); - for (std::vector<string>::const_iterator a = archs.begin(); a != archs.end(); ++a) - WriteOkay(Okay, output, " ", *a); - WriteOkay(Okay, output, "\n"); + bool Okay = WriteGenericRequestHeaders(output, "Request: EIPP 0.1\n"); if (del.empty() == false) WriteOkay(Okay, output, "Remove:", del, "\n"); if (inst.empty() == false) @@ -934,7 +938,6 @@ bool EIPP::WriteScenario(pkgDepCache &Cache, FileFd &output, OpProgress * const Progress->SubProgress(Cache.Head().PackageCount, _("Send scenario to planner")); decltype(Cache.Head().PackageCount) p = 0; bool Okay = output.Failed() == false; - std::vector<std::string> archs = APT::Configuration::getArchitectures(); std::vector<bool> pkgset(Cache.Head().PackageCount, false); auto const MarkVersion = [&](pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver) { pkgset[Pkg->ID] = true; diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index cbde7c42f..68efcaddc 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -127,10 +127,7 @@ bool pkgCache::Header::CheckSizes(Header &Against) const /* */ pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map), VS(nullptr), d(NULL) { - // call getArchitectures() with cached=false to ensure that the - // architectures cache is re-evaluated. this is needed in cases - // when the APT::Architecture field changes between two cache creations - MultiArchEnabled = APT::Configuration::getArchitectures(false).size() > 1; + MultiArchEnabled = true; if (DoMap == true) ReMap(); } diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 55baa3cef..0e8046ddc 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -268,7 +268,7 @@ class APT_PUBLIC pkgCache /*{{{*/ inline RlsFileIterator RlsFileBegin(); inline RlsFileIterator RlsFileEnd(); - inline bool MultiArchCache() const { return MultiArchEnabled; } + APT_DEPRECATED_MSG("Always true") inline bool MultiArchCache() const { return MultiArchEnabled; } inline char const * NativeArch(); // Make me a function diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index b4fd0641e..807f3bf6c 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -626,16 +626,16 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg, StringView Name, pkgCache::PkgIterator const M = Grp.FindPreferredPkg(false); // native or any foreign pkg will do if (M.end() == false) { pkgCache::PrvIterator Prv; + pkgCache::VerIterator Ver; Dynamic<pkgCache::PrvIterator> DynPrv(Prv); + Dynamic<pkgCache::VerIterator> DynVer(Ver); for (Prv = M.ProvidesList(); Prv.end() == false; ++Prv) { if ((Prv->Flags & pkgCache::Flag::ArchSpecific) != 0) continue; - pkgCache::VerIterator Ver = Prv.OwnerVer(); - Dynamic<pkgCache::VerIterator> DynVer(Ver); - if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed || - ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign && - (Prv->Flags & pkgCache::Flag::MultiArchImplicit) == 0)) + Ver = Prv.OwnerVer(); + if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign && + (Prv->Flags & pkgCache::Flag::MultiArchImplicit) == 0) { if (APT::Configuration::checkArchitecture(Ver.ParentPkg().Arch()) == false) continue; |