+ pkgCache::PkgIterator Pkg;
+
+ // Cross-Building?
+ if (StripMultiArch == false)
+ {
+ size_t const colon = D->Package.find(":");
+ if (colon != string::npos &&
+ (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0))
+ Pkg = Cache->FindPkg(D->Package.substr(0,colon));
+ else
+ Pkg = Cache->FindPkg(D->Package);
+
+ // We need to decide if host or build arch, so find a version we can look at
+ pkgCache::VerIterator Ver;
+
+ // a bad version either is invalid or doesn't satify dependency
+ #define BADVER(Ver) Ver.end() == true || \
+ (Ver.end() == false && D->Version.empty() == false && \
+ Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false)
+
+ if (Pkg.end() == false)
+ {
+ Ver = (*Cache)[Pkg].InstVerIter(*Cache);
+ if (BADVER(Ver))
+ Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
+ }
+ if (BADVER(Ver))
+ {
+ pkgCache::PkgIterator HostPkg = Cache->FindPkg(D->Package, hostArch);
+ if (HostPkg.end() == false)
+ {
+ Ver = (*Cache)[HostPkg].InstVerIter(*Cache);
+ if (BADVER(Ver))
+ Ver = (*Cache)[HostPkg].CandidateVerIter(*Cache);
+ }
+ }
+ if ((BADVER(Ver)) == false)
+ {
+ string forbidden;
+ if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All);
+ else if (Ver->MultiArch == pkgCache::Version::Same)
+ {
+ if (colon != string::npos)
+ Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
+ else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
+ forbidden = "Multi-Arch: same";
+ // :native gets the buildArch
+ }
+ else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign)
+ {
+ if (colon != string::npos)
+ forbidden = "Multi-Arch: foreign";
+ }
+ else if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed)
+ {
+ if (colon == string::npos)
+ Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
+ else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
+ {
+ // prefer any installed over preferred non-installed architectures
+ pkgCache::GrpIterator Grp = Ver.ParentPkg().Group();
+ // we don't check for version here as we are better of with upgrading than remove and install
+ for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
+ if (Pkg.CurrentVer().end() == false)
+ break;
+ if (Pkg.end() == true)
+ Pkg = Grp.FindPreferredPkg(true);
+ }
+ // native gets buildArch
+ }
+ if (forbidden.empty() == false)
+ {
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " :any is not allowed from M-A: same package " << (*D).Package << endl;
+ if (hasAlternatives)
+ continue;
+ return _error->Error(_("%s dependency for %s can't be satisfied "
+ "because %s is not allowed on '%s' packages"),
+ Last->BuildDepType(D->Type), Src.c_str(),
+ D->Package.c_str(), "Multi-Arch: same");
+ }
+ }
+ else if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl;
+ #undef BADVER
+ }
+ else
+ Pkg = Cache->FindPkg(D->Package);
+