diff options
Diffstat (limited to 'meta/lib/bblayers/makesetup.py')
-rw-r--r-- | meta/lib/bblayers/makesetup.py | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/meta/lib/bblayers/makesetup.py b/meta/lib/bblayers/makesetup.py index 22f89d81a4..4199b5f069 100644 --- a/meta/lib/bblayers/makesetup.py +++ b/meta/lib/bblayers/makesetup.py @@ -6,12 +6,9 @@ import logging import os -import stat import sys -import shutil import bb.utils -import bb.process from bblayers.common import LayerPlugin @@ -26,50 +23,46 @@ def plugin_init(plugins): class MakeSetupPlugin(LayerPlugin): - def _get_repo_path(self, layer_path): - repo_path, _ = bb.process.run('git rev-parse --show-toplevel', cwd=layer_path) - return repo_path.strip() - - def _get_remotes(self, repo_path): + def _get_remotes_with_url(self, repo_path): remotes = {} - remotes_list,_ = bb.process.run('git remote', cwd=repo_path) - for r in remotes_list.split(): - uri,_ = bb.process.run('git remote get-url {r}'.format(r=r), cwd=repo_path) - remotes[r] = {'uri':uri.strip()} + for r in oe.buildcfg.get_metadata_git_remotes(repo_path): + remotes[r] = {'uri':oe.buildcfg.get_metadata_git_remote_url(repo_path, r)} return remotes - def _get_describe(self, repo_path): - try: - describe,_ = bb.process.run('git describe --tags', cwd=repo_path) - except bb.process.ExecutionError: - return "" - return describe.strip() + def _is_submodule(self, repo_path): + # This is slightly brittle: git does not offer a way to tell whether + # a given repo dir is a submodule checkout, so we need to rely on .git + # being a file (rather than a dir like it is in standalone checkouts). + # The file typically contains a gitdir pointer to elsewhere. + return os.path.isfile(os.path.join(repo_path,".git")) def make_repo_config(self, destdir): - """ This is a helper function for the writer plugins that discovers currently confugured layers. + """ This is a helper function for the writer plugins that discovers currently configured layers. The writers do not have to use it, but it can save a bit of work and avoid duplicated code, hence it is available here. """ repos = {} layers = oe.buildcfg.get_layer_revisions(self.tinfoil.config_data) - try: - destdir_repo = self._get_repo_path(destdir) - except bb.process.ExecutionError: - destdir_repo = None + destdir_repo = oe.buildcfg.get_metadata_git_toplevel(destdir) for (l_path, l_name, l_branch, l_rev, l_ismodified) in layers: if l_name == 'workspace': continue if l_ismodified: - logger.error("Layer {name} in {path} has uncommitted modifications or is not in a git repository.".format(name=l_name,path=l_path)) - return - repo_path = self._get_repo_path(l_path) + e = "Layer {name} in {path} has uncommitted modifications or is not in a git repository.".format(name=l_name,path=l_path) + logger.error(e) + raise Exception(e) + repo_path = oe.buildcfg.get_metadata_git_toplevel(l_path) + + if self._is_submodule(repo_path): + continue if repo_path not in repos.keys(): - repos[repo_path] = {'path':os.path.basename(repo_path),'git-remote':{'rev':l_rev, 'branch':l_branch, 'remotes':self._get_remotes(repo_path), 'describe':self._get_describe(repo_path)}} + repos[repo_path] = {'path':os.path.basename(repo_path),'git-remote':{ + 'rev':l_rev, + 'branch':l_branch, + 'remotes':self._get_remotes_with_url(repo_path), + 'describe':oe.buildcfg.get_metadata_git_describe(repo_path)}} if repo_path == destdir_repo: repos[repo_path]['contains_this_file'] = True - if not repos[repo_path]['git-remote']['remotes'] and not repos[repo_path]['contains_this_file']: - logger.error("Layer repository in {path} does not have any remotes configured. Please add at least one with 'git remote add'.".format(path=repo_path)) - return top_path = os.path.commonpath([os.path.dirname(r) for r in repos.keys()]) @@ -79,6 +72,7 @@ class MakeSetupPlugin(LayerPlugin): repos_nopaths[r_nopath] = repos[r] r_relpath = os.path.relpath(r, top_path) repos_nopaths[r_nopath]['path'] = r_relpath + repos_nopaths[r_nopath]['originpath'] = r return repos_nopaths def do_make_setup(self, args): |