[PATCH] Added a new boolean parameter called "update_submodules".

Martin Wilhelm martin at system4.org
Wed Oct 8 15:08:46 UTC 2014


If set to true and if the scm-method is "git", mock does a
"git submodule update --init --recursive" as a final step after
code checkout and possibly branch-switches.

Without "git submodule update --init --recursive" but with cloned
submodules, all the submodules are master-branch-only. Thus, you can't point
to a submodule's non-master-branch within your main project. Conversely, only
after a "git submodule update --init --recursive" its possible to point to
submodules non-master-branches.

The default for "update_submodules" is False (nothing will happen).
If it is set to True, but there are no submodules, git will simply exit 0.
Other SCM-methodes beside git are actually not supported.

Signed-off-by: Martin Wilhelm <martin at system4.org>
---
 etc/mock/site-defaults.cfg |  1 +
 py/mockbuild/scm.py        | 13 +++++++++++++
 py/mockbuild/util.py       |  1 +
 3 files changed, 15 insertions(+)

diff --git a/etc/mock/site-defaults.cfg b/etc/mock/site-defaults.cfg
index ffd6f72..4cec580 100644
--- a/etc/mock/site-defaults.cfg
+++ b/etc/mock/site-defaults.cfg
@@ -118,6 +118,7 @@
 # config_opts['scm_opts']['cvs_get'] = 'cvs -d /srv/cvs co SCM_BRN SCM_PKG'
 # config_opts['scm_opts']['git_get'] = 'git clone SCM_BRN git://localhost/SCM_PKG.git SCM_PKG'
 # config_opts['scm_opts']['svn_get'] = 'svn co file:///srv/svn/SCM_PKG/SCM_BRN SCM_PKG'
+# config_opts['scm_opts']['update_submodules'] = False
 # config_opts['scm_opts']['spec'] = 'SCM_PKG.spec'
 # config_opts['scm_opts']['ext_src_dir'] = '/dev/null'
 # config_opts['scm_opts']['write_tar'] = True
diff --git a/py/mockbuild/scm.py b/py/mockbuild/scm.py
index e76293d..83cce00 100644
--- a/py/mockbuild/scm.py
+++ b/py/mockbuild/scm.py
@@ -55,6 +55,16 @@ class scmWorker(object):
             self.get = self.get.replace("SCM_BRN", "trunk")
         self.get = self.get.replace("SCM_BRN", "")
 
+        self.submoduleupdatecommand = None
+        self.update_submodules = opts['update_submodules']
+        if str(self.update_submodules).lower() == "true":
+           # We only support git here. All other SCM methodes are unsupported if update_submodules is set to True.
+           if self.method == "git":
+              self.submoduleupdatecommand = "git submodule update --init --recursive"
+           else:
+              self.log.error("Unsupported SCM method: " + self.method)
+              sys.exit(5)
+
         if 'package' in opts:
             self.pkg = opts['package']
         else:
@@ -73,6 +83,7 @@ class scmWorker(object):
 
         self.log.debug("SCM checkout command: " + self.get)
         self.log.debug("SCM checkout post command: " + str(self.postget))
+        self.log.debug("SCM submodule update command: " + str(self.submoduleupdatecommand))
         self.environ = os.environ.copy()
         # Set HOME properly while checking out from SCM since tools like
         # Subversion might have there settings needed to carry out checkout
@@ -90,6 +101,8 @@ class scmWorker(object):
         mockbuild.util.do(shlex.split(self.get), shell=False, cwd=self.wrk_dir, env=self.environ)
         if self.postget:
             mockbuild.util.do(shlex.split(self.postget), shell=False, cwd=self.src_dir, env=self.environ)
+        if self.submoduleupdatecommand:
+            mockbuild.util.do(shlex.split(self.submoduleupdatecommand), shell=False, cwd=self.src_dir, env=self.environ)
         self.log.debug("Fetched sources from SCM")
 
     decorate(traceLog())
diff --git a/py/mockbuild/util.py b/py/mockbuild/util.py
index 49e0de4..733d41f 100644
--- a/py/mockbuild/util.py
+++ b/py/mockbuild/util.py
@@ -581,6 +581,7 @@ def setup_default_config_opts(unprivUid, version, pkgpythondir):
             'cvs_get': 'cvs -d /srv/cvs co SCM_BRN SCM_PKG',
             'git_get': 'git clone SCM_BRN git://localhost/SCM_PKG.git SCM_PKG',
             'svn_get': 'svn co file:///srv/svn/SCM_PKG/SCM_BRN SCM_PKG',
+            'update_submodules': False,
             'spec': 'SCM_PKG.spec',
             'ext_src_dir': '/dev/null',
             'write_tar': False,
-- 
1.9.1



More information about the buildsys mailing list