summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.com>2019-01-17 17:44:18 +0000
committerJames Ennis <james.ennis@codethink.com>2019-02-13 09:35:45 +0000
commitbf1933b60c511fc88afdce11f0c69c4eb657ec4b (patch)
tree0408c0b42aae5bdfd524f973780d78beab97e9f6
parent6951cfc8554043d5669ea927f7b5dd637467c6ac (diff)
downloadbuildstream-bf1933b60c511fc88afdce11f0c69c4eb657ec4b.tar.gz
_stream.py: Add the _classify_artifacts() helper
-rw-r--r--buildstream/_stream.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index 588780558..07eb44208 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -27,6 +27,7 @@ import shutil
import tarfile
import tempfile
from contextlib import contextmanager, suppress
+from fnmatch import fnmatch
from ._exceptions import StreamError, ImplError, BstError, set_last_task_error
from ._message import Message, MessageType
@@ -1331,3 +1332,47 @@ class Stream():
required_list.append(element)
return required_list
+
+ # _classify_artifacts()
+ #
+ # Split up a list of tagets into element names and artifact refs
+ #
+ # Args:
+ # names (list): A list of targets
+ # cas (CASCache): The CASCache object
+ # project_directory (str): Absolute path to the project
+ #
+ # Returns:
+ # (list): element names present in the targets
+ # (list): artifact refs present in the targets
+ #
+ def _classify_artifacts(names, cas, project_directory):
+ element_targets = []
+ artifact_refs = []
+ element_globs = []
+ artifact_globs = []
+
+ for name in names:
+ if name.endswith('.bst'):
+ if any(c in "*?[" for c in name):
+ element_globs.append(name)
+ else:
+ element_targets.append(name)
+ else:
+ if any(c in "*?[" for c in name):
+ artifact_globs.append(name)
+ else:
+ artifact_refs.append(name)
+
+ if element_globs:
+ for dirpath, _, filenames in os.walk(project_directory):
+ for filename in filenames:
+ element_path = os.path.join(dirpath, filename).lstrip(project_directory).lstrip('/')
+ 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 cas.list_refs()
+ if any(fnmatch(ref, glob) for glob in artifact_globs))
+
+ return element_targets, artifact_refs