- if (_config->FindB("Debug::BuildDeps",false) == true)
- std::cout << "Looking for " << (*D).Package << "...\n";
-
- pkgCache::PkgIterator Pkg;
-
- // Cross-Building?
- if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
- {
- size_t const colon = D->Package.find(":");
- if (colon != std::string::npos)
- {
- if (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);
- }
- else
- Pkg = Cache->FindPkg(D->Package, hostArch);
-
- // a bad version either is invalid or doesn't satify dependency
-#define BADVER(Ver) (Ver.end() == true || \
- (D->Version.empty() == false && \
- Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
-
- APT::VersionList verlist;
- if (Pkg.end() == false)
- {
- pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache);
- if (BADVER(Ver) == false)
- verlist.insert(Ver);
- Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
- if (BADVER(Ver) == false)
- verlist.insert(Ver);
- }
- if (verlist.empty() == true)
- {
- pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native");
- if (BuildPkg.end() == false && Pkg != BuildPkg)
- {
- pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache);
- if (BADVER(Ver) == false)
- verlist.insert(Ver);
- Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache);
- if (BADVER(Ver) == false)
- verlist.insert(Ver);
- }
- }
-#undef BADVER
-
- std::string forbidden;
- // We need to decide if host or build arch, so find a version we can look at
- APT::VersionList::const_iterator Ver = verlist.begin();
- for (; Ver != verlist.end(); ++Ver)
- {
- forbidden.clear();
- if (Ver->MultiArch == pkgCache::Version::No || Ver->MultiArch == pkgCache::Version::All)
- {
- if (colon == std::string::npos)
- Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
- else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
- forbidden = "Multi-Arch: no";
- else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
- Pkg = Ver.ParentPkg().Group().FindPkg("native");
- }
- else if (Ver->MultiArch == pkgCache::Version::Same)
- {
- if (colon == std::string::npos)
- Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
- else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
- forbidden = "Multi-Arch: same";
- else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
- Pkg = Ver.ParentPkg().Group().FindPkg("native");
- }
- else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
- {
- if (colon == std::string::npos)
- Pkg = Ver.ParentPkg().Group().FindPkg("native");
- else if (strcmp(D->Package.c_str() + colon, ":any") == 0 ||
- strcmp(D->Package.c_str() + colon, ":native") == 0)
- forbidden = "Multi-Arch: foreign";
- }
- else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
- {
- if (colon == std::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);
- }
- else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
- Pkg = Ver.ParentPkg().Group().FindPkg("native");
- }
-
- if (forbidden.empty() == false)
- {
- if (_config->FindB("Debug::BuildDeps",false) == true)
- std::cout << D->Package.substr(colon, std::string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << std::endl;
- continue;
- }
-
- //we found a good version
- break;
- }
- if (Ver == verlist.end())
- {
- if (_config->FindB("Debug::BuildDeps",false) == true)
- std::cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << std::endl;
-
- if (forbidden.empty() == false)
- {
- 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(), forbidden.c_str());
- }
- }
- }