summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.com>2019-01-24 14:12:42 +0000
committerJames Ennis <james.ennis@codethink.com>2019-02-13 09:35:45 +0000
commit6ae41474c175c454f850ac1ccdbfe663d60214bf (patch)
tree5618cc5bf3d3148a3560f2b6f72fc8aea4b8ac19
parent491937d7aad3f6a35779327d06135537c7622e0e (diff)
downloadbuildstream-jennis/refactor_artifact_log.tar.gz
_stream.py: _classify_artifacts() should be able to handle globsjennis/refactor_artifact_log
_classify_artifacts() no longer filters glob expressions by first obtaining a list of ALL refs locally cached. We now only obtain refs specified by the glob expression. Furthermore, the Project.element_path is used to start searching for globbed elements as opposed to the Project.directory.
-rw-r--r--buildstream/_stream.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index 6e97aeccd..caaa48908 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -954,13 +954,8 @@ class Stream():
dynamic_plan=False,
load_refs=False):
- # Obtain cached refs and project element path needed to classify artifacts
- cas = self._artifacts.cas
- cached_refs = cas.list_refs()
- project_element_path = self._project.element_path
-
# Classify element and artifact strings
- target_elements, target_artifacts = self._classify_artifacts(targets, cached_refs, project_element_path)
+ target_elements, target_artifacts = self._classify_artifacts(targets)
if target_artifacts and not load_refs:
detail = '\n'.join(target_artifacts)
@@ -1383,14 +1378,12 @@ class Stream():
#
# Args:
# targets (list): A list of targets
- # cached (list): A list of locally cached refs
- # project_element_path (str): Absolute path to where the elements exist in the project
#
# Returns:
# (list): element names present in the targets
# (list): artifact refs present in the targets
#
- def _classify_artifacts(self, targets, cached, project_element_path):
+ def _classify_artifacts(self, targets):
element_targets = []
artifact_refs = []
element_globs = []
@@ -1414,14 +1407,19 @@ class Stream():
artifact_refs.append(target)
if element_globs:
- for dirpath, _, filenames in os.walk(project_element_path):
+ for dirpath, _, filenames in os.walk(self._project.element_path):
for filename in filenames:
- element_path = os.path.join(dirpath, filename).lstrip(project_element_path).lstrip('/')
+ element_path = os.path.join(dirpath, filename)
+ length = len(self._project.element_path) + 1
+ element_path = element_path[length:] # Strip out the element_path
+
if any(fnmatch(element_path, glob) for glob in element_globs):
element_targets.append(element_path)
if artifact_globs:
- artifact_refs.extend(ref for ref in cached
- if any(fnmatch(ref, glob) for glob in artifact_globs))
+ for glob in artifact_globs:
+ artifact_refs.extend(self._artifacts.list_artifacts(glob=glob))
+ if not artifact_refs:
+ self._message(MessageType.WARN, "No artifacts found for globs: {}".format(', '.join(artifact_globs)))
return element_targets, artifact_refs