+
+ if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true)
+ {
+ // We successfully installed something; skip remaining alternatives
+ skipAlternatives = hasAlternatives;
+ if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true)
+ Cache->MarkAuto(Pkg, true);
+ continue;
+ }
+ else if (hasAlternatives)
+ {
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ std::cout << " Unsatisfiable, trying alternatives\n";
+ continue;
+ }
+ else
+ {
+ return _error->Error(_("Failed to satisfy %s dependency for %s: %s"),
+ pkgSrcRecords::Parser::BuildDepType(D->Type),
+ Src.c_str(),
+ (*D).Package.c_str());
+ }
+ }
+ }
+
+ if (Fix.Resolve(true) == false)
+ _error->Discard();
+
+ // Now we check the state of the packages,
+ if (Cache->BrokenCount() != 0)
+ {
+ ShowBroken(std::cout, Cache, false);
+ return _error->Error(_("Build-dependencies for %s could not be satisfied."), Src.c_str());
+ }
+ return true;
+}
+ /*}}}*/
+// DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
+// ---------------------------------------------------------------------
+/* This function will look at the build depends list of the given source
+ package and install the necessary packages to make it true, or fail. */
+static std::vector<pkgSrcRecords::Parser::BuildDepRec> GetBuildDeps(pkgSrcRecords::Parser * const Last,
+ char const * const Src, bool const StripMultiArch, std::string const &hostArch)
+{
+ std::vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
+ // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
+ if (hostArch.empty() == false)
+ {
+ std::string nativeArch = _config->Find("APT::Architecture");
+ _config->Set("APT::Architecture", hostArch);
+ bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
+ _config->Set("APT::Architecture", nativeArch);
+ if (Success == false)
+ {
+ _error->Error(_("Unable to get build-dependency information for %s"), Src);
+ return {};
+ }
+ }
+ else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
+ {
+ _error->Error(_("Unable to get build-dependency information for %s"), Src);
+ return {};
+ }
+
+ if (BuildDeps.empty() == true)
+ ioprintf(c1out,_("%s has no build depends.\n"), Src);
+
+ return BuildDeps;
+}
+bool DoBuildDep(CommandLine &CmdL)
+{
+ CacheFile Cache;
+ std::vector<char const *> VolatileCmdL;
+ Cache.GetSourceList()->AddVolatileFiles(CmdL, &VolatileCmdL);
+
+ _config->Set("APT::Install-Recommends", false);
+
+ bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false;
+
+ if (Cache.Open(WantLock) == false)
+ return false;
+
+ if (CmdL.FileSize() <= 1 && VolatileCmdL.empty())
+ return _error->Error(_("Must specify at least one package to check builddeps for"));
+
+ // Read the source list
+ if (Cache.BuildSourceList() == false)
+ return false;
+ pkgSourceList *List = Cache.GetSourceList();
+
+ // Create the text record parsers
+ pkgSrcRecords SrcRecs(*List);
+ if (_error->PendingError() == true)
+ return false;
+
+ bool StripMultiArch;
+ std::string hostArch = _config->Find("APT::Get::Host-Architecture");
+ if (hostArch.empty() == false)
+ {
+ std::vector<std::string> archs = APT::Configuration::getArchitectures();
+ if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
+ return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
+ StripMultiArch = false;
+ }
+ else
+ StripMultiArch = true;
+
+ // deal with the build essentials first
+ {
+ std::vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
+
+ Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
+ if (Opts)
+ Opts = Opts->Child;
+ for (; Opts; Opts = Opts->Next)
+ {
+ if (Opts->Value.empty() == true)
+ continue;
+
+ pkgSrcRecords::Parser::BuildDepRec rec;
+ rec.Package = Opts->Value;
+ rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
+ rec.Op = 0;
+ BuildDeps.push_back(rec);