summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan van Berkom <tristan@codethink.co.uk>2020-08-30 18:41:48 +0900
committerbst-marge-bot <marge-bot@buildstream.build>2020-08-30 17:25:07 +0000
commitb758505b6f1d82d839cee4b870a7fa5a8ce7422b (patch)
tree9b49ecb988c018e64b88691282edfc11d860cf1a /src
parentfd80d4903eb28845ca9a67d5730254d93dbd0c24 (diff)
downloadbuildstream-b758505b6f1d82d839cee4b870a7fa5a8ce7422b.tar.gz
Remove unused Scope argument from artifact name related APIs.tristan/artifact-dependency-names
Additionally, this reverts terminology back to calling these "artifact names", and not "artifact refs", which is a terminology which crept in from various underlying implementations. Summary of changes: * _artifact.py: - get_dependency_refs() renamed to get_dependency_artifact_names() - get_dependency_artifact_names() loses the Scope argument - Consequently, a huge and needless XXX comment is removed * _artifactelement.py: - _new_from_artifact_ref() renamed to _new_from_artifact_name() - get_dependency_refs() renamed to get_dependency_artifact_names() - get_dependency_artifact_names() loses the Scope argument * _project.py: - Now call _new_from_artifact_name() - Removes a legacy XXX comment which is not particularly relevant * element.py: - __get_dependency_refs() renamed to __get_dependency_artifact_names() - Adapt __get_last_build_artifact() to updated API names.
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/_artifact.py43
-rw-r--r--src/buildstream/_artifactelement.py22
-rw-r--r--src/buildstream/_project.py9
-rw-r--r--src/buildstream/element.py15
4 files changed, 28 insertions, 61 deletions
diff --git a/src/buildstream/_artifact.py b/src/buildstream/_artifact.py
index ac33f041c..f74f3f9ff 100644
--- a/src/buildstream/_artifact.py
+++ b/src/buildstream/_artifact.py
@@ -30,7 +30,6 @@ 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
@@ -362,46 +361,28 @@ class Artifact:
return self._metadata_workspaced_dependencies
- # get_dependency_refs()
+ # get_dependency_artifact_names()
#
- # Retrieve the artifact refs of the artifact's dependencies
- #
- # Args:
- # deps (Scope): The scope of dependencies
+ # Retrieve the artifact names of all of the dependencies in Scope.BUILD
#
# Returns:
# (list [str]): A list of refs of all build dependencies in staging order.
#
- def get_dependency_refs(self, deps=Scope.BUILD):
+ def get_dependency_artifact_names(self):
# 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))
+ 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, the build_deps attribute
+ # will be missing from the proto.
+ dependency_refs = []
return dependency_refs
diff --git a/src/buildstream/_artifactelement.py b/src/buildstream/_artifactelement.py
index 44e52ea90..53a1ff72f 100644
--- a/src/buildstream/_artifactelement.py
+++ b/src/buildstream/_artifactelement.py
@@ -24,7 +24,6 @@ from . import _cachekey
from ._exceptions import ArtifactElementError
from ._loader import LoadElement
from .node import Node
-from .types import Scope
if TYPE_CHECKING:
from typing import Dict
@@ -54,10 +53,10 @@ class ArtifactElement(Element):
super().__init__(context, project, load_element, None)
- # _new_from_artifact_ref():
+ # _new_from_artifact_name():
#
# Recursively instantiate a new ArtifactElement instance, and its
- # dependencies from an artifact ref
+ # dependencies from an artifact name
#
# Args:
# ref (String): The artifact ref
@@ -68,7 +67,7 @@ class ArtifactElement(Element):
# (ArtifactElement): A newly created Element instance
#
@classmethod
- def _new_from_artifact_ref(cls, ref, context, task=None):
+ def _new_from_artifact_name(cls, ref, context, task=None):
if ref in cls.__instantiated_artifacts:
return cls.__instantiated_artifacts[ref]
@@ -79,8 +78,8 @@ class ArtifactElement(Element):
artifact_element._initialize_state()
cls.__instantiated_artifacts[ref] = artifact_element
- for dep_ref in artifact_element.get_dependency_refs(Scope.BUILD):
- dependency = ArtifactElement._new_from_artifact_ref(dep_ref, context, task)
+ for dep_ref in artifact_element.get_dependency_artifact_names():
+ dependency = ArtifactElement._new_from_artifact_name(dep_ref, context, task)
artifact_element._add_build_dependency(dependency)
return artifact_element
@@ -112,19 +111,16 @@ class ArtifactElement(Element):
def preflight(self):
pass
- # get_dependency_refs()
+ # get_dependency_artifact_names()
#
- # Obtain the refs of a particular scope of dependencies
- #
- # Args:
- # scope (Scope): The scope of dependencies for which we want to obtain the refs
+ # Retrieve the artifact names of all of the dependencies in Scope.BUILD
#
# Returns:
# (list [str]): A list of artifact refs
#
- def get_dependency_refs(self, scope=Scope.BUILD):
+ def get_dependency_artifact_names(self):
artifact = self._get_artifact()
- return artifact.get_dependency_refs(deps=scope)
+ return artifact.get_dependency_artifact_names()
# configure_sandbox()
#
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 87772995a..209ba516c 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -467,16 +467,9 @@ class Project:
#
def load_artifacts(self, targets):
with self._context.messenger.simple_task("Loading artifacts") as task:
- # XXX: Here, we are explicitly checking for refs in the artifactdir
- # for two reasons:
- # 1. The Project, or the Context, do not currently have
- # access to the ArtifactCache
- # 2. The ArtifactCache.contains() method expects an Element
- # and a key, not a ref.
- #
artifacts = []
for ref in targets:
- artifacts.append(ArtifactElement._new_from_artifact_ref(ref, self._context, task))
+ artifacts.append(ArtifactElement._new_from_artifact_name(ref, self._context, task))
ArtifactElement._clear_artifact_refs_cache()
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 4995f1f37..4b53aa3dd 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -2259,20 +2259,17 @@ class Element(Plugin):
if redundant_ref is not None:
self.__redundant_source_refs.append((source, redundant_ref))
- # __get_dependency_refs()
+ # __get_dependency_artifact_names()
#
- # Retrieve the artifact refs of the element's dependencies
- #
- # Args:
- # scope (Scope): The scope of dependencies
+ # Retrieve the artifact names of all of the dependencies in Scope.BUILD
#
# Returns:
# (list [str]): A list of refs of all dependencies in staging order.
#
- def __get_dependency_refs(self, scope):
+ def __get_dependency_artifact_names(self):
return [
os.path.join(dep.project_name, _get_normal_name(dep.name), dep._get_cache_key())
- for dep in self.dependencies(scope)
+ for dep in self.dependencies(Scope.BUILD)
]
# __get_last_build_artifact()
@@ -2305,8 +2302,8 @@ class Element(Plugin):
# Don't perform an incremental build if there has been a change in
# build dependencies.
- old_dep_refs = artifact.get_dependency_refs(Scope.BUILD)
- new_dep_refs = self.__get_dependency_refs(Scope.BUILD)
+ old_dep_refs = artifact.get_dependency_artifact_names()
+ new_dep_refs = self.__get_dependency_artifact_names()
if old_dep_refs != new_dep_refs:
return None