From 9169cd5049bd7f0d5dcc56c40d567a766cf5b851 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Jan 2018 16:15:13 +0100 Subject: Extend apt build-dep pkg/release to switch dep as needed apt install pkg/release follows versioned dependencies in the candidate switching if the current candidate does not satisfy the dependency, so for uniformity the same should be supported in build-dep. --- apt-private/private-install.cc | 12 +++++- apt-private/private-source.cc | 38 ++++++++++++++--- test/integration/test-apt-source-and-build-dep | 59 ++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 8 deletions(-) diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index e1beb21c6..c9e45cc00 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -945,13 +945,21 @@ bool TryToInstall::propergateReleaseCandiateSwitching(std::listsecond.end() == true) + { + auto const pkgname = c->first.ParentPkg().FullName(true); + if (APT::String::Startswith(pkgname, "builddeps:")) + continue; ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), - c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str()); + c->first.VerStr(), c->first.RelStr().c_str(), pkgname.c_str()); + } else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group) { + auto pkgname = c->second.ParentPkg().FullName(true); + if (APT::String::Startswith(pkgname, "builddeps:")) + pkgname.replace(0, strlen("builddeps"), "src"); pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache); ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(), - V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str()); + V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), pkgname.c_str()); } } return Success; diff --git a/apt-private/private-source.cc b/apt-private/private-source.cc index 32651cfdb..a24493421 100644 --- a/apt-private/private-source.cc +++ b/apt-private/private-source.cc @@ -658,7 +658,15 @@ bool DoBuildDep(CommandLine &CmdL) StripMultiArch = true; std::ostringstream buildDepsPkgFile; - std::vector> pseudoPkgs; + struct PseudoPkg + { + std::string name; + std::string arch; + std::string release; + PseudoPkg(std::string const &n, std::string const &a, std::string const &r) : + name(n), arch(a), release(r) {} + }; + std::vector pseudoPkgs; // deal with the build essentials first { std::vector BuildDeps; @@ -675,7 +683,7 @@ bool DoBuildDep(CommandLine &CmdL) std::string const pseudo = "builddeps:essentials"; std::string const nativeArch = _config->Find("APT::Architecture"); WriteBuildDependencyPackage(buildDepsPkgFile, pseudo, nativeArch, BuildDeps); - pseudoPkgs.emplace_back(pseudo, nativeArch); + pseudoPkgs.emplace_back(pseudo, nativeArch, ""); } // Read the source list @@ -703,7 +711,7 @@ bool DoBuildDep(CommandLine &CmdL) std::string const pseudo = std::string("builddeps:") + Src; WriteBuildDependencyPackage(buildDepsPkgFile, pseudo, pseudoArch, GetBuildDeps(Last.get(), Src.c_str(), StripMultiArch, hostArch)); - pseudoPkgs.emplace_back(pseudo, pseudoArch); + pseudoPkgs.emplace_back(pseudo, pseudoArch, ""); } } else @@ -731,7 +739,13 @@ bool DoBuildDep(CommandLine &CmdL) std::string const pseudo = std::string("builddeps:") + Src; WriteBuildDependencyPackage(buildDepsPkgFile, pseudo, pseudoArch, GetBuildDeps(Last, Src.c_str(), StripMultiArch, hostArch)); - pseudoPkgs.emplace_back(pseudo, pseudoArch); + std::string reltag = *I; + size_t found = reltag.find_last_of("/"); + if (found == std::string::npos) + reltag.clear(); + else + reltag.erase(0, found + 1); + pseudoPkgs.emplace_back(pseudo, pseudoArch, std::move(reltag)); } } @@ -745,12 +759,24 @@ bool DoBuildDep(CommandLine &CmdL) { pkgDepCache::ActionGroup group(Cache); TryToInstall InstallAction(Cache, &Fix, false); + std::list> candSwitch; + for (auto const &pkg: pseudoPkgs) + { + pkgCache::PkgIterator const Pkg = Cache->FindPkg(pkg.name, pkg.arch); + if (Pkg.end()) + continue; + if (pkg.release.empty()) + Cache->SetCandidateVersion(Pkg.VersionList()); + else + candSwitch.emplace_back(Pkg.VersionList(), pkg.release); + } + if (candSwitch.empty() == false) + InstallAction.propergateReleaseCandiateSwitching(candSwitch, c0out); for (auto const &pkg: pseudoPkgs) { - pkgCache::PkgIterator const Pkg = Cache->FindPkg(pkg.first, pkg.second); + pkgCache::PkgIterator const Pkg = Cache->FindPkg(pkg.name, pkg.arch); if (Pkg.end()) continue; - Cache->SetCandidateVersion(Pkg.VersionList()); InstallAction(Cache[Pkg].CandidateVerIter(Cache)); removeAgain.push_back(Pkg); } diff --git a/test/integration/test-apt-source-and-build-dep b/test/integration/test-apt-source-and-build-dep index 7f7457217..24790a578 100755 --- a/test/integration/test-apt-source-and-build-dep +++ b/test/integration/test-apt-source-and-build-dep @@ -14,6 +14,10 @@ insertpackage 'wheezy' 'build-essential' 'all' '1.0' # a "normal" package with source and binary insertpackage 'unstable' 'foo' 'all' '2.0' insertsource 'unstable' 'foo' 'all' '2.0' +insertpackage 'unstable' 'foo-common' 'all' '2.0' 'Source: foo (2.0)' +insertpackage 'experimental' 'foo' 'all' '5' 'Depends: foo-common (= 5)' +insertpackage 'experimental' 'foo-common' 'all' '5' 'Source: foo (5)' +insertsource 'experimental' 'foo-source' 'all' '42' 'Build-Depends: foo (= 5), baz' # binary packages with Source-field insertpackage 'unstable,testing' 'bin' 'i386' '3-2+b1' 'Source: bin (3-2)' @@ -40,6 +44,8 @@ insertsource 'wheezy' 'foo' 'all' '0.1' insertsource 'stable' 'baz' 'all' '1.0' insertsource 'unstable' 'baz' 'all' '2.0' insertsource 'unstable' 'baz' 'all' '1.5' +insertpackage 'unstable' 'baz' 'all' '2.0' +insertpackage 'experimental' 'baz' 'all' '5.0' # ensure we really have the situation we wanted (first 2.0 is foo above) testequal 'Version: 2.0 @@ -189,3 +195,56 @@ Need to get 0 B/43 B of source archives. Fetch source bin-backport" apt source bin/stable -s -q testsuccessequal "$(getbuilddep 'bin-backport' "Picking 'bin-backport' as source package instead of 'bin' Selected version '2-2' (stable) for bin-backport")" apt build-dep bin/stable -s + +testsuccess apt install foo/experimental -s +testfailure apt build-dep foo-source -s +testsuccessequal "Reading package lists... +Selected version '42' (experimental) for foo-source +Reading package lists... +Building dependency tree... +Selected version '5' (experimental [all]) for 'foo' because of 'src:foo-source' +Selected version '5' (experimental [all]) for 'foo-common' because of 'foo' +The following NEW packages will be installed: + baz build-essential foo foo-common +0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. +Inst baz (2.0 unstable [all]) +Inst build-essential (1.0 wheezy [all]) +Inst foo-common (5 experimental [all]) +Inst foo (5 experimental [all]) +Conf baz (2.0 unstable [all]) +Conf build-essential (1.0 wheezy [all]) +Conf foo-common (5 experimental [all]) +Conf foo (5 experimental [all])" apt build-dep foo-source/experimental -s +testsuccessequal "Reading package lists... +Selected version '42' (experimental) for foo-source +Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + baz build-essential foo foo-common +0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. +Inst baz (5.0 experimental [all]) +Inst build-essential (1.0 wheezy [all]) +Inst foo-common (5 experimental [all]) +Inst foo (5 experimental [all]) +Conf baz (5.0 experimental [all]) +Conf build-essential (1.0 wheezy [all]) +Conf foo-common (5 experimental [all]) +Conf foo (5 experimental [all])" apt build-dep foo-source -t experimental -s +# this checks that mentioning the source pkg baz has no influence on the binary package baz +testsuccessequal "Reading package lists... +Selected version '42' (experimental) for foo-source +Selected version '2.0' (unstable) for baz +baz has no build depends. +Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + baz build-essential foo foo-common +0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. +Inst baz (5.0 experimental [all]) +Inst build-essential (1.0 wheezy [all]) +Inst foo-common (5 experimental [all]) +Inst foo (5 experimental [all]) +Conf baz (5.0 experimental [all]) +Conf build-essential (1.0 wheezy [all]) +Conf foo-common (5 experimental [all]) +Conf foo (5 experimental [all])" apt build-dep foo-source baz/unstable -t experimental -s -- cgit v1.2.3