[PATCH] add support to make the command used to fetch sources configuable per repo

dennis at ausil.us dennis at ausil.us
Fri Jun 11 18:09:21 UTC 2010


From: Dennis Gilmore <dennis at ausil.us>

---
 builder/kojid |   43 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/builder/kojid b/builder/kojid
index 893b180..c854364 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -495,12 +495,13 @@ class BuildRoot(object):
         msg = '; see %s for more information' % logfile
         return _parseStatus(rv, 'mock') + msg
 
-    def build_srpm(self, specfile, sourcedir):
+    def build_srpm(self, specfile, sourcedir, source_cmd):
         session.host.setBuildRootState(self.id,'BUILDING')
         chroot_sourcedir = sourcedir[len(self.rootdir()):]
-        # call "make sources" in the chroot so any required files not stored in
+        # call the command defined by source_cmd in the chroot so any required files not stored in
         # the SCM can be retrieved
-        args = ['--no-clean', '--unpriv', '--cwd', chroot_sourcedir, '--chroot', 'make', 'sources']
+        args = ['--no-clean', '--unpriv', '--cwd', chroot_sourcedir, '--chroot']
+        args.extend(source_cmd)
 
         rv = self.mock(args)
 
@@ -2629,6 +2630,7 @@ class BuildSRPMFromSCMTask(BaseTaskHandler):
         # will throw a BuildError if the url is invalid
         scm = SCM(url)
         scm.assert_allowed(options.allowed_scms)
+        source_cmd = scm.get_source_cmd(options.allowed_scms)
 
         if opts is None:
             opts = {}
@@ -2685,7 +2687,7 @@ class BuildSRPMFromSCMTask(BaseTaskHandler):
 
         #build srpm
         self.logger.debug("Running srpm build")
-        broot.build_srpm(spec_file, sourcedir)
+        broot.build_srpm(spec_file, sourcedir, source_cmd)
 
         srpms = glob.glob('%s/*.src.rpm' % broot.resultdir())
         if len(srpms) == 0:
@@ -3255,6 +3257,7 @@ class SCM(object):
         - module
         - revision
         - use_common (defaults to True, may be set by assert_allowed())
+        - source_cmd (defaults to ['make', 'sources'], may be set by get_source_cmd())
         - scmtype
 
         The exact format of each attribute is SCM-specific, but the structure of the url
@@ -3275,6 +3278,7 @@ class SCM(object):
         self.module = query
         self.revision = fragment
         self.use_common = True
+        self.source_cmd = ['make', 'sources']
 
         for scmtype, schemes in SCM.types.items():
             if self.scheme in schemes:
@@ -3331,7 +3335,7 @@ class SCM(object):
         Verify that the host and repository of this SCM is in the provided list of
         allowed repositories.
 
-        allowed is a space-separated list of host:repository[:use_common] tuples.  Incorrectly-formatted
+        allowed is a space-separated list of host:repository[[:use_common]:source_cmd] tuples.  Incorrectly-formatted
         tuples will be ignored.
 
         If use_common is not present, kojid will attempt to checkout a common/ directory from the
@@ -3340,11 +3344,11 @@ class SCM(object):
         """
         for allowed_scm in allowed.split():
             scm_tuple = allowed_scm.split(':')
-            if len(scm_tuple) in (2, 3):
+            if len(scm_tuple) in (2, 3, 4):
                 if fnmatch(self.host, scm_tuple[0]) and fnmatch(self.repository, scm_tuple[1]):
                     # SCM host:repository is in the allowed list
                     # check if we specify a value for use_common
-                    if len(scm_tuple) == 3:
+                    if len(scm_tuple) >= 3:
                         if scm_tuple[2].lower() in ('no', 'off', 'false', '0'):
                             self.use_common = False
                     break
@@ -3353,6 +3357,31 @@ class SCM(object):
         else:
             raise koji.BuildError, '%s:%s is not in the list of allowed SCMs' % (self.host, self.repository)
 
+    def get_source_cmd(self, allowed):
+        """
+        Get the command to be used for the repo to pull its sources from lookaside cache.
+ 
+        allowed is a space-separated list of host:repository:use_common:[source_cmd] tuples.  Incorrectly-formatted
+        tuples will be ignored.
+
+        use_common must be present to define a source_cmd. source_cmd is a comma seperated list default is make,sources
+        """
+        for allowed_scm in allowed.split():
+            scm_tuple = allowed_scm.split(':')
+            if len(scm_tuple) in (2, 3, 4):
+                if fnmatch(self.host, scm_tuple[0]) and fnmatch(self.repository, scm_tuple[1]):
+                    # SCM host:repository is in the allowed list
+                    # check if we specify a value for source_cmd
+                    if len(scm_tuple) == 4:
+                        self.source_cmd = scm_tuple[3].split(',')
+                    break
+            else:
+                self.logger.warn('Ignoring incorrectly formatted SCM host:repository: %s' % allowed_scm)
+        else:
+            raise koji.BuildError, '%s:%s is not in the list of allowed SCMs' % (self.host, self.repository)
+
+        return self.source_cmd
+
     def checkout(self, scmdir, uploadpath, logfile):
         """
         Checkout the module from SCM.  Accepts the following parameters:
-- 
1.7.0.1



More information about the buildsys mailing list