Bug#275379: apt-get: please support "satisfy"
Package: apt
Severity: wishlist
Tags: patch
Hi,
please support the possibility to just give some dependencies and have
them satisfied. A patch is attached.
Thanks for consideration.
Cheers,
Andi
Only in apt-0.5.27-new: build
diff -ur apt-0.5.27/cmdline/apt-get.cc apt-0.5.27-new/cmdline/apt-get.cc
--- apt-0.5.27/cmdline/apt-get.cc Thu Feb 26 20:17:55 2004
+++ apt-0.5.27-new/cmdline/apt-get.cc Sun Sep 5 20:00:38 2004
@@ -39,7 +39,9 @@
#include <apt-pkg/cachefile.h>
#include <apt-pkg/sptr.h>
#include <apt-pkg/versionmatch.h>
-
+#include <apt-pkg/deblistparser.h>
+#include <apt-pkg/debsrcrecords.h>
+
#include <config.h>
#include <apti18n.h>
@@ -58,6 +60,7 @@
#include <errno.h>
#include <regex.h>
#include <sys/wait.h>
+#include <string>
/*}}}*/
using namespace std;
@@ -2234,6 +2237,205 @@
return true;
}
/*}}}*/
+// DoSatisfy - 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. */
+bool DoSatisfy(CommandLine &CmdL)
+{
+ CacheFile Cache;
+ if (Cache.Open(true) == false)
+ return false;
+
+ if (CmdL.FileSize() <= 1)
+ return _error->Error(_("Must specify at least one package to check builddeps for"));
+
+ string dependencylist;
+ for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+ dependencylist += ((string) *I + (string) " ");
+
+ vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
+ BuildDeps.clear();
+ pkgSrcRecords::Parser::BuildDepRec rec;
+
+ const char *Start, *Stop;
+ Start=dependencylist.c_str();
+ Stop=dependencylist.c_str()+strlen(dependencylist.c_str())-1;
+ while (1)
+ {
+ Start = debListParser::ParseDepends(Start, Stop,
+ rec.Package,rec.Version,rec.Op,true);
+ if (Start == 0)
+ return _error->Error("Problem parsing dependency: %s", "satisfy");
+ rec.Type = 0; // strictly speaking, we don't need it ...
+ if (rec.Package != "")
+ BuildDeps.push_back(rec);
+ if (Start == Stop)
+ break;
+ }
+
+ printf("Number of dependencies: %i\n", BuildDeps.size());
+
+ // Install the requested packages
+ unsigned int ExpectedInst = 0;
+ vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
+ pkgProblemResolver Fix(Cache);
+ bool skipAlternatives = false; // skip remaining alternatives in an or group
+ for (D = BuildDeps.begin(); D != BuildDeps.end(); D++)
+ {
+ bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or);
+
+ if (skipAlternatives == true)
+ {
+ if (!hasAlternatives)
+ skipAlternatives = false; // end of or group
+ continue;
+ }
+
+ {
+ pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package);
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << "Looking for " << (*D).Package << "...\n";
+
+ if (Pkg.end() == true)
+ {
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " (not found)" << (*D).Package << endl;
+
+ if (hasAlternatives)
+ continue;
+
+ return _error->Error(_("%s dependency for %s cannot be satisfied "
+ "because the package %s cannot be found"),
+ "build","cmdline",
+ (*D).Package.c_str());
+ }
+
+ /*
+ * if there are alternatives, we've already picked one, so skip
+ * the rest
+ *
+ * TODO: this means that if there's a build-dep on A|B and B is
+ * installed, we'll still try to install A; more importantly,
+ * if A is currently broken, we cannot go back and try B. To fix
+ * this would require we do a Resolve cycle for each package we
+ * add to the install list. Ugh
+ */
+
+ /*
+ * If this is a virtual package, we need to check the list of
+ * packages that provide it and see if any of those are
+ * installed
+ */
+ pkgCache::PrvIterator Prv = Pkg.ProvidesList();
+ for (; Prv.end() != true; Prv++)
+ {
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " Checking provider " << Prv.OwnerPkg().Name() << endl;
+
+ if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
+ break;
+ }
+
+ // Get installed version and version we are going to install
+ pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
+
+ if ((*D).Version[0] != '\0') {
+ // Versioned dependency
+
+ pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
+
+ for (; CV.end() != true; CV++)
+ {
+ if (Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
+ break;
+ }
+ if (CV.end() == true)
+ if (hasAlternatives)
+ {
+ continue;
+ }
+ else
+ {
+ return _error->Error(_("%s dependency for %s cannot be satisfied "
+ "because no available versions of package %s "
+ "can satisfy version requirements"),
+ "build", "cmdline",
+ (*D).Package.c_str());
+ }
+ }
+ else
+ {
+ // Only consider virtual packages if there is no versioned dependency
+ if (Prv.end() == false)
+ {
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " Is provided by installed package " << Prv.OwnerPkg().Name() << endl;
+ skipAlternatives = hasAlternatives;
+ continue;
+ }
+ }
+
+ if (IV.end() == false)
+ {
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " Is installed\n";
+
+ if (Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
+ {
+ skipAlternatives = hasAlternatives;
+ continue;
+ }
+
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " ...but the installed version doesn't meet the version requirement\n";
+
+ if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq)
+ {
+ return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
+ "build", "cmdline",
+ Pkg.Name());
+ }
+ }
+
+
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " Trying to install " << (*D).Package << endl;
+
+ if (TryToInstall(Pkg,Cache,Fix,false,false,ExpectedInst) == true)
+ {
+ // We successfully installed something; skip remaining alternatives
+ skipAlternatives = hasAlternatives;
+ continue;
+ }
+ else if (hasAlternatives)
+ {
+ if (_config->FindB("Debug::BuildDeps",false) == true)
+ cout << " Unsatisfiable, trying alternatives\n";
+ continue;
+ }
+ else
+ {
+ return _error->Error(_("Failed to satisfy %s dependency for %s: %s"),
+ "build", "cmdline",
+ (*D).Package.c_str());
+ }
+ }
+
+ Fix.InstallProtect();
+ if (Fix.Resolve(true) == false)
+ _error->Discard();
+
+ // Now we check the state of the packages,
+ if (Cache->BrokenCount() != 0)
+ return _error->Error(_("Build-dependencies could not be satisfied."));
+ }
+
+ if (InstallPackages(Cache, false, true) == false)
+ return _error->Error(_("Failed to process build dependencies"));
+ return true;
+}
+ /*}}}*/
// DoMoo - Never Ask, Never Tell /*{{{*/
// ---------------------------------------------------------------------
@@ -2422,6 +2624,7 @@
{"dist-upgrade",&DoDistUpgrade},
{"dselect-upgrade",&DoDSelectUpgrade},
{"build-dep",&DoBuildDep},
+ {"satisfy",&DoSatisfy},
{"clean",&DoClean},
{"autoclean",&DoAutoClean},
{"check",&DoCheck},
Only in apt-0.5.27-new/debian: copyright
Reply to: