Classification: HACK

This patches uses an external program to resolve buildrequirements.
Such a program exists in the fedora.us-build package
(http://www.tu-chemnitz.de/~ensc/fedora.us-build/files).

The 'args' patch is mandatory for this one.


2003-12-05  Enrico Scholz  <enrico.scholz@informatik.tu-chemnitz.de>
	* created initially

--- mach/scripts/mach.in~buildreq	2003-12-09 00:19:16.000000000 +0100
+++ mach/scripts/mach.in	2003-12-09 00:19:16.000000000 +0100
@@ -11,6 +11,7 @@
 import tempfile # for tempdir for spec extraction
 import glob # for globbing paths
 import grp # for finding out the mach gid
+import popen2
 
 # make sure True and False constants exist
 
@@ -76,6 +77,7 @@
   'rm': '@SBINDIR@/mach-helper rm',
   'apt-get': '@SBINDIR@/mach-helper apt-get',
   'apt-cache': '/usr/bin/apt-cache',
+  'resolve-builddeps': '/usr/bin/resolve-builddeps',
 
 }
 DEBUG = 0
@@ -253,15 +255,27 @@
         debug ("SRPM.specname: %s" % name)
         return name
     
-    def BuildRequires (self):
+    def BuildRequires (self, statedir, rootdir, args):
         "return a list of BuildRequires for this src.rpm"
-        buildreqs = self.header[rpm.RPMTAG_REQUIRENAME]
-        # remove non-packagey things from buildreqs
-        # currently removes everything containing ( or /
-        if buildreqs:
-            return filter(lambda x: not re.search("^(/|rpmlib\\()", x), buildreqs)
-        else:
-            return []
+
+        path     = self.path
+        specname = self.specname
+        spectmp  = os.path.join ("/usr/src/rpm/SPECS", specname)
+
+
+        opts = map(lambda x: escapeShell(x), args)
+        cmd  = '%s "%s" "%s" "%s" %s' % (config['resolve-builddeps'],
+                                         statedir, spectmp, rootdir,
+                                         string.join(opts))
+        debug("Executing: %s" % cmd)
+        proc = popen2.Popen3(cmd)
+        res  = map(lambda x: string.strip(x), proc.fromchild.readlines())
+        code = proc.wait()
+        debug("-> status=%u, res=%s" % (code,res))
+        if not os.WIFEXITED(code) or os.WEXITSTATUS(code)!=0:
+            warning("resolve-builddeps failed with code %x" % code)
+
+        return res
 
     def results (self):
         "returns a list of packages that can be built from this src.rpm"
@@ -757,8 +771,9 @@
         pkgs = {}
         for path in paths:
     	# resolve path to basename (without dirs)
-            srpmname = os.path.basename (path)
-            newpath = os.path.join (self.rootdir, 'tmp', srpmname)
+            srpmname  = os.path.basename (path)
+            plainpath = os.path.join('/tmp', srpmname)
+            newpath   = self.rootdir + plainpath
             try:
                 urlgrab (path, newpath)
             except IOError:
@@ -766,7 +781,8 @@
                 return False
             srpm = SRPM (newpath)
             spec = srpm.specname
-            buildreqs = srpm.BuildRequires ()
+            self.do_chroot ("su -c 'rpm -Uhv --force --nodeps %s' machbuild" % plainpath)
+            buildreqs = srpm.BuildRequires (self.statedir+"/apt/var/state/apt/lists", self.rootdir, options)
             name = srpm.header[rpm.RPMTAG_NAME]
             pkgs[name] = {}
             pkgs[name]['path'] = newpath
