diff options
author | James Ennis <james.ennis@codethink.co.uk> | 2019-08-13 17:49:01 +0100 |
---|---|---|
committer | James Ennis <james.ennis@codethink.co.uk> | 2019-08-22 16:26:52 +0100 |
commit | e0c3c284b7ad0400d82b6e345b694f41c899f39a (patch) | |
tree | d3a8304dc1d77c2cb01aae8cc2d79b5d83abf835 | |
parent | fcadd6b5cf3e2eee88f925e2bd4ce9726e2eebf5 (diff) | |
download | buildstream-e0c3c284b7ad0400d82b6e345b694f41c899f39a.tar.gz |
_artifact.py: Add get_dependency_refs() method
-rw-r--r-- | src/buildstream/_artifact.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/buildstream/_artifact.py b/src/buildstream/_artifact.py index 05d025427..4aef1d7cf 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,47 @@ 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): + 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 |