summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-18 17:08:53 +0100
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-06-22 13:12:37 +0000
commitb18764f144983dfb9aa892892084af1daeb9100d (patch)
treea9529d65053b918451b79c66f17c9f59137605b3
parent26dce1d6ef83294c184fc513232130dbbd8f19dc (diff)
downloadmorph-b18764f144983dfb9aa892892084af1daeb9100d.tar.gz
Make more commands work outside a system-branch/workspace
This makes `morph get-chunk-details`, `morph get-repo` and `morph show-build-log` work in any Git checkout of definitions.git. These are all of the commands outside of the deprecated branch_and_merge_plugin that take notice of system branches. The DefinitionsRepo.relative_path_to_chunk() function is changed a bit. It actually only existed for the `get-repo` command to use, but it turns out that it did the wrong thing by returning a long path for the repo (e.g. baserock/baserock/fhs-dirs) instead of a short one (fhs-dirs). The latter is less typing, and is the behaviour expected by the `get-repo` yarn tests, so it now does that. Change-Id: I430b540b3b0f309cf7018e0b8236f0e8a9042d89
-rw-r--r--morphlib/definitions_repo.py18
-rw-r--r--morphlib/plugins/get_chunk_details_plugin.py5
-rw-r--r--morphlib/plugins/get_repo_plugin.py17
-rw-r--r--morphlib/plugins/show_build_log_plugin.py88
4 files changed, 61 insertions, 67 deletions
diff --git a/morphlib/definitions_repo.py b/morphlib/definitions_repo.py
index 24b88a7e..c1381af6 100644
--- a/morphlib/definitions_repo.py
+++ b/morphlib/definitions_repo.py
@@ -267,24 +267,16 @@ class DefinitionsRepo(gitdir.GitDirectory):
repo, with its name based on 'repo_url'.
'''
- # This is copied from systembranch._fabricate_git_directory_name().
-
# Parse the URL. If the path component is absolute, we assume
# it's a real URL; otherwise, an aliased URL.
parts = urlparse.urlparse(repo_url)
- if os.path.isabs(parts.path):
- # Remove .git suffix, if any.
- path = parts.path
- if path.endswith('.git'):
- path = path[:-len('.git')]
+ # Remove .git suffix, if any.
+ path = parts.path
+ if path.endswith('.git'):
+ path = path[:-len('.git')]
- # Add the domain name etc (netloc). Ignore any other parts.
- # Note that we _know_ the path starts with a slash, so we avoid
- # adding one here.
- relative = '%s%s' % (parts.netloc, path)
- else:
- relative = repo_url
+ relative = os.path.basename(parts.path)
# Replace colons with slashes.
relative = '/'.join(relative.split(':'))
diff --git a/morphlib/plugins/get_chunk_details_plugin.py b/morphlib/plugins/get_chunk_details_plugin.py
index 842b4afe..e58ed6c5 100644
--- a/morphlib/plugins/get_chunk_details_plugin.py
+++ b/morphlib/plugins/get_chunk_details_plugin.py
@@ -47,14 +47,15 @@ class GetChunkDetailsPlugin(cliapp.Plugin):
'Wrong number of arguments to get-chunk-details command '
'(see help)')
- sb = morphlib.sysbranchdir.open_from_within('.')
+ definitions_repo = morphlib.definitions_repo.open(
+ '.', search_for_root=True, search_workspace=True, app=self.app)
loader = morphlib.morphloader.MorphologyLoader()
aliases = self.app.settings['repo-alias']
self.resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases)
found = 0
- for morph in sb.load_all_morphologies(loader):
+ for morph in definitions_repo.load_all_morphologies(loader):
if morph['kind'] == 'stratum':
if (stratum_name == None or
morph['name'] == stratum_name):
diff --git a/morphlib/plugins/get_repo_plugin.py b/morphlib/plugins/get_repo_plugin.py
index 5701de97..38039406 100644
--- a/morphlib/plugins/get_repo_plugin.py
+++ b/morphlib/plugins/get_repo_plugin.py
@@ -60,11 +60,11 @@ class GetRepoPlugin(cliapp.Plugin):
gd.update_submodules(self.app)
gd.update_remotes()
- def _get_chunk_dirname(self, path, sb, spec):
+ def _get_chunk_dirname(self, path, definitions_repo, spec):
if path:
return path
else:
- return sb.get_git_directory_name(spec['repo'])
+ return definitions_repo.relative_path_to_chunk(spec['repo'])
def get_repo(self, args):
'''Checkout a component repository.
@@ -92,12 +92,9 @@ class GetRepoPlugin(cliapp.Plugin):
path = os.path.abspath(args[1])
ref = self.app.settings['ref']
- ws = morphlib.workspace.open('.')
- sb = morphlib.sysbranchdir.open_from_within('.')
- loader = morphlib.morphloader.MorphologyLoader()
-
def checkout_chunk(morph, chunk_spec):
- dirname = self._get_chunk_dirname(path, sb, chunk_spec)
+ dirname = self._get_chunk_dirname(path, definitions_repo,
+ chunk_spec)
if not os.path.exists(dirname):
self.app.status(
msg='Checking out ref %(ref)s of %(chunk)s in '
@@ -123,8 +120,12 @@ class GetRepoPlugin(cliapp.Plugin):
strata = set()
found = 0
+ definitions_repo = morphlib.definitions_repo.open(
+ '.', search_for_root=True, search_workspace=True, app=self.app)
+ loader = morphlib.morphloader.MorphologyLoader()
+
self.app.status(msg='Loading in all morphologies')
- for morph in sb.load_all_morphologies(loader):
+ for morph in definitions_repo.load_all_morphologies(loader):
if morph['kind'] == 'stratum':
for chunk in morph['chunks']:
if chunk['name'] == chunk_name:
diff --git a/morphlib/plugins/show_build_log_plugin.py b/morphlib/plugins/show_build_log_plugin.py
index 38b62540..98509841 100644
--- a/morphlib/plugins/show_build_log_plugin.py
+++ b/morphlib/plugins/show_build_log_plugin.py
@@ -48,10 +48,6 @@ class ShowBuildLog(cliapp.Plugin):
raise cliapp.AppException('show-build-log expects system filename '
'and chunk as input.')
- artifact_cache_server = (
- self.app.settings['artifact-cache-server'] or
- self.app.settings['cache-server'])
-
system = args[0]
chunk = args[1]
@@ -61,45 +57,49 @@ class ShowBuildLog(cliapp.Plugin):
pass
morphlib.buildcommand.BuildCommand._validate_architecture = validate
- sb = morphlib.sysbranchdir.open_from_within('.')
- root_repo_url = sb.get_config('branch.root')
- ref = sb.get_config('branch.name')
-
- definitions_repo_path = sb.get_git_directory_name(root_repo_url)
-
- build_command = morphlib.buildcommand.BuildCommand(self.app, None)
- srcpool = build_command.create_source_pool(definitions_repo_path, ref,
- [system])
- root = build_command.resolve_artifacts(srcpool)
-
- arch = root.source.morphology['arch']
- build_env = build_command.new_build_env(arch)
-
- ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
-
- cache_key = None
- for source in set(a.source for a in root.walk()):
- if source.name == chunk:
- cache_key = ckc.compute_key(source)
- break
-
- if cache_key:
- url = urlparse.urljoin(artifact_cache_server,
- '/1.0/artifacts?filename=%s.build-log' % source.cache_key)
- response = urllib.urlopen(url)
- if response.getcode() == 200:
- build_output = []
- for line in response:
- build_output.append(str(line))
- self.app.output.write(''.join(build_output))
- elif response.getcode() == 404:
- raise cliapp.AppException(
- 'No build log for artifact %s found on cache server %s' %
- (source.cache_key, artifact_cache_server))
+ definitions_repo = morphlib.definitions_repo.open(
+ '.', search_for_root=True, search_workspace=True, app=self.app)
+ source_pool_context = definitions_repo.source_pool(
+ ref=definitions_repo.HEAD, system_filename=system)
+ with source_pool_context as source_pool:
+ build_command = morphlib.buildcommand.BuildCommand(self.app, None)
+ root = build_command.resolve_artifacts(source_pool)
+
+ arch = root.source.morphology['arch']
+ build_env = build_command.new_build_env(arch)
+
+ ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
+
+ cache_key = None
+ for source in set(a.source for a in root.walk()):
+ if source.name == chunk:
+ cache_key = ckc.compute_key(source)
+ break
+
+ if cache_key:
+ self.show_build_log_for_artifact(cache_key)
else:
- raise cliapp.AppException(
- 'Error connecting to cache server %s: %s' %
- (artifact_cache_server, response.getcode()))
+ raise cliapp.AppException('Component not found in the given '
+ 'system.')
+
+ def show_build_log_for_artifact(self, cache_key):
+ artifact_cache_server = (
+ self.app.settings['artifact-cache-server'] or
+ self.app.settings['cache-server'])
+
+ url = urlparse.urljoin(artifact_cache_server,
+ '/1.0/artifacts?filename=%s.build-log' % cache_key)
+ response = urllib.urlopen(url)
+ if response.getcode() == 200:
+ build_output = []
+ for line in response:
+ build_output.append(str(line))
+ self.app.output.write(''.join(build_output))
+ elif response.getcode() == 404:
+ raise cliapp.AppException(
+ 'No build log for artifact %s found on cache server %s' %
+ (cache_key, artifact_cache_server))
else:
- raise cliapp.AppException('Component not found in the given '
- 'system.')
+ raise cliapp.AppException(
+ 'Error connecting to cache server %s: %s' %
+ (artifact_cache_server, response.getcode()))