瀏覽代碼

Merge remote-tracking branch 'mvo/feature/build-dep-dsc2' into debian/experimental

Conflicts:
	apt-pkg/deb/debindexfile.cc
	apt-pkg/deb/debindexfile.h
	apt-pkg/deb/debsrcrecords.cc
Michael Vogt 12 年之前
父節點
當前提交
070536e61c

+ 65 - 0
apt-pkg/deb/debindexfile.cc

@@ -759,6 +759,41 @@ unsigned long debDebPkgFileIndex::Size() const
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
+// debDscFileIndex stuff
+debDscFileIndex::debDscFileIndex(std::string &DscFile) 
+   : pkgIndexFile(true), DscFile(DscFile)
+{
+}
+
+bool debDscFileIndex::Exists() const
+{
+   return FileExists(DscFile);
+}
+
+unsigned long debDscFileIndex::Size() const
+{
+   struct stat buf;
+   if(stat(DscFile.c_str(), &buf) == 0)
+      return buf.st_size;
+   return 0;
+}
+
+// DscFileIndex::CreateSrcParser - Get a parser for the .dsc file	/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const
+{
+   if (!FileExists(DscFile))
+      return NULL;
+
+   return new debDscRecordParser(DscFile,this);
+}
+									/*}}}*/
+
+
+
+
+// ---------------------------------------------------------------------
 // Index File types for Debian						/*{{{*/
 // Index File types for Debian						/*{{{*/
 class debIFTypeSrc : public pkgIndexFile::Type
 class debIFTypeSrc : public pkgIndexFile::Type
 {
 {
@@ -800,11 +835,33 @@ class debIFTypeDebPkgFile : public pkgIndexFile::Type
    };
    };
    debIFTypeDebPkgFile() {Label = "deb Package file";};
    debIFTypeDebPkgFile() {Label = "deb Package file";};
 };
 };
+class debIFTypeDscFile : public pkgIndexFile::Type
+{
+   public:
+   virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const
+   {
+      return new debDscRecordParser(DscFile, NULL);
+   };
+   debIFTypeDscFile() {Label = "dsc File Source Index";};
+};
+class debIFTypeDebianSourceDir : public pkgIndexFile::Type
+{
+   public:
+   virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const
+   {
+      return new debDscRecordParser(SourceDir + string("/debian/control"), NULL);
+   };
+   debIFTypeDebianSourceDir() {Label = "debian/control File Source Index";};
+};
+
 static debIFTypeSrc _apt_Src;
 static debIFTypeSrc _apt_Src;
 static debIFTypePkg _apt_Pkg;
 static debIFTypePkg _apt_Pkg;
 static debIFTypeTrans _apt_Trans;
 static debIFTypeTrans _apt_Trans;
 static debIFTypeStatus _apt_Status;
 static debIFTypeStatus _apt_Status;
 static debIFTypeDebPkgFile _apt_DebPkgFile;
 static debIFTypeDebPkgFile _apt_DebPkgFile;
+// file based pseudo indexes
+static debIFTypeDscFile _apt_DscFile;
+static debIFTypeDebianSourceDir _apt_DebianSourceDir;
 
 
 const pkgIndexFile::Type *debSourcesIndex::GetType() const
 const pkgIndexFile::Type *debSourcesIndex::GetType() const
 {
 {
@@ -825,5 +882,13 @@ const pkgIndexFile::Type *debStatusIndex::GetType() const
 const pkgIndexFile::Type *debDebPkgFileIndex::GetType() const
 const pkgIndexFile::Type *debDebPkgFileIndex::GetType() const
 {
 {
    return &_apt_DebPkgFile;
    return &_apt_DebPkgFile;
+}
+const pkgIndexFile::Type *debDscFileIndex::GetType() const
+{
+   return &_apt_DscFile;
+}
+const pkgIndexFile::Type *debDebianSourceDirIndex::GetType() const
+{
+   return &_apt_DebianSourceDir;
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 23 - 1
apt-pkg/deb/debindexfile.h

@@ -192,7 +192,29 @@ class debDebPkgFileIndex : public pkgIndexFile
 
 
    debDebPkgFileIndex(std::string DebFile);
    debDebPkgFileIndex(std::string DebFile);
    virtual ~debDebPkgFileIndex() {};
    virtual ~debDebPkgFileIndex() {};
-   
+};   
+
+class debDscFileIndex : public pkgIndexFile
+{
+ private:
+   std::string DscFile;
+ public:
+   virtual const Type *GetType() const APT_CONST;
+   virtual pkgSrcRecords::Parser *CreateSrcParser() const;
+   virtual bool Exists() const;
+   virtual bool HasPackages() const {return false;};
+   virtual unsigned long Size() const;
+   virtual std::string Describe(bool /*Short*/) const {
+      return DscFile;
+   };
+
+   debDscFileIndex(std::string &DscFile);
+   virtual ~debDscFileIndex() {};
+};
+
+class debDebianSourceDirIndex : public debDscFileIndex
+{
+   virtual const Type *GetType() const APT_CONST;
 };
 };
 
 
 #endif
 #endif

+ 2 - 2
apt-pkg/deb/debmetaindex.cc

@@ -521,8 +521,8 @@ class debSLTypeDebFile : public pkgSourceList::Type
    public:
    public:
 
 
    bool CreateItem(vector<metaIndex *> &List, string const &URI,
    bool CreateItem(vector<metaIndex *> &List, string const &URI,
-		   string const &Dist, string const &Section,
-		   std::map<string, string> const &Options) const
+		   string const &/*Dist*/, string const &/*Section*/,
+		   std::map<string, string> const &/*Options*/) const
    {
    {
       metaIndex *mi = new debDebFileMetaIndex(URI);
       metaIndex *mi = new debDebFileMetaIndex(URI);
       List.push_back(mi);
       List.push_back(mi);

+ 19 - 0
apt-pkg/deb/debsrcrecords.cc

@@ -19,6 +19,7 @@
 #include <apt-pkg/srcrecords.h>
 #include <apt-pkg/srcrecords.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/hashes.h>
+#include <apt-pkg/gpgv.h>
 
 
 #include <ctype.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdlib.h>
@@ -212,3 +213,21 @@ debSrcRecordParser::~debSrcRecordParser()
    delete[] Buffer;
    delete[] Buffer;
 }
 }
 									/*}}}*/
 									/*}}}*/
+
+
+debDscRecordParser::debDscRecordParser(std::string const &DscFile, pkgIndexFile const *Index)
+   : debSrcRecordParser(DscFile, Index)
+{
+   // support clear signed files
+   if (OpenMaybeClearSignedFile(DscFile, Fd) == false)
+   {
+      _error->Error("Failed to open %s", DscFile.c_str());
+      return;
+   }
+
+   // re-init to ensure the updated Fd is used
+   Tags.Init(&Fd);
+   // read the first (and only) record
+   Step();
+
+}

+ 7 - 0
apt-pkg/deb/debsrcrecords.h

@@ -26,6 +26,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
    /** \brief dpointer placeholder (for later in case we need it) */
    /** \brief dpointer placeholder (for later in case we need it) */
    void *d;
    void *d;
 
 
+ protected:
    FileFd Fd;
    FileFd Fd;
    pkgTagFile Tags;
    pkgTagFile Tags;
    pkgTagSection Sect;
    pkgTagSection Sect;
@@ -60,4 +61,10 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
    virtual ~debSrcRecordParser();
    virtual ~debSrcRecordParser();
 };
 };
 
 
+class debDscRecordParser : public debSrcRecordParser
+{
+ public:
+   debDscRecordParser(std::string const &DscFile, pkgIndexFile const *Index);
+};
+
 #endif
 #endif

+ 1 - 0
apt-pkg/indexfile.h

@@ -59,6 +59,7 @@ class pkgIndexFile
       const char *Label;
       const char *Label;
 
 
       virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator /*File*/) const {return 0;};
       virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator /*File*/) const {return 0;};
+      virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string /*File*/) const {return 0;};
       Type();
       Type();
       virtual ~Type() {};
       virtual ~Type() {};
    };
    };

+ 4 - 2
apt-pkg/pkgsystem.h

@@ -85,10 +85,12 @@ class pkgSystem
    virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List) = 0;   
    virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List) = 0;   
    virtual bool FindIndex(pkgCache::PkgFileIterator File,
    virtual bool FindIndex(pkgCache::PkgFileIterator File,
 			  pkgIndexFile *&Found) const = 0;
 			  pkgIndexFile *&Found) const = 0;
-   
+
    /* Evauluate how 'right' we are for this system based on the filesystem
    /* Evauluate how 'right' we are for this system based on the filesystem
       etc.. */
       etc.. */
-   virtual signed Score(Configuration const &/*Cnf*/) {return 0;};
+   virtual signed Score(Configuration const &/*Cnf*/) {
+      return 0;
+   };
    
    
    pkgSystem();
    pkgSystem();
    virtual ~pkgSystem() {};
    virtual ~pkgSystem() {};

+ 1 - 1
apt-pkg/sourcelist.h

@@ -94,7 +94,7 @@ class pkgSourceList : public pkgSource
    
    
    typedef std::vector<metaIndex *>::const_iterator const_iterator;
    typedef std::vector<metaIndex *>::const_iterator const_iterator;
    
    
-   protected:
+   public:
 
 
    std::vector<metaIndex *> SrcList;
    std::vector<metaIndex *> SrcList;
 
 

+ 11 - 0
apt-pkg/tagfile.cc

@@ -51,12 +51,23 @@ public:
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
 pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long long Size)
 pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long long Size)
+   : d(NULL)
+{
+   Init(pFd, Size);
+}
+
+void pkgTagFile::Init(FileFd *pFd,unsigned long long Size)
 {
 {
    /* The size is increased by 4 because if we start with the Size of the
    /* The size is increased by 4 because if we start with the Size of the
       filename we need to try to read 1 char more to see an EOF faster, 1
       filename we need to try to read 1 char more to see an EOF faster, 1
       char the end-pointer can be on and maybe 2 newlines need to be added
       char the end-pointer can be on and maybe 2 newlines need to be added
       to the end of the file -> 4 extra chars */
       to the end of the file -> 4 extra chars */
    Size += 4;
    Size += 4;
+   if(d != NULL)
+   {
+      free(d->Buffer);
+      delete d;
+   }
    d = new pkgTagFilePrivate(pFd, Size);
    d = new pkgTagFilePrivate(pFd, Size);
 
 
    if (d->Fd.IsOpen() == false)
    if (d->Fd.IsOpen() == false)

+ 2 - 0
apt-pkg/tagfile.h

@@ -105,6 +105,8 @@ class pkgTagFile
    unsigned long Offset();
    unsigned long Offset();
    bool Jump(pkgTagSection &Tag,unsigned long long Offset);
    bool Jump(pkgTagSection &Tag,unsigned long long Offset);
 
 
+   void Init(FileFd *F,unsigned long long Size = 32*1024);
+
    pkgTagFile(FileFd *F,unsigned long long Size = 32*1024);
    pkgTagFile(FileFd *F,unsigned long long Size = 32*1024);
    virtual ~pkgTagFile();
    virtual ~pkgTagFile();
 };
 };

+ 25 - 2
cmdline/apt-get.cc

@@ -1050,7 +1050,30 @@ static bool DoBuildDep(CommandLine &CmdL)
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    {
    {
       string Src;
       string Src;
-      pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
+      pkgSrcRecords::Parser *Last = 0;
+
+      // a unpacked debian source tree
+      if (DirectoryExists(*I))
+      {
+         // FIXME: how can we make this more elegant?
+         std::string TypeName = "debian/control File Source Index";
+         pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
+         if(Type != NULL)
+            Last = Type->CreateSrcPkgParser(*I);
+      }
+      // if its a local file (e.g. .dsc) use this
+      else if (FileExists(*I))
+      {
+         // see if we can get a parser for this pkgIndexFile type
+         string TypeName = flExtension(*I) + " File Source Index";
+         pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
+         if(Type != NULL)
+            Last = Type->CreateSrcPkgParser(*I);
+      } else {
+         // normal case, search the cache for the source file
+         Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
+      }
+
       if (Last == 0)
       if (Last == 0)
 	 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
 	 return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
             
             
@@ -1068,7 +1091,7 @@ static bool DoBuildDep(CommandLine &CmdL)
       }
       }
       else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
       else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
 	    return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
 	    return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
-   
+
       // Also ensure that build-essential packages are present
       // Also ensure that build-essential packages are present
       Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
       Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
       if (Opts) 
       if (Opts) 

+ 126 - 0
test/integration/test-apt-get-build-dep

@@ -0,0 +1,126 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture "i386"
+
+buildsimplenativepackage 'debhelper' 'i386' '7' 'stable'
+buildsimplenativepackage 'build-essential' 'i386' '1' 'stable'
+
+setupaptarchive
+cat > 2vcard_0.5-3.dsc <<EOF
+Format: 1.0
+Source: 2vcard
+Binary: 2vcard
+Architecture: all
+Version: 0.5-3
+Maintainer: Martin Albisetti <argentina@gmail.com>
+Uploaders: Marcela Tiznado <mlt@debian.org>
+Standards-Version: 3.8.0
+Build-Depends: debhelper (>= 5.0.37)
+Checksums-Sha1: 
+ b7f1ce31ec856414a3f0f1090689f91aa7456d56 9398 2vcard_0.5.orig.tar.gz
+ 5f9acd07ebda6ab00fa6b4fe3198c13e94090862 2036 2vcard_0.5-3.diff.gz
+Checksums-Sha256: 
+ efdc22859ac2f8f030d038dc4faa9020082ebae34212498c288968ffd45c9764 9398 2vcard_0.5.orig.tar.gz
+ 82673ff3456af571094066c89bcea87b25c23c87cf1d0050b731e5222563626b 2036 2vcard_0.5-3.diff.gz
+Files: 
+ f73a69c170f772f3f6e75f2d11bbb792 9398 2vcard_0.5.orig.tar.gz
+ 1e806d32233af87437258d86b1561f57 2036 2vcard_0.5-3.diff.gz
+EOF
+
+testequal "Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+  build-essential debhelper
+0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
+Inst build-essential (1 stable [i386])
+Inst debhelper (7 stable [i386])
+Conf build-essential (1 stable [i386])
+Conf debhelper (7 stable [i386])" aptget build-dep -s 2vcard_0.5-3.dsc
+
+cat > 2vcard_0.5-3.dsc <<EOF
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+Format: 1.0
+Source: 2vcard
+Binary: 2vcard
+Architecture: all
+Version: 0.5-3
+Maintainer: Martin Albisetti <argentina@gmail.com>
+Uploaders: Marcela Tiznado <mlt@debian.org>
+Standards-Version: 3.8.0
+Build-Depends: debhelper (>= 5.0.37)
+Checksums-Sha1: 
+ b7f1ce31ec856414a3f0f1090689f91aa7456d56 9398 2vcard_0.5.orig.tar.gz
+ 5f9acd07ebda6ab00fa6b4fe3198c13e94090862 2036 2vcard_0.5-3.diff.gz
+Checksums-Sha256: 
+ efdc22859ac2f8f030d038dc4faa9020082ebae34212498c288968ffd45c9764 9398 2vcard_0.5.orig.tar.gz
+ 82673ff3456af571094066c89bcea87b25c23c87cf1d0050b731e5222563626b 2036 2vcard_0.5-3.diff.gz
+Files: 
+ f73a69c170f772f3f6e75f2d11bbb792 9398 2vcard_0.5.orig.tar.gz
+ 1e806d32233af87437258d86b1561f57 2036 2vcard_0.5-3.diff.gz
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.9 (GNU/Linux)
+
+iEYEARECAAYFAkijKhsACgkQsrBfRdYmq7aA2gCfaOW9riTYVQMx5ajKQVAcctlC
+z2UAn1oXgTai6opwhVfkxrlmJ+iRxzuc
+=4eRd
+-----END PGP SIGNATURE-----
+EOF
+
+testequal "Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+  build-essential debhelper
+0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
+Inst build-essential (1 stable [i386])
+Inst debhelper (7 stable [i386])
+Conf build-essential (1 stable [i386])
+Conf debhelper (7 stable [i386])" aptget build-dep --simulate 2vcard_0.5-3.dsc
+
+
+# unpacked source dir
+mkdir -p foo-1.0/debian
+cat > foo-1.0/debian/control <<'EOF'
+Source: apturl
+Section: admin
+Priority: optional
+Maintainer: Michael Vogt <mvo@ubuntu.com>
+Build-Depends: debhelper (>= 7)
+X-Python3-Version: >= 3.2
+Standards-Version: 3.9.3
+
+Package: apturl-common
+Architecture: any
+Depends: ${python3:Depends},
+ ${shlibs:Depends},
+ ${misc:Depends},
+ python3-apt,
+ python3-update-manager
+Replaces: apturl (<< 0.3.6ubuntu2)
+Description: install packages using the apt protocol - common data
+ AptUrl is a simple graphical application that takes an URL (which follows the
+ apt-protocol) as a command line option, parses it and carries out the
+ operations that the URL describes (that is, it asks the user if he wants the
+ indicated packages to be installed and if the answer is positive does so for
+ him).
+ .
+ This package contains the common data shared between the frontends.
+
+EOF
+
+testequal "Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+  build-essential debhelper
+0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
+Inst build-essential (1 stable [i386])
+Inst debhelper (7 stable [i386])
+Conf build-essential (1 stable [i386])
+Conf debhelper (7 stable [i386])" aptget build-dep --simulate ./foo-1.0