Просмотр исходного кода

Added compile and unpack support to apt-get
Author: jgg
Date: 1999-04-19 06:03:09 GMT
Added compile and unpack support to apt-get

Arch Librarian лет назад: 22
Родитель
Сommit
fb0ee66e0b
6 измененных файлов с 108 добавлено и 7 удалено
  1. 22 1
      apt-pkg/version.cc
  2. 2 1
      apt-pkg/version.h
  3. 64 2
      cmdline/apt-get.cc
  4. 7 1
      doc/apt-get.8.yo
  5. 6 1
      doc/apt.conf.5.yo
  6. 7 1
      doc/examples/apt.conf

+ 22 - 1
apt-pkg/version.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: version.cc,v 1.8 1998/12/05 01:44:57 jgg Exp $
+// $Id: version.cc,v 1.9 1999/04/19 06:03:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Version - Version string 
    Version - Version string 
@@ -248,3 +248,24 @@ bool pkgCheckDep(const char *DepVer,const char *PkgVer,int Op)
    return false;
    return false;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// BaseVersion - Return the upstream version string			/*{{{*/
+// ---------------------------------------------------------------------
+/* This strips all the debian specific information from the version number */
+string pkgBaseVersion(const char *Ver)
+{
+   // Strip off the bit before the first colon
+   const char *I = Ver;
+   for (; *I != 0 && *I != ':'; I++);
+   if (*I == ':')
+      Ver = I + 1;
+   
+   // Chop off the trailing -
+   I = Ver;
+   unsigned Last = strlen(Ver);
+   for (; *I != 0; I++)
+      if (*I == '-')
+	 Last = I - Ver;
+   
+   return string(Ver,Last);
+}
+									/*}}}*/

+ 2 - 1
apt-pkg/version.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: version.h,v 1.4 1998/07/19 21:24:19 jgg Exp $
+// $Id: version.h,v 1.5 1999/04/19 06:03:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Version - Version comparison routines
    Version - Version comparison routines
@@ -25,5 +25,6 @@ int pkgVersionCompare(const char *A, const char *AEnd, const char *B,
 		   const char *BEnd);
 		   const char *BEnd);
 int pkgVersionCompare(string A,string B);
 int pkgVersionCompare(string A,string B);
 bool pkgCheckDep(const char *DepVer,const char *PkgVer,int Op);
 bool pkgCheckDep(const char *DepVer,const char *PkgVer,int Op);
+string pkgBaseVersion(const char *Ver);
 
 
 #endif
 #endif

+ 64 - 2
cmdline/apt-get.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: apt-get.cc,v 1.53 1999/04/18 06:51:09 jgg Exp $
+// $Id: apt-get.cc,v 1.54 1999/04/19 06:03:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    apt-get - Cover for dpkg
    apt-get - Cover for dpkg
@@ -1047,6 +1047,13 @@ bool DoCheck(CommandLine &CmdL)
 // DoSource - Fetch a source archive					/*{{{*/
 // DoSource - Fetch a source archive					/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* Fetch souce packages */
 /* Fetch souce packages */
+struct DscFile
+{
+   string Package;
+   string Version;
+   string Dsc;
+};
+
 bool DoSource(CommandLine &CmdL)
 bool DoSource(CommandLine &CmdL)
 {
 {
    CacheFile Cache;
    CacheFile Cache;
@@ -1070,9 +1077,12 @@ bool DoSource(CommandLine &CmdL)
    // Create the download object
    // Create the download object
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));   
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));   
    pkgAcquire Fetcher(&Stat);
    pkgAcquire Fetcher(&Stat);
+
+   DscFile *Dsc = new DscFile[CmdL.FileSize()];
    
    
    // Load the requestd sources into the fetcher
    // Load the requestd sources into the fetcher
-   for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+   unsigned J = 0;
+   for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    {
    {
       string Src;
       string Src;
       
       
@@ -1130,7 +1140,13 @@ bool DoSource(CommandLine &CmdL)
 	 // Try to guess what sort of file it is we are getting.
 	 // Try to guess what sort of file it is we are getting.
 	 string Comp;
 	 string Comp;
 	 if (I->Path.find(".dsc") != string::npos)
 	 if (I->Path.find(".dsc") != string::npos)
+	 {
 	    Comp = "dsc";
 	    Comp = "dsc";
+	    Dsc[J].Package = Last->Package();
+	    Dsc[J].Version = Last->Version();
+	    Dsc[J].Dsc = flNotDir(I->Path);
+	 }
+	 
 	 if (I->Path.find(".tar.gz") != string::npos)
 	 if (I->Path.find(".tar.gz") != string::npos)
 	    Comp = "tar";
 	    Comp = "tar";
 	 if (I->Path.find(".diff.gz") != string::npos)
 	 if (I->Path.find(".diff.gz") != string::npos)
@@ -1180,6 +1196,7 @@ bool DoSource(CommandLine &CmdL)
       return false;
       return false;
 
 
    // Print error messages
    // Print error messages
+   bool Failed = false;
    for (pkgAcquire::Item **I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
    for (pkgAcquire::Item **I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
    {
    {
       if ((*I)->Status == pkgAcquire::Item::StatDone &&
       if ((*I)->Status == pkgAcquire::Item::StatDone &&
@@ -1188,8 +1205,51 @@ bool DoSource(CommandLine &CmdL)
       
       
       cerr << "Failed to fetch " << (*I)->DescURI() << endl;
       cerr << "Failed to fetch " << (*I)->DescURI() << endl;
       cerr << "  " << (*I)->ErrorText << endl;
       cerr << "  " << (*I)->ErrorText << endl;
+      Failed = true;
    }
    }
+   if (Failed == true)
+      return _error->Error("Failed to fetch some archives.");
+   
+   if (_config->FindB("APT::Get::Download-only",false) == true)
+      return true;
    
    
+   // Unpack the sources
+   for (unsigned I = 0; I != J; I++)
+   {
+      string Dir = Dsc[I].Package + '-' + pkgBaseVersion(Dsc[I].Version.c_str());
+    
+      // See if the package is already unpacked
+      struct stat Stat;
+      if (stat(Dir.c_str(),&Stat) == 0 &&
+	  S_ISDIR(Stat.st_mode) != 0)
+      {
+	 c0out << "Skipping unpack of already unpacked source in " << Dir << endl;
+      }
+      else
+      {
+	 // Call dpkg-source
+	 char S[500];
+	 snprintf(S,sizeof(S),"%s -x %s",
+		  _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
+		  Dsc[I].Dsc.c_str());
+	 if (system(S) != 0)
+	    return _error->Error("Unpack command '%s' failed.",S);
+      }
+  
+      // Try to compile it with dpkg-buildpackage
+      if (_config->FindB("APT::Get::Compile",false) == true)
+      {
+	 // Call dpkg-buildpackage
+	 char S[500];
+	 snprintf(S,sizeof(S),"cd %s && %s %s",
+		  Dir.c_str(),
+		  _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
+		  _config->Find("DPkg::Build-Options","-b -uc").c_str());
+	 
+	 if (system(S) != 0)
+	    return _error->Error("Build command '%s' failed.",S);
+      }      
+   }   
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -1277,6 +1337,8 @@ int main(int argc,const char *argv[])
       {'q',"quiet","quiet",CommandLine::IntLevel},
       {'q',"quiet","quiet",CommandLine::IntLevel},
       {'q',"silent","quiet",CommandLine::IntLevel},
       {'q',"silent","quiet",CommandLine::IntLevel},
       {'d',"download-only","APT::Get::Download-Only",0},
       {'d',"download-only","APT::Get::Download-Only",0},
+      {'b',"compile","APT::Get::Compile",0},
+      {'b',"build","APT::Get::Compile",0},
       {'s',"simulate","APT::Get::Simulate",0},      
       {'s',"simulate","APT::Get::Simulate",0},      
       {'s',"just-print","APT::Get::Simulate",0},      
       {'s',"just-print","APT::Get::Simulate",0},      
       {'s',"recon","APT::Get::Simulate",0},      
       {'s',"recon","APT::Get::Simulate",0},      

+ 7 - 1
doc/apt-get.8.yo

@@ -89,7 +89,10 @@ find and download into the current directory the newest available version of
 that source package. Source packages are tracked seperately from binary
 that source package. Source packages are tracked seperately from binary
 packages via df(deb-src) type lines in the bf(/etc/apt/sources.list) file.
 packages via df(deb-src) type lines in the bf(/etc/apt/sources.list) file.
 This probably will mean that you will not get the same source as the package
 This probably will mean that you will not get the same source as the package
-you have installed or as you could install.
+you have installed or as you could install. If the --compile options is
+specified then the package will be compiled to a binary .deb using
+dpkg-buildpackage, if --download-only is specified then the source package
+will not be unpacked.
 
 
 dit(bf(check))
 dit(bf(check))
 bf(check) is a diagnostic tool; it updates the package cache and checks for 
 bf(check) is a diagnostic tool; it updates the package cache and checks for 
@@ -173,6 +176,9 @@ dit(bf(-u, --show-upgraded))
 Show upgraded packages; Print out a list of all packages that are to be
 Show upgraded packages; Print out a list of all packages that are to be
 upgraded. See bf(APT::Get::Show-Upgraded).
 upgraded. See bf(APT::Get::Show-Upgraded).
 
 
+dit(bf(-b, --compile, --build))
+Compile source packages after downloading them.
+
 dit(bf(--ignore-hold))
 dit(bf(--ignore-hold))
 Ignore package Holds; This causes bf(apt-get) to ignore a hold placed on 
 Ignore package Holds; This causes bf(apt-get) to ignore a hold placed on 
 a package. This may be usefull in conjunction with bf(dist-upgrade) to
 a package. This may be usefull in conjunction with bf(dist-upgrade) to

+ 6 - 1
doc/apt.conf.5.yo

@@ -150,7 +150,8 @@ gives the location of the sourcelist and bf(main) is the default configuration
 file (setting has no effect)
 file (setting has no effect)
 
 
 Binary programs are pointed to by bf(Dir::Bin). bf(methods) specifies the
 Binary programs are pointed to by bf(Dir::Bin). bf(methods) specifies the
-location of the method handlers and bf(gzip), bf(dpkg), bf(apt-get), and
+location of the method handlers and bf(gzip), bf(dpkg), bf(apt-get), 
+bf(dpkg-source), bf(dpkg-buildpackage) and
 bf(apt-cache) specify the location of the respective programs.
 bf(apt-cache) specify the location of the respective programs.
 
 
 manpagesection(APT in DSelect)
 manpagesection(APT in DSelect)
@@ -194,6 +195,10 @@ are invoked in order using /bin/sh, should any fail APT will abort.
 dit(bf(Run-Directory))
 dit(bf(Run-Directory))
 APT chdirs to this directory before invoking dpkg, the default is /.
 APT chdirs to this directory before invoking dpkg, the default is /.
 
 
+dit(bf(Build-Options))
+These options are passed to dpkg-buildpackage when compiling packages,
+the default is to disable signing and produce all binaries.
+
 enddit()
 enddit()
 
 
 manpagesection(Debug Options)
 manpagesection(Debug Options)

+ 7 - 1
doc/examples/apt.conf

@@ -1,4 +1,4 @@
-// $Id: apt.conf,v 1.31 1999/04/11 21:23:10 jgg Exp $
+// $Id: apt.conf,v 1.32 1999/04/19 06:03:09 jgg Exp $
 /* This file is an index of all APT configuration directives. It should
 /* This file is an index of all APT configuration directives. It should
    NOT actually be used as a real config file, though it is a completely
    NOT actually be used as a real config file, though it is a completely
    valid file.
    valid file.
@@ -32,6 +32,7 @@ APT
      Show-Upgraded "false";
      Show-Upgraded "false";
      No-Upgrade "false";
      No-Upgrade "false";
      Print-URIs "false";
      Print-URIs "false";
+     Compile "false";
   };
   };
 
 
   Cache 
   Cache 
@@ -139,6 +140,8 @@ Dir
      methods "/usr/lib/apt/methods/";
      methods "/usr/lib/apt/methods/";
      gzip "/bin/gzip";
      gzip "/bin/gzip";
      dpkg "/usr/bin/dpkg";
      dpkg "/usr/bin/dpkg";
+     dpkg-source "/usr/bin/dpkg-source";
+     dpkg-buildpackage "/usr/bin/dpkg-buildpackage"
      apt-get "/usr/bin/apt-get";
      apt-get "/usr/bin/apt-get";
      apt-cache "/usr/bin/apt-cache";
      apt-cache "/usr/bin/apt-cache";
   };
   };
@@ -164,6 +167,9 @@ DPkg
    
    
    // Prevents daemons from getting cwd as something mountable (default)
    // Prevents daemons from getting cwd as something mountable (default)
    Run-Directory "/";
    Run-Directory "/";
+   
+   // Build options for apt-get source --compile
+   Build-Options "-b -uc";
 }
 }
 
 
 /* Options you can set to see some debugging text They corrispond to names
 /* Options you can set to see some debugging text They corrispond to names