From 50003c9dd3deb5b2912644723481bdef802e35f7 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 18 Apr 2016 19:48:01 +0000 Subject: Make `morph list-artifacts` work from definitions checkout Change-Id: I711953b829c786911c46e413d2b7af3427b7ba26 --- morphlib/plugins/list_artifacts_plugin.py | 40 +++++++++++++++++++++++++------ yarns/implementations.yarn | 6 +++-- yarns/noncore-plugins.yarn | 3 ++- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/morphlib/plugins/list_artifacts_plugin.py b/morphlib/plugins/list_artifacts_plugin.py index 2c098c2a..9e09e2b9 100644 --- a/morphlib/plugins/list_artifacts_plugin.py +++ b/morphlib/plugins/list_artifacts_plugin.py @@ -17,6 +17,7 @@ # See: for more information. from __future__ import print_function +import uuid import cliapp import morphlib @@ -27,7 +28,7 @@ class ListArtifactsPlugin(cliapp.Plugin): def enable(self): self.app.add_subcommand( 'list-artifacts', self.list_artifacts, - arg_synopsis='REPO REF MORPH [MORPH]...') + arg_synopsis='MORPH [MORPH]...') def disable(self): pass @@ -37,8 +38,6 @@ class ListArtifactsPlugin(cliapp.Plugin): Command line arguments: - * `REPO` is a git repository URL. - * `REF` is a branch or other commit reference in that repository. * `MORPH` is a system morphology name at that ref. You can pass multiple values for `MORPH`, in which case the command @@ -49,14 +48,41 @@ class ListArtifactsPlugin(cliapp.Plugin): ''' - if len(args) < 3: + MINARGS = 1 + + if len(args) < MINARGS: raise cliapp.AppException( 'Wrong number of arguments to list-artifacts command ' '(see help)') - repo, ref = args[0], args[1] - system_filenames = map(morphlib.util.sanitise_morphology_path, - args[2:]) + definitions_repo = morphlib.definitions_repo.open( + '.', search_for_root=True, app=self.app) + + system_filenames = [] + for arg in args: + filename = morphlib.util.sanitise_morphology_path(arg) + filename = definitions_repo.relative_path(filename, cwd='.') + system_filenames.append(filename) + + if self.app.settings['local-changes'] == 'include': + # Create a temporary branch with any local changes, and push it to + # the shared Git server. This is a convenience for developers, who + # otherwise need to commit and push each change manually in order + # for distbuild to see it. It renders the build unreproducible, as + # the branch is deleted after being built, so this feature should + # only be used during development! + build_uuid = uuid.uuid4().hex + branch = definitions_repo.branch_with_local_changes( + build_uuid, push=True) + with branch as (repo_url, commit, original_ref): + self._list_artifacts(repo_url, commit, system_filenames) + else: + ref = definitions_repo.HEAD + commit = definitions_repo.resolve_ref_to_commit(ref) + self._list_artifacts(definitions_repo.remote_url, commit, + system_filenames) + + def _list_artifacts(self, repo, ref, system_filenames): self.repo_cache = morphlib.util.new_repo_cache(self.app) self.resolver = morphlib.artifactresolver.ArtifactResolver() diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index eab162b3..705ff14f 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -637,8 +637,10 @@ Implementations for `morph certify` Implementations for `morph list-artifacts` ------------------------------------------ - IMPLEMENTS WHEN the user lists the artifacts which make up the system (\S+) at ref (\S+) in repository (\S+) - attempt_morph list-artifacts "$MATCH_3" "$MATCH_2" "$MATCH_1" + IMPLEMENTS WHEN the user lists the artifacts which make up the system (\S+) at ref (\S+) + cd "$DATADIR/definitions" + git checkout "$MATCH_2" + attempt_morph list-artifacts "$MATCH_1" Implementation sections for building ==================================== diff --git a/yarns/noncore-plugins.yarn b/yarns/noncore-plugins.yarn index d7f532da..0783cda5 100644 --- a/yarns/noncore-plugins.yarn +++ b/yarns/noncore-plugins.yarn @@ -210,7 +210,8 @@ artifact in a system. This name includes the cache key of the artifact. SCENARIO using morph list-artifacts GIVEN a git server - WHEN the user lists the artifacts which make up the system systems/test-system.morph at ref HEAD in repository test:definitions + WHEN the user clones definitions + AND the user lists the artifacts which make up the system systems/test-system.morph at ref HEAD THEN morph succeeded FINALLY the git server is shut down -- cgit v1.2.1