diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2015-07-10 14:48:01 -0400 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2015-09-10 14:03:31 -0400 |
commit | 6692a69b6abe35bca60e9e1975aef8a54736a7b0 (patch) | |
tree | deb9e256fe1f5f5cdfe9dd4a6cb405bd5ac9643c | |
parent | a4da77b0b759eaf8a131f33a6daed6c76364f885 (diff) |
git: Also fetch submodules during the fetch stage
Instead of fetching the submodules during the build, do it as the fetch
stage. Also copy the submodules from the local sources during the local
checkout.
https://bugzilla.gnome.org/show_bug.cgi?id=742830
-rw-r--r-- | cerbero/build/source.py | 3 | ||||
-rw-r--r-- | cerbero/utils/git.py | 37 |
2 files changed, 36 insertions, 4 deletions
diff --git a/cerbero/build/source.py b/cerbero/build/source.py index 2bc3360d..b60d00d3 100644 --- a/cerbero/build/source.py +++ b/cerbero/build/source.py @@ -161,6 +161,7 @@ class GitCache (Source): git.add_remote(self.repo_dir, remote, "file://" + cached_dir) git.fetch(self.repo_dir, fail=False) else: + cached_dir = None # add remotes from both upstream and config so user can easily # cherry-pick patches between branches for remote, url in self.remotes.iteritems(): @@ -172,6 +173,8 @@ class GitCache (Source): if checkout: commit = self.config.recipe_commit(self.name) or self.commit git.checkout(self.repo_dir, commit) + git.submodules_update(self.repo_dir, cached_dir, fail=False) + def built_version(self): return '%s+git~%s' % (self.version, git.get_hash(self.repo_dir, self.commit)) diff --git a/cerbero/utils/git.py b/cerbero/utils/git.py index 697cdc76..53717d72 100644 --- a/cerbero/utils/git.py +++ b/cerbero/utils/git.py @@ -111,6 +111,36 @@ def fetch(git_dir, fail=True): ''' return shell.call('%s fetch --all' % GIT, git_dir, fail=fail) +def submodules_update(git_dir, src_dir=None, fail=True): + ''' + Update somdules from local directory + + @param git_dir: path of the git repository + @type git_dir: str + @param src_dir: path or base URI of the source directory + @type src_dir: src + @param fail: raise an error if the command failed + @type fail: false + ''' + if src_dir: + config = shell.check_call('%s config --file=.gitmodules --list' % GIT, + git_dir) + config_array = [s.split('=', 1) for s in config.split('\n')] + for c in config_array: + if c[0].startswith('submodule.') and c[0].endswith('.path'): + submodule = c[0][len('submodule.'):-len('.path')] + shell.call("%s config --file=.gitmodules submodule.%s.url %s" % + (GIT, submodule, os.path.join(src_dir, c[1])), + git_dir) + shell.call("%s submodule init" % GIT, git_dir) + shell.call("%s submodule sync" % GIT, git_dir) + shell.call("%s submodule update" % GIT, git_dir, fail=fail) + if src_dir: + for c in config_array: + if c[0].startswith('submodule.') and c[0].endswith('.url'): + shell.call("%s config --file=.gitmodules %s %s" % + (GIT, c[0], c[1]), git_dir) + shell.call("%s submodule sync" % GIT, git_dir) def checkout(git_dir, commit): ''' @@ -156,10 +186,9 @@ def local_checkout(git_dir, local_git_dir, commit): shell.call('%s branch %s' % (GIT, branch_name), local_git_dir, fail=False) shell.call('%s checkout %s' % (GIT, branch_name), local_git_dir) shell.call('%s reset --hard %s' % (GIT, commit), local_git_dir) - return shell.call('%s clone %s -s -b %s .' % (GIT, local_git_dir, - branch_name), - git_dir) - + shell.call('%s clone %s -s -b %s .' % (GIT, local_git_dir, branch_name), + git_dir) + submodules_update(git_dir, local_git_dir) def add_remote(git_dir, name, url): ''' |