[Yum-devel] [PATCH] yum-builddep directly from spec files

Panu Matilainen pmatilai at laiskiainen.org
Tue Nov 23 09:23:11 UTC 2010


Hi,

Attached quick hack of a patch adds support for installing build requires 
directly from spec files to yum-builddep if rpm-python supports it 
(currently means rpm >= 4.9 but likely to be backported to 4.8 too), eg

[root at dhcp102 yum-utils]# ./yum-builddep.py /tmp/alpine.spec
Loaded plugins: presto, refresh-packagekit
Getting requirements for /home/pmatilai/dist/alpine/alpine.spec
  --> Already installed : gettext-0.18.1.1-4.fc14.x86_64
  --> Already installed : hunspell-1.2.12-3.fc14.x86_64
  --> krb5-devel-1.8.2-6.fc14.x86_64
  --> Already installed : ncurses-devel-5.7-8.20100703.fc14.x86_64
  --> Already installed : openldap-devel-2.4.23-3.fc14.x86_64
  --> openssl-devel-1.0.0b-1.fc14.x86_64
  --> pam-devel-1.1.1-6.fc14.x86_64
  --> Already installed : passwd-0.78-1.fc14.x86_64
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.8.2-6.fc14 set to be installed
---> Package openssl-devel.x86_64 0:1.0.0b-1.fc14 set to be installed
---> Package pam-devel.x86_64 0:1.1.1-6.fc14 set to be installed
--> Finished Dependency Resolution

Dependencies Resolved
...

 	- Panu -

-------------- next part --------------
diff --git a/yum-builddep.py b/yum-builddep.py
index 657707b..02db3b0 100755
--- a/yum-builddep.py
+++ b/yum-builddep.py
@@ -136,6 +136,24 @@ class YumBuildDep(YumUtilBase):
                     print "Could not setup repo %s: %s" % (r.id, e)
                     sys.exit(1)
 
+    def install_deps(self, deplist):
+        for dep in deplist:
+            self.logger.debug(' REQ:  %s' % dep)                
+            if dep.startswith("rpmlib("): 
+                continue
+            instreq = self.returnInstalledPackagesByDep(dep)
+            if instreq:
+                self.logger.info(' --> Already installed : %s'  % instreq[0])                    
+                continue
+            try:
+                pkg = self.returnPackageByDep(dep)
+                self.logger.info(' --> %s' % pkg)
+                self.install(pkg)
+                
+            except yum.Errors.YumBaseError, e:
+                self.logger.error("Error: %s" % e)
+                sys.exit(1)
+
     # go through each of the pkgs, figure out what they are/where they are 
     # if they are not a local package then run
         # Setup source repos
@@ -146,7 +164,14 @@ class YumBuildDep(YumUtilBase):
     
     def get_build_deps(self,opts):
         srcnames = []
+        specnames = []
         srpms = []
+        specworks = False
+
+        # See if we can use spec files for buildrequires
+        if hasattr(rpm, 'spec') and hasattr(rpm.spec, 'sourceHeader'):
+            specworks = True
+
         for arg in self.cmds:
             if arg.endswith('.src.rpm'):
                 try:
@@ -157,6 +182,8 @@ class YumBuildDep(YumUtilBase):
                     raise
             elif arg.endswith('.src'):
                 srcnames.append(arg)
+            elif specworks and arg.endswith('.spec'):
+                specnames.append(arg)
             else:
                 srcnames.append(arg)
 
@@ -183,24 +210,22 @@ class YumBuildDep(YumUtilBase):
 
         for srpm in toActOn:
             self.logger.info('Getting requirements for %s' % srpm)
-            for dep in srpm.requiresList():
-                self.logger.debug(' REQ:  %s' % dep)                
-                if dep.startswith("rpmlib("): 
-                    continue
-                instreq = self.returnInstalledPackagesByDep(dep)
-                if instreq:
-                    self.logger.info(' --> Already installed : %s'  % instreq[0])                    
-                    continue
-                try:
-                    pkg = self.returnPackageByDep(dep)
-                    self.logger.info(' --> %s' % pkg)
-                    self.install(pkg)
-                    
-                except yum.Errors.YumBaseError, e:
-                    self.logger.error("Error: %s" % e)
-                    sys.exit(1)
-    
+            self.install_deps(srpm.requiresList())
     
+        for name in specnames:
+            try:
+                spec = rpm.spec(name)
+            except ValueError:
+                self.logger.error("Bad spec: %s" % name)
+                continue
+
+            buildreqs = []
+            for d in rpm.ds(spec.sourceHeader, 'requires'):
+                buildreqs.append(d.DNEVR()[2:])
+                
+            self.logger.info('Getting requirements for %s' % name)
+            self.install_deps(buildreqs)
+            
 if __name__ == '__main__':
     setup_locale()
     util = YumBuildDep()


More information about the Yum-devel mailing list