summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-08-13 17:49:01 +0100
committerJames Ennis <james.ennis@codethink.co.uk>2019-08-27 12:12:13 +0100
commita6d252963a53da0395379927aa06eb3e0f3c9741 (patch)
treea3c0bbc41d9bb0a4420e3323542e2a79641d2f48
parentaf03e3edc2cf7159bf5865a95f101d2fd890cc84 (diff)
downloadbuildstream-a6d252963a53da0395379927aa06eb3e0f3c9741.tar.gz
_artifact.py: Add get_dependency_refs() method
-rw-r--r--src/buildstream/_artifact.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/buildstream/_artifact.py b/src/buildstream/_artifact.py
index 05d025427..1e3e39b8f 100644
--- a/src/buildstream/_artifact.py
+++ b/src/buildstream/_artifact.py
@@ -30,6 +30,7 @@ artifact composite interaction away from Element class
import os
+from ._exceptions import ArtifactError
from ._protos.buildstream.v2.artifact_pb2 import Artifact as ArtifactProto
from . import _yaml
from . import utils
@@ -349,6 +350,49 @@ class Artifact():
return self._metadata_workspaced_dependencies
+ # get_dependency_refs()
+ #
+ # Retrieve the artifact refs of the artifact's dependencies
+ #
+ # Args:
+ # deps (Scope): The scope of dependencies
+ #
+ # Returns:
+ # (list [str]): A list of refs of all build dependencies in staging order.
+ #
+ def get_dependency_refs(self, deps=Scope.BUILD):
+ # XXX: The pylint disable is necessary due to upstream issue:
+ # https://github.com/PyCQA/pylint/issues/850
+ from .element import _get_normal_name # pylint: disable=cyclic-import
+
+ # Extract the proto
+ artifact = self._get_proto()
+
+ if deps == Scope.BUILD:
+ try:
+ dependency_refs = [
+ os.path.join(dep.project_name, _get_normal_name(dep.element_name), dep.cache_key)
+ for dep in artifact.build_deps
+ ]
+ except AttributeError:
+ # If the artifact has no dependencies
+ dependency_refs = []
+ elif deps == Scope.NONE:
+ dependency_refs = [self._element.get_artifact_name()]
+ else:
+ # XXX: We can only support obtaining the build dependencies of
+ # an artifact. This is because this is the only information we store
+ # in the proto. If we were to add runtime deps to the proto, we'd need
+ # to include these in cache key calculation.
+ #
+ # This would have some undesirable side effects:
+ # 1. It might trigger unnecessary rebuilds.
+ # 2. It would be impossible to support cyclic runtime dependencies
+ # in the future
+ raise ArtifactError("Dependency scope: {} is not supported for artifacts".format(deps))
+
+ return dependency_refs
+
# cached():
#
# Check whether the artifact corresponding to the stored cache key is