]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/edsp.cc
Merge EDSP 0.5 w/ multi-arch support for external solvers
[apt.git] / apt-pkg / edsp.cc
index b125d4bfb3b3b9e68d934225821644d7f0d5d4fa..88ad27681180a2c9e07cd9a75fe6a021731596af 100644 (file)
 #include <apt-pkg/error.h>
 #include <apt-pkg/cacheset.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/version.h>
-#include <apt-pkg/policy.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/progress.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/pkgrecords.h>
 
-#include <limits>
+#include <ctype.h>
+#include <stddef.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
 #include <stdio.h>
-
+#include <iostream>
+#include <vector>
+#include <limits>
 #include <string>
+#include <list>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -44,7 +54,7 @@ bool EDSP::WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress)
       for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver, ++p)
       {
         WriteScenarioVersion(Cache, output, Pkg, Ver);
-        WriteScenarioDependency(Cache, output, Pkg, Ver);
+        WriteScenarioDependency(output, Ver);
         fprintf(output, "\n");
         if (Progress != NULL && p % 100 == 0)
            Progress->Progress(p);
@@ -64,7 +74,7 @@ bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
       for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
       {
         WriteScenarioVersion(Cache, output, Pkg, Ver);
-        WriteScenarioLimitedDependency(Cache, output, Pkg, Ver, pkgset);
+        WriteScenarioLimitedDependency(output, Ver, pkgset);
         fprintf(output, "\n");
         if (Progress != NULL && p % 100 == 0)
            Progress->Progress(p);
@@ -78,7 +88,12 @@ bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
 void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
                                pkgCache::VerIterator const &Ver)
 {
+   pkgRecords Recs(Cache);
+   pkgRecords::Parser &rec = Recs.Lookup(Ver.FileList());
+   string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg();
+
    fprintf(output, "Package: %s\n", Pkg.Name());
+   fprintf(output, "Source: %s\n", srcpkg.c_str());
    fprintf(output, "Architecture: %s\n", Ver.Arch());
    fprintf(output, "Version: %s\n", Ver.VerStr());
    if (Pkg.CurrentVer() == Ver)
@@ -98,10 +113,22 @@ void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgI
    else if ((Ver->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
       fprintf(output, "Multi-Arch: same\n");
    signed short Pin = std::numeric_limits<signed short>::min();
-   for (pkgCache::VerFileIterator File = Ver.FileList(); File.end() == false; ++File) {
-      signed short const p = Cache.GetPolicy().GetPriority(File.File());
+   std::set<string> Releases;
+   for (pkgCache::VerFileIterator I = Ver.FileList(); I.end() == false; ++I) {
+      pkgCache::PkgFileIterator File = I.File();
+      signed short const p = Cache.GetPolicy().GetPriority(File);
       if (Pin < p)
         Pin = p;
+      if ((File->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource) {
+        string Release = File.RelStr();
+        if (!Release.empty())
+           Releases.insert(Release);
+      }
+   }
+   if (!Releases.empty()) {
+       fprintf(output, "APT-Release:\n");
+       for (std::set<string>::iterator R = Releases.begin(); R != Releases.end(); ++R)
+          fprintf(output, " %s\n", R->c_str());
    }
    fprintf(output, "APT-Pin: %d\n", Pin);
    if (Cache.GetCandidateVer(Pkg) == Ver)
@@ -111,8 +138,7 @@ void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgI
 }
                                                                        /*}}}*/
 // EDSP::WriteScenarioDependency                                       /*{{{*/
-void EDSP::WriteScenarioDependency(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
-                               pkgCache::VerIterator const &Ver)
+void EDSP::WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &Ver)
 {
    std::string dependencies[pkgCache::Dep::Enhances + 1];
    bool orGroup = false;
@@ -148,8 +174,7 @@ void EDSP::WriteScenarioDependency(pkgDepCache &Cache, FILE* output, pkgCache::P
 }
                                                                        /*}}}*/
 // EDSP::WriteScenarioLimitedDependency                                        /*{{{*/
-void EDSP::WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output,
-                                         pkgCache::PkgIterator const &Pkg,
+void EDSP::WriteScenarioLimitedDependency(FILE* output,
                                          pkgCache::VerIterator const &Ver,
                                          APT::PackageSet const &pkgset)
 {
@@ -224,7 +249,16 @@ bool EDSP::WriteRequest(pkgDepCache &Cache, FILE* output, bool const Upgrade,
         continue;
       req->append(" ").append(Pkg.FullName());
    }
-   fprintf(output, "Request: EDSP 0.4\n");
+   fprintf(output, "Request: EDSP 0.5\n");
+
+   const char *arch = _config->Find("APT::Architecture").c_str();
+   std::vector<string> archs = APT::Configuration::getArchitectures();
+   fprintf(output, "Architecture: %s\n", arch);
+   fprintf(output, "Architectures:");
+   for (std::vector<string>::const_iterator a = archs.begin(); a != archs.end(); ++a)
+       fprintf(output, " %s", a->c_str());
+   fprintf(output, "\n");
+
    if (del.empty() == false)
       fprintf(output, "Remove: %s\n", del.c_str()+1);
    if (inst.empty() == false)
@@ -474,10 +508,7 @@ bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output)
       {
         fprintf(output, "Autoremove: %d\n", Pkg.CurrentVer()->ID);
         if (Debug == true)
-         {
            fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Pkg.CurrentVer().VerStr());
-           fprintf(stderr, "Autoremove: %s\nVersion: %s\n", Pkg.FullName().c_str(), Pkg.CurrentVer().VerStr());
-         }
       }
       else
         continue;