From feab34c5216941ca95aae1a389238a77b662d1de Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Apr 2014 17:59:09 +0200 Subject: add support for apt-get build-dep foo.dsc --- apt-pkg/deb/debsrcrecords.cc | 19 ++++++++ apt-pkg/deb/debsrcrecords.h | 7 +++ apt-pkg/tagfile.cc | 11 +++++ apt-pkg/tagfile.h | 2 + cmdline/apt-get.cc | 20 ++++++-- test/integration/test-apt-get-build-dep | 85 +++++++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 3 deletions(-) create mode 100755 test/integration/test-apt-get-build-dep diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index b09588dd3..fc748c40f 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -189,3 +190,21 @@ debSrcRecordParser::~debSrcRecordParser() delete[] Buffer; } /*}}}*/ + + +debDscRecordParser::debDscRecordParser(std::string const &DscFile) + : debSrcRecordParser(DscFile, NULL) +{ + // 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(); + +} diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index b65d1480b..0cd664818 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -26,6 +26,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser /** \brief dpointer placeholder (for later in case we need it) */ void *d; + protected: FileFd Fd; pkgTagFile Tags; pkgTagSection Sect; @@ -60,4 +61,10 @@ class debSrcRecordParser : public pkgSrcRecords::Parser virtual ~debSrcRecordParser(); }; +class debDscRecordParser : public debSrcRecordParser +{ + public: + debDscRecordParser(std::string const &DscFile); +}; + #endif diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 91d176e3c..009ed7d74 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -51,12 +51,23 @@ public: // --------------------------------------------------------------------- /* */ 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 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 to the end of the file -> 4 extra chars */ Size += 4; + if(d != NULL) + { + free(d->Buffer); + delete d; + } d = new pkgTagFilePrivate(pFd, Size); if (d->Fd.IsOpen() == false) diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index d5b62e76d..d1a24ba45 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -105,6 +105,8 @@ class pkgTagFile unsigned 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); virtual ~pkgTagFile(); }; diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index caf69da2a..92384931b 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -57,6 +57,9 @@ #include #include +// FIXME: direct include of deb specific header +#include + #include #include #include @@ -1053,12 +1056,23 @@ static bool DoBuildDep(CommandLine &CmdL) for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) { string Src; - pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache); + pkgSrcRecords::Parser *Last = 0; + vector BuildDeps; + + // support local .dsc files + if (FileExists(*I) && flExtension(*I) == "dsc") + { + // FIXME: add a layer of abstraction + Last = new debDscRecordParser(*I); + Src = *I; + } else { + Last = FindSrc(*I,Recs,SrcRecs,Src,Cache); + } if (Last == 0) return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); // Process the build-dependencies - vector BuildDeps; + // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary if (hostArch.empty() == false) { @@ -1071,7 +1085,7 @@ static bool DoBuildDep(CommandLine &CmdL) } 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()); - + // Also ensure that build-essential packages are present Configuration::Item const *Opts = _config->Tree("APT::Build-Essential"); if (Opts) diff --git a/test/integration/test-apt-get-build-dep b/test/integration/test-apt-get-build-dep new file mode 100755 index 000000000..6516aa705 --- /dev/null +++ b/test/integration/test-apt-get-build-dep @@ -0,0 +1,85 @@ +#!/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 < +Uploaders: Marcela Tiznado +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 < +Uploaders: Marcela Tiznado +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 -- cgit v1.2.3 From a49e7948029d8219d7cb182fbc1b0adb587691b8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 23 Apr 2014 13:51:48 +0200 Subject: create debIFTypeDscFile type --- apt-pkg/deb/debindexfile.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/deb/debindexfile.h | 18 +++++++++++++++ apt-pkg/deb/debsrcrecords.cc | 4 ++-- apt-pkg/deb/debsrcrecords.h | 2 +- apt-pkg/indexfile.h | 1 + apt-pkg/pkgsystem.h | 6 +++-- apt-pkg/sourcelist.h | 2 +- cmdline/apt-get.cc | 20 ++++++++--------- 8 files changed, 89 insertions(+), 16 deletions(-) diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index eee758b7a..e7e764dd4 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -667,6 +667,42 @@ APT_CONST bool debStatusIndex::Exists() 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 /*{{{*/ class debIFTypeSrc : public pkgIndexFile::Type { @@ -699,10 +735,22 @@ class debIFTypeStatus : public pkgIndexFile::Type }; debIFTypeStatus() {Label = "Debian dpkg status 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";}; +}; + static debIFTypeSrc _apt_Src; static debIFTypePkg _apt_Pkg; static debIFTypeTrans _apt_Trans; static debIFTypeStatus _apt_Status; +// file based pseudo indexes +static debIFTypeDscFile _apt_DscFile; const pkgIndexFile::Type *debSourcesIndex::GetType() const { @@ -720,5 +768,9 @@ const pkgIndexFile::Type *debStatusIndex::GetType() const { return &_apt_Status; } +const pkgIndexFile::Type *debDscFileIndex::GetType() const +{ + return &_apt_DscFile; +} /*}}}*/ diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 017c69a0a..88abfdd9d 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -164,4 +164,22 @@ class debSourcesIndex : public pkgIndexFile virtual ~debSourcesIndex() {}; }; +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() {}; +}; + #endif diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index fc748c40f..8aad81e3c 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -192,8 +192,8 @@ debSrcRecordParser::~debSrcRecordParser() /*}}}*/ -debDscRecordParser::debDscRecordParser(std::string const &DscFile) - : debSrcRecordParser(DscFile, NULL) +debDscRecordParser::debDscRecordParser(std::string const &DscFile, pkgIndexFile const *Index) + : debSrcRecordParser(DscFile, Index) { // support clear signed files if (OpenMaybeClearSignedFile(DscFile, Fd) == false) diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index 0cd664818..a0a151875 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -64,7 +64,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser class debDscRecordParser : public debSrcRecordParser { public: - debDscRecordParser(std::string const &DscFile); + debDscRecordParser(std::string const &DscFile, pkgIndexFile const *Index); }; #endif diff --git a/apt-pkg/indexfile.h b/apt-pkg/indexfile.h index b5c9ac77e..817165f08 100644 --- a/apt-pkg/indexfile.h +++ b/apt-pkg/indexfile.h @@ -59,6 +59,7 @@ class pkgIndexFile const char *Label; virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator /*File*/) const {return 0;}; + virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string /*File*/) const {return 0;}; Type(); virtual ~Type() {}; }; diff --git a/apt-pkg/pkgsystem.h b/apt-pkg/pkgsystem.h index 6e33c67ed..f88ffa7c8 100644 --- a/apt-pkg/pkgsystem.h +++ b/apt-pkg/pkgsystem.h @@ -85,10 +85,12 @@ class pkgSystem virtual bool AddStatusFiles(std::vector &List) = 0; virtual bool FindIndex(pkgCache::PkgFileIterator File, pkgIndexFile *&Found) const = 0; - + /* Evauluate how 'right' we are for this system based on the filesystem etc.. */ - virtual signed Score(Configuration const &/*Cnf*/) {return 0;}; + virtual signed Score(Configuration const &/*Cnf*/) { + return 0; + }; pkgSystem(); virtual ~pkgSystem() {}; diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h index 9df0c1d74..0ebf4e080 100644 --- a/apt-pkg/sourcelist.h +++ b/apt-pkg/sourcelist.h @@ -86,7 +86,7 @@ class pkgSourceList typedef std::vector::const_iterator const_iterator; - protected: + public: std::vector SrcList; diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 92384931b..5418c351b 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -57,9 +57,6 @@ #include #include -// FIXME: direct include of deb specific header -#include - #include #include #include @@ -1057,22 +1054,25 @@ static bool DoBuildDep(CommandLine &CmdL) { string Src; pkgSrcRecords::Parser *Last = 0; - vector BuildDeps; - // support local .dsc files - if (FileExists(*I) && flExtension(*I) == "dsc") + // if its a local file (e.g. .dsc) use this + if (FileExists(*I)) { - // FIXME: add a layer of abstraction - Last = new debDscRecordParser(*I); - Src = *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) return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); // Process the build-dependencies - + vector BuildDeps; // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary if (hostArch.empty() == false) { -- cgit v1.2.3 From 77da39b95870498431fc21df65900acc5ce2f7ea Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 25 Apr 2014 09:47:50 +0200 Subject: add support for apt-get build-dep unpacked-source-dir --- apt-pkg/deb/debindexfile.cc | 14 +++++++++++ apt-pkg/deb/debindexfile.h | 5 ++++ cmdline/apt-get.cc | 11 ++++++++- test/integration/test-apt-get-build-dep | 41 +++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index e7e764dd4..bb6884123 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -744,6 +744,15 @@ class debIFTypeDscFile : public pkgIndexFile::Type }; 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 debIFTypePkg _apt_Pkg; @@ -751,6 +760,7 @@ static debIFTypeTrans _apt_Trans; static debIFTypeStatus _apt_Status; // file based pseudo indexes static debIFTypeDscFile _apt_DscFile; +static debIFTypeDebianSourceDir _apt_DebianSourceDir; const pkgIndexFile::Type *debSourcesIndex::GetType() const { @@ -772,5 +782,9 @@ const pkgIndexFile::Type *debDscFileIndex::GetType() const { return &_apt_DscFile; } +const pkgIndexFile::Type *debDebianSourceDirIndex::GetType() const +{ + return &_apt_DebianSourceDir; +} /*}}}*/ diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 88abfdd9d..64ca558d2 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -182,4 +182,9 @@ class debDscFileIndex : public pkgIndexFile virtual ~debDscFileIndex() {}; }; +class debDebianSourceDirIndex : public debDscFileIndex +{ + virtual const Type *GetType() const APT_CONST; +}; + #endif diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 5418c351b..6d6ba5ff9 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1055,8 +1055,17 @@ static bool DoBuildDep(CommandLine &CmdL) string Src; 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 - if (FileExists(*I)) + else if (FileExists(*I)) { // see if we can get a parser for this pkgIndexFile type string TypeName = flExtension(*I) + " File Source Index"; diff --git a/test/integration/test-apt-get-build-dep b/test/integration/test-apt-get-build-dep index 6516aa705..f71beae9c 100755 --- a/test/integration/test-apt-get-build-dep +++ b/test/integration/test-apt-get-build-dep @@ -83,3 +83,44 @@ 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 +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 -- cgit v1.2.3