]> git.saurik.com Git - apt.git/commitdiff
add a first round of stuff needed for talking between APT and solvers
authorDavid Kalnischkies <kalnischkies@gmail.com>
Wed, 30 Mar 2011 15:23:43 +0000 (17:23 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Wed, 30 Mar 2011 15:23:43 +0000 (17:23 +0200)
based on a very early draft for EDSP by Stefano

APT can now write a scenario as well as load most stuff from it.

18 files changed:
apt-pkg/algorithms.cc
apt-pkg/algorithms.h
apt-pkg/deb/debindexfile.h
apt-pkg/deb/deblistparser.h
apt-pkg/depcache.cc
apt-pkg/depcache.h
apt-pkg/edsp/edspindexfile.cc [new file with mode: 0644]
apt-pkg/edsp/edspindexfile.h [new file with mode: 0644]
apt-pkg/edsp/edsplistparser.cc [new file with mode: 0644]
apt-pkg/edsp/edsplistparser.h [new file with mode: 0644]
apt-pkg/edsp/edspsystem.cc [new file with mode: 0644]
apt-pkg/edsp/edspsystem.h [new file with mode: 0644]
apt-pkg/edsp/edspwriter.cc [new file with mode: 0644]
apt-pkg/edsp/edspwriter.h [new file with mode: 0644]
apt-pkg/makefile
apt-pkg/pkgcachegen.cc
apt-pkg/policy.cc
apt-pkg/policy.h

index 0b4366e5ebe758a8e0cee36e3fa0f5b2d38c02aa..2ca3404a08c3b5469978f58485aa83beb8dc1d6d 100644 (file)
 #include <apt-pkg/version.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/acquire-item.h>
-    
+#include <apt-pkg/edspwriter.h>
+
 #include <apti18n.h>
 #include <sys/types.h>
 #include <cstdlib>
 #include <algorithm>
 #include <iostream>
+
+#include <stdio.h>
                                                                        /*}}}*/
 using namespace std;
 
@@ -731,7 +734,25 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
    return true;
 }
                                                                        /*}}}*/
-// ProblemResolver::Resolve - Run the resolution pass                  /*{{{*/
+// ProblemResolver::Resolve - calls a resolver to fix the situation    /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgProblemResolver::Resolve(bool BrokenFix)
+{
+   std::string const solver = _config->Find("APT::Solver::Name", "internal");
+   if (solver != "internal")
+   {
+      FILE* output = fopen("/tmp/universe.log", "w");
+      edspWriter::WriteUniverse(Cache, output);
+      fclose(output);
+      output = fopen("/tmp/request.log", "w");
+      edspWriter::WriteRequest(Cache, output);
+      fclose(output);
+   }
+   return ResolveInternal(BrokenFix);
+}
+                                                                       /*}}}*/
+// ProblemResolver::ResolveInternal - Run the resolution pass          /*{{{*/
 // ---------------------------------------------------------------------
 /* This routines works by calculating a score for each package. The score
    is derived by considering the package's priority and all reverse 
@@ -745,12 +766,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
  
    The BrokenFix flag enables a mode where the algorithm tries to 
    upgrade packages to advoid problems. */
-bool pkgProblemResolver::Resolve(bool BrokenFix)
+bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
 {
    pkgDepCache::ActionGroup group(Cache);
 
-   unsigned long Size = Cache.Head().PackageCount;
-
    // Record which packages are marked for install
    bool Again = false;
    do
@@ -780,7 +799,9 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
       clog << "Starting" << endl;
    
    MakeScores();
-   
+
+   unsigned long const Size = Cache.Head().PackageCount;
+
    /* We have to order the packages so that the broken fixing pass 
       operates from highest score to lowest. This prevents problems when
       high score packages cause the removal of lower score packages that
index ebe31cc103024ab08124cb57bf5d8b400cbf7329..0778ec72260b0b7047ffd3752a1700297a6a817e 100644 (file)
@@ -105,6 +105,8 @@ class pkgProblemResolver                                            /*{{{*/
 
    void MakeScores();
    bool DoUpgrade(pkgCache::PkgIterator Pkg);
+
+   bool ResolveInternal(bool const BrokenFix = false);
    
    public:
    
index b5085992dacd83492b0342fc1027a9a145058a96..6697c5f26dafb31f7e74aa5f408efa77049cae5d 100644 (file)
@@ -22,8 +22,9 @@
 
 class debStatusIndex : public pkgIndexFile
 {
+   protected:
    string File;
-   
+
    public:
 
    virtual const Type *GetType() const;
@@ -36,6 +37,7 @@ class debStatusIndex : public pkgIndexFile
    virtual bool HasPackages() const {return true;};
    virtual unsigned long Size() const;
    virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
+   bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog, unsigned long const Flag) const;
    virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
 
    debStatusIndex(string File);
index d62ce641cc59888427c3683abf8907eba4e8f59e..8b8aff788dd0693b17e78198e188a6c369128357 100644 (file)
@@ -25,9 +25,9 @@ class debListParser : public pkgCacheGenerator::ListParser
       const char *Str;
       unsigned char Val;
    };
-   
-   private:
-   
+
+   protected:
+
    pkgTagFile Tags;
    pkgTagSection Section;
    unsigned long iOffset;
@@ -36,7 +36,7 @@ class debListParser : public pkgCacheGenerator::ListParser
    bool MultiArchEnabled;
 
    unsigned long UniqFindTagWrite(const char *Tag);
-   bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
+   virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
    bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag,
                     unsigned int Type);
    bool ParseProvides(pkgCache::VerIterator &Ver);
index 07803d7bf7a69bb9e012b5b5698e8715ded19f0f..2790080a1567eed1c95a059d8cb1d126f5dd23e8 100644 (file)
@@ -1578,6 +1578,12 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep)
    return false;
 }
                                                                        /*}}}*/
+// Policy::GetPriority - Get the priority of the package pin           /*{{{*/
+signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator const &Pkg)
+{ return 0; };
+signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator const &File)
+{ return 0; };
+                                                                       /*}}}*/
 pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc()              /*{{{*/
 {
   DefaultRootSetFunc *f = new DefaultRootSetFunc;
index 750da3d6f1cb9db717a57882881626fc495d6a01..b15cd527d6ef7a934ff15f84a4d3ad5b683d811a 100644 (file)
@@ -258,7 +258,9 @@ class pkgDepCache : protected pkgCache::Namespace
       
       virtual VerIterator GetCandidateVer(PkgIterator const &Pkg);
       virtual bool IsImportantDep(DepIterator const &Dep);
-      
+      virtual signed short GetPriority(PkgIterator const &Pkg);
+      virtual signed short GetPriority(PkgFileIterator const &File);
+
       virtual ~Policy() {};
    };
 
diff --git a/apt-pkg/edsp/edspindexfile.cc b/apt-pkg/edsp/edspindexfile.cc
new file mode 100644 (file)
index 0000000..5a9d5aa
--- /dev/null
@@ -0,0 +1,74 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+   The universe file is designed to work as an intermediate file between
+   APT and the resolver. Its on propose very similar to a dpkg status file
+   ##################################################################### */
+                                                                       /*}}}*/
+// Include Files                                                       /*{{{*/
+#include <apt-pkg/edspindexfile.h>
+#include <apt-pkg/edsplistparser.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/acquire-item.h>
+
+#include <sys/stat.h>
+                                                                       /*}}}*/
+
+// edspIndex::edspIndex - Constructor                                  /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+edspIndex::edspIndex(string File) : debStatusIndex(File)
+{
+}
+                                                                       /*}}}*/
+// StatusIndex::Merge - Load the index file into a cache               /*{{{*/
+bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
+{
+   FileFd Pkg(File,FileFd::ReadOnlyGzip);
+   if (_error->PendingError() == true)
+      return false;
+   edspListParser Parser(&Pkg);
+   if (_error->PendingError() == true)
+      return false;
+
+   if (Prog != NULL)
+      Prog->SubProgress(0,File);
+   if (Gen.SelectFile(File,string(),*this) == false)
+      return _error->Error("Problem with SelectFile %s",File.c_str());
+
+   // Store the IMS information
+   pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
+   struct stat St;
+   if (fstat(Pkg.Fd(),&St) != 0)
+      return _error->Errno("fstat","Failed to stat");
+   CFile->Size = St.st_size;
+   CFile->mtime = St.st_mtime;
+   CFile->Archive = Gen.WriteUniqString("universe");
+
+   if (Gen.MergeList(Parser) == false)
+      return _error->Error("Problem with MergeList %s",File.c_str());
+   return true;
+}
+                                                                       /*}}}*/
+// Index File types for APT                                            /*{{{*/
+class edspIFType: public pkgIndexFile::Type
+{
+   public:
+   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
+   {
+      // we don't have a record parser for this type as the file is not presistent
+      return NULL;
+   };
+   edspIFType() {Label = "APT universe file";};
+};
+static edspIFType _apt_Universe;
+
+const pkgIndexFile::Type *edspIndex::GetType() const
+{
+   return &_apt_Universe;
+}
+                                                                       /*}}}*/
diff --git a/apt-pkg/edsp/edspindexfile.h b/apt-pkg/edsp/edspindexfile.h
new file mode 100644 (file)
index 0000000..4ef7787
--- /dev/null
@@ -0,0 +1,25 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+   The universe file is designed to work as an intermediate file between
+   APT and the resolver. Its on propose very similar to a dpkg status file
+   ##################################################################### */
+                                                                       /*}}}*/
+#ifndef PKGLIB_EDSPINDEXFILE_H
+#define PKGLIB_EDSPINDEXFILE_H
+
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/debindexfile.h>
+
+class edspIndex : public debStatusIndex
+{
+   public:
+
+   virtual const Type *GetType() const;
+
+   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
+
+   edspIndex(string File);
+};
+
+#endif
diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc
new file mode 100644 (file)
index 0000000..3e57ea8
--- /dev/null
@@ -0,0 +1,109 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+
+   Package Cache Generator - Generator for the cache structure.
+
+   This builds the cache structure from the abstract package list parser.
+
+   ##################################################################### */
+                                                                       /*}}}*/
+// Include Files                                                       /*{{{*/
+#include <apt-pkg/edsplistparser.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/md5.h>
+#include <apt-pkg/macros.h>
+                                                                       /*}}}*/
+
+// ListParser::edspListParser - Constructor                            /*{{{*/
+edspListParser::edspListParser(FileFd *File, string const &Arch) : debListParser(File, Arch)
+{}
+                                                                       /*}}}*/
+// ListParser::NewVersion - Fill in the version structure              /*{{{*/
+bool edspListParser::NewVersion(pkgCache::VerIterator &Ver)
+{
+   Ver->ID = Section.FindI("APT-ID", Ver->ID);
+   return debListParser::NewVersion(Ver);
+}
+                                                                       /*}}}*/
+// ListParser::Description - Return the description string             /*{{{*/
+// ---------------------------------------------------------------------
+/* Sorry, no description for the resolversā€¦ */
+string edspListParser::Description()
+{
+   return "";
+}
+string edspListParser::DescriptionLanguage()
+{
+   return "";
+}
+MD5SumValue edspListParser::Description_md5()
+{
+   return MD5SumValue("");
+}
+                                                                       /*}}}*/
+// ListParser::VersionHash - Compute a unique hash for this version    /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+unsigned short edspListParser::VersionHash()
+{
+   if (Section.Exists("APT-Hash") == true)
+      return Section.FindI("APT-Hash");
+   else if (Section.Exists("APT-ID") == true)
+      return Section.FindI("APT-ID");
+   return 0;
+}
+                                                                       /*}}}*/
+// ListParser::ParseStatus - Parse the status field                    /*{{{*/
+// ---------------------------------------------------------------------
+/* The Status: line here is not a normal dpkg one but just one which tells
+   use if the package is installed or not, where missing means not. */
+bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
+                               pkgCache::VerIterator &Ver)
+{
+   const char *Start;
+   const char *Stop;
+   if (Section.Find("Status",Start,Stop) == false)
+      return true;
+
+   // UsePackage() is responsible for setting the flag in the default case
+   bool const static essential = _config->Find("pkgCacheGen::Essential", "") == "installed";
+   if (essential == true &&
+       Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
+      return false;
+
+   // Isolate the first word
+   const char *I = Start;
+   for(; I < Stop && *I != ' '; I++);
+
+   // Process the flag field
+   WordList StatusList[] = {{"installed",pkgCache::State::Installed},
+                            {}};
+   if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
+      return _error->Error("Malformed Status line");
+
+   /* A Status line marks the package as indicating the current
+      version as well. Only if it is actually installed.. Otherwise
+      the interesting dpkg handling of the status file creates bogus 
+      entries. */
+   if (!(Pkg->CurrentState == pkgCache::State::NotInstalled ||
+        Pkg->CurrentState == pkgCache::State::ConfigFiles))
+   {
+      if (Ver.end() == true)
+        _error->Warning("Encountered status field in a non-version description");
+      else
+        Pkg->CurrentVer = Ver.Index();
+   }
+   
+   return true;
+}
+                                                                       /*}}}*/
+// ListParser::LoadReleaseInfo - Load the release information          /*{{{*/
+bool edspListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
+                                   FileFd &File, string component)
+{
+   return true;
+}
+                                                                       /*}}}*/
diff --git a/apt-pkg/edsp/edsplistparser.h b/apt-pkg/edsp/edsplistparser.h
new file mode 100644 (file)
index 0000000..ec9f099
--- /dev/null
@@ -0,0 +1,38 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+
+   EDSP Package List Parser - This implements the abstract parser
+   interface for the APT specific intermediate format which is passed
+   to external resolvers
+
+   ##################################################################### */
+                                                                       /*}}}*/
+#ifndef PKGLIB_EDSPLISTPARSER_H
+#define PKGLIB_EDSPLISTPARSER_H
+
+#include <apt-pkg/deblistparser.h>
+#include <apt-pkg/pkgcachegen.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/tagfile.h>
+
+class edspListParser : public debListParser
+{
+   public:
+   virtual bool NewVersion(pkgCache::VerIterator &Ver);
+   virtual string Description();
+   virtual string DescriptionLanguage();
+   virtual MD5SumValue Description_md5();
+   virtual unsigned short VersionHash();
+
+   bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File,
+                       string section);
+
+   edspListParser(FileFd *File, string const &Arch = "");
+
+   protected:
+   virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
+
+};
+
+#endif
diff --git a/apt-pkg/edsp/edspsystem.cc b/apt-pkg/edsp/edspsystem.cc
new file mode 100644 (file)
index 0000000..579ffc6
--- /dev/null
@@ -0,0 +1,117 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+
+   This system provides the abstraction to use the universe file as the
+   only source of package information to be able to feed the created file
+   back to APT for its own consumption (eat your own dogfood).
+
+   ##################################################################### */
+                                                                       /*}}}*/
+// Include Files                                                       /*{{{*/
+#include <apt-pkg/edspsystem.h>
+#include <apt-pkg/debversion.h>
+#include <apt-pkg/edspindexfile.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apti18n.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+                                                                       /*}}}*/
+
+edspSystem edspSys;
+
+// System::debSystem - Constructor                                     /*{{{*/
+edspSystem::edspSystem()
+{
+   StatusFile = 0;
+
+   Label = "Debian APT solver interface";
+   VS = &debVS;
+}
+                                                                       /*}}}*/
+// System::~debSystem - Destructor                                     /*{{{*/
+edspSystem::~edspSystem()
+{
+   delete StatusFile;
+}
+                                                                       /*}}}*/
+// System::Lock - Get the lock                                         /*{{{*/
+bool edspSystem::Lock()
+{
+   return true;
+}
+                                                                       /*}}}*/
+// System::UnLock - Drop a lock                                                /*{{{*/
+bool edspSystem::UnLock(bool NoErrors)
+{
+   return true;
+}
+                                                                       /*}}}*/
+// System::CreatePM - Create the underlying package manager            /*{{{*/
+// ---------------------------------------------------------------------
+/* we can't use edsp input as input for real installations - just a
+   simulation can work, but everything else will fail bigtime */
+pkgPackageManager *edspSystem::CreatePM(pkgDepCache *Cache) const
+{
+   return NULL;
+}
+                                                                       /*}}}*/
+// System::Initialize - Setup the configuration space..                        /*{{{*/
+bool edspSystem::Initialize(Configuration &Cnf)
+{
+   Cnf.Set("Dir::State::extended_states", "/dev/null");
+   Cnf.Set("Dir::State::status","/dev/null");
+   Cnf.Set("Dir::State::lists","/dev/null");
+
+   Cnf.Set("Debug::NoLocking", "true");
+   Cnf.Set("APT::Get::Simulate", "true");
+
+   if (StatusFile) {
+     delete StatusFile;
+     StatusFile = 0;
+   }
+   return true;
+}
+                                                                       /*}}}*/
+// System::ArchiveSupported - Is a file format supported               /*{{{*/
+bool edspSystem::ArchiveSupported(const char *Type)
+{
+   return false;
+}
+                                                                       /*}}}*/
+// System::Score - Determine if we should use the edsp system          /*{{{*/
+signed edspSystem::Score(Configuration const &Cnf)
+{
+   if (FileExists(Cnf.FindFile("Dir::State::universe","")) == true)
+       return 1000;
+   return -1000;
+}
+                                                                       /*}}}*/
+// System::AddStatusFiles - Register the status files                  /*{{{*/
+bool edspSystem::AddStatusFiles(vector<pkgIndexFile *> &List)
+{
+   if (StatusFile == 0)
+      StatusFile = new edspIndex(_config->FindFile("Dir::State::universe"));
+   List.push_back(StatusFile);
+   return true;
+}
+                                                                       /*}}}*/
+// System::FindIndex - Get an index file for status files              /*{{{*/
+bool edspSystem::FindIndex(pkgCache::PkgFileIterator File,
+                         pkgIndexFile *&Found) const
+{
+   if (StatusFile == 0)
+      return false;
+   if (StatusFile->FindInCache(*File.Cache()) == File)
+   {
+      Found = StatusFile;
+      return true;
+   }
+
+   return false;
+}
+                                                                       /*}}}*/
diff --git a/apt-pkg/edsp/edspsystem.h b/apt-pkg/edsp/edspsystem.h
new file mode 100644 (file)
index 0000000..bc5be61
--- /dev/null
@@ -0,0 +1,38 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+// $Id: debsystem.h,v 1.4 2003/01/11 07:16:33 jgg Exp $
+/* ######################################################################
+
+   System - Debian version of the  System Class
+
+   ##################################################################### */
+                                                                       /*}}}*/
+#ifndef PKGLIB_EDSPSYSTEM_H
+#define PKGLIB_EDSPSYSTEM_H
+
+#include <apt-pkg/pkgsystem.h>
+
+class edspIndex;
+class edspSystem : public pkgSystem
+{
+   edspIndex *StatusFile;
+
+   public:
+
+   virtual bool Lock();
+   virtual bool UnLock(bool NoErrors = false);
+   virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const;
+   virtual bool Initialize(Configuration &Cnf);
+   virtual bool ArchiveSupported(const char *Type);
+   virtual signed Score(Configuration const &Cnf);
+   virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List);
+   virtual bool FindIndex(pkgCache::PkgFileIterator File,
+                         pkgIndexFile *&Found) const;
+
+   edspSystem();
+   ~edspSystem();
+};
+
+extern edspSystem edspSys;
+
+#endif
diff --git a/apt-pkg/edsp/edspwriter.cc b/apt-pkg/edsp/edspwriter.cc
new file mode 100644 (file)
index 0000000..38d0d82
--- /dev/null
@@ -0,0 +1,130 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+   Set of methods to help writing and reading everything needed for EDSP
+   ##################################################################### */
+                                                                       /*}}}*/
+// Include Files                                                       /*{{{*/
+#include <apt-pkg/edspwriter.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/policy.h>
+
+#include <apti18n.h>
+#include <limits>
+
+#include <stdio.h>
+                                                                       /*}}}*/
+
+// edspWriter::WriteUniverse - to the given file descriptor            /*{{{*/
+bool edspWriter::WriteUniverse(pkgDepCache &Cache, FILE* output)
+{
+   // we could use pkgCache::DepType and ::Priority, but these would be lokalized stringsā€¦
+   const char * const PrioMap[] = {0, "important", "required", "standard",
+                                  "optional", "extra"};
+   const char * const DepMap[] = {"", "Depends", "PreDepends", "Suggests",
+                                 "Recommends" , "Conflicts", "Replaces",
+                                 "Obsoletes", "Breaks", "Enhances"};
+
+   for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
+   {
+      for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
+      {
+        fprintf(output, "Package: %s\n", Pkg.Name());
+        fprintf(output, "Architecture: %s\n", Ver.Arch());
+        fprintf(output, "Version: %s\n", Ver.VerStr());
+        if (Pkg.CurrentVer() == Ver)
+           fprintf(output, "Installed: yes\n");
+        if (Pkg->SelectedState == pkgCache::State::Hold)
+           fprintf(output, "Hold: yes\n");
+        fprintf(output, "APT-ID: %u\n", Ver->ID);
+        fprintf(output, "Priority: %s\n", PrioMap[Ver->Priority]);
+        if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
+           fprintf(output, "Essential: yes\n");
+        fprintf(output, "Section: %s\n", Ver.Section());
+        if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed)
+           fprintf(output, "Multi-Arch: allowed\n");
+        else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign)
+           fprintf(output, "Multi-Arch: foreign\n");
+        else if (Ver->MultiArch == 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());
+           if (Pin < p)
+              Pin = p;
+        }
+        fprintf(output, "APT-Pin: %d\n", Pin);
+        if (Cache.GetCandidateVer(Pkg) == Ver)
+           fprintf(output, "APT-Candidate: yes\n");
+        if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
+           fprintf(output, "APT-Automatic: yes\n");
+        std::string dependencies[pkgCache::Dep::Enhances + 1];
+        bool orGroup = false;
+        for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
+        {
+           // Ignore implicit dependencies for multiarch here
+           if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0)
+              continue;
+           if (orGroup == false)
+              dependencies[Dep->Type].append(", ");
+           dependencies[Dep->Type].append(Dep.TargetPkg().Name());
+           if (Dep->Version != 0)
+              dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")");
+           if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
+           {
+              dependencies[Dep->Type].append(" | ");
+              orGroup = true;
+           }
+           else
+              orGroup = false;
+        }
+        for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
+           if (dependencies[i].empty() == false)
+              fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str()+2);
+        string provides;
+        for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv)
+        {
+           // Ignore implicit provides for multiarch here
+           if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0)
+              continue;
+           provides.append(", ").append(Prv.Name());
+        }
+        if (provides.empty() == false)
+           fprintf(output, "Provides: %s\n", provides.c_str()+2);
+
+
+        fprintf(output, "\n");
+      }
+   }
+   return true;
+}
+                                                                       /*}}}*/
+// edspWriter::WriteRequest - to the given file descriptor             /*{{{*/
+bool edspWriter::WriteRequest(pkgDepCache &Cache, FILE* output)
+{
+   string del, inst, upgrade;
+   for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
+   {
+      string* req;
+      if (Cache[Pkg].Delete() == true)
+        req = &del;
+      else if (Cache[Pkg].NewInstall() == true)
+        req = &inst;
+      else if (Cache[Pkg].Upgrade() == true)
+        req = &upgrade;
+      else
+        continue;
+      req->append(", ").append(Pkg.FullName());
+   }
+   if (del.empty() == false)
+      fprintf(output, "Remove: %s\n", del.c_str()+2);
+   if (inst.empty() == false)
+      fprintf(output, "Install: %s\n", inst.c_str()+2);
+   if (upgrade.empty() == false)
+      fprintf(output, "Upgrade: %s\n", upgrade.c_str()+2);
+
+   return true;
+}
+                                                                       /*}}}*/
diff --git a/apt-pkg/edsp/edspwriter.h b/apt-pkg/edsp/edspwriter.h
new file mode 100644 (file)
index 0000000..52923ff
--- /dev/null
@@ -0,0 +1,19 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+   Set of methods to help writing and reading everything needed for EDSP
+   ##################################################################### */
+                                                                       /*}}}*/
+#ifndef PKGLIB_EDSPWRITER_H
+#define PKGLIB_EDSPWRITER_H
+
+#include <apt-pkg/depcache.h>
+
+class edspWriter                                                               /*{{{*/
+{
+public:
+       bool static WriteUniverse(pkgDepCache &Cache, FILE* output);
+       bool static WriteRequest(pkgDepCache &Cache, FILE* output);
+};
+                                                                       /*}}}*/
+#endif
index 4e5ec107f09b73af7f7c74c9184ef069f972a445..a7880e81cd2defea21094e137ce9f305fd981d6b 100644 (file)
@@ -3,7 +3,7 @@ BASE=..
 SUBDIR=apt-pkg
 
 # Header location
-SUBDIRS = deb contrib
+SUBDIRS = deb edsp contrib
 HEADER_TARGETDIRS = apt-pkg
 
 # Bring in the default rules
@@ -53,6 +53,11 @@ SOURCE+= deb/deblistparser.cc deb/debrecords.cc deb/dpkgpm.cc \
 HEADERS+= debversion.h debsrcrecords.h dpkgpm.h debrecords.h \
          deblistparser.h debsystem.h debindexfile.h debmetaindex.h
 
+# Source code for the APT resolver interface specific components
+SOURCE+= edsp/edsplistparser.cc edsp/edspindexfile.cc edsp/edspsystem.cc \
+        edsp/edspwriter.cc
+HEADERS+= edsplistparser.h edspindexfile.h edspsystem.h edspwriter.h
+
 HEADERS := $(addprefix apt-pkg/,$(HEADERS))
 
 include $(LIBRARY_H)
index b0ee04554995636c16d5d609576b08c28299e872..46dd220073fc6015f50b3420f3f511fd39a7f5ca 100644 (file)
@@ -641,7 +641,7 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
               bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same);
               for (vector<string>::const_iterator A = archs.begin(); A != archs.end(); ++A)
               {
-                 if (*A == Arch)
+                 if (Arch == 0 || *A == Arch)
                     continue;
                  /* We allow only one installed arch at the time
                     per group, therefore each group member conflicts
index 94c7fd4afca7834ec4d43358524caf56eddaa538..4e4077feb3a5dafcda09003ccb00ca0f3e790f66 100644 (file)
@@ -269,6 +269,10 @@ signed short pkgPolicy::GetPriority(pkgCache::PkgIterator const &Pkg)
    }
    
    return 0;
+}
+signed short pkgPolicy::GetPriority(pkgCache::PkgFileIterator const &File)
+{
+   return PFPriority[File->ID];
 }
                                                                        /*}}}*/
 // PreferenceSection class - Overriding the default TrimRecord method  /*{{{*/
index f8b2678de434997d9d5825fda8c1588376b33a33..e7f36d6187ee2e4537caa2a1fb57c689de14cfae 100644 (file)
@@ -69,14 +69,13 @@ class pkgPolicy : public pkgDepCache::Policy
    // Things for manipulating pins
    void CreatePin(pkgVersionMatch::MatchType Type,string Pkg,
                  string Data,signed short Priority);
-   inline signed short GetPriority(pkgCache::PkgFileIterator const &File) 
-       {return PFPriority[File->ID];};
-   signed short GetPriority(pkgCache::PkgIterator const &Pkg);
    pkgCache::VerIterator GetMatch(pkgCache::PkgIterator const &Pkg);
 
    // Things for the cache interface.
    virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg);
-   virtual bool IsImportantDep(pkgCache::DepIterator const &Dep) {return pkgDepCache::Policy::IsImportantDep(Dep);};
+   virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg);
+   virtual signed short GetPriority(pkgCache::PkgFileIterator const &File);
+
    bool InitDefaults();
    
    pkgPolicy(pkgCache *Owner);