summaryrefslogtreecommitdiff
path: root/buildstream/testing/runcli.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildstream/testing/runcli.py')
-rw-r--r--buildstream/testing/runcli.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/buildstream/testing/runcli.py b/buildstream/testing/runcli.py
index 934c31236..8b3185143 100644
--- a/buildstream/testing/runcli.py
+++ b/buildstream/testing/runcli.py
@@ -53,9 +53,11 @@ from _pytest.capture import MultiCapture, FDCapture, FDCaptureBinary
from buildstream._frontend import cli as bst_cli
from buildstream import _yaml
from buildstream._cas import CASCache
+from buildstream.element import _get_normal_name, _compose_artifact_name
# Special private exception accessor, for test case purposes
from buildstream._exceptions import BstError, get_last_exception, get_last_task_error
+from buildstream._protos.buildstream.v2 import artifact_pb2
# Wrapper for the click.testing result
@@ -495,6 +497,17 @@ class Cli():
result.assert_success()
return result.output.splitlines()
+ # Fetch an element's complete artifact name, cache_key will be generated
+ # if not given.
+ #
+ def get_artifact_name(self, project, project_name, element_name, cache_key=None):
+ if not cache_key:
+ cache_key = self.get_element_key(project, element_name)
+
+ # Replace path separator and chop off the .bst suffix for normal name
+ normal_name = _get_normal_name(element_name)
+ return _compose_artifact_name(project_name, normal_name, cache_key)
+
class CliIntegration(Cli):
@@ -636,7 +649,8 @@ class TestArtifact():
#
def remove_artifact_from_cache(self, cache_dir, element_name):
- cache_dir = os.path.join(cache_dir, 'cas', 'refs', 'heads')
+ cache_dir = os.path.join(cache_dir, 'artifacts', 'refs')
+
normal_name = element_name.replace(os.sep, '-')
cache_dir = os.path.splitext(os.path.join(cache_dir, 'test', normal_name))[0]
shutil.rmtree(cache_dir)
@@ -655,13 +669,13 @@ class TestArtifact():
#
def is_cached(self, cache_dir, element, element_key):
- cas = CASCache(str(cache_dir))
+ # cas = CASCache(str(cache_dir))
artifact_ref = element.get_artifact_name(element_key)
- return cas.contains(artifact_ref)
+ return os.path.exists(os.path.join(cache_dir, 'artifacts', 'refs', artifact_ref))
# get_digest():
#
- # Get the digest for a given element's artifact
+ # Get the digest for a given element's artifact files
#
# Args:
# cache_dir (str): Specific cache dir to check
@@ -673,10 +687,12 @@ class TestArtifact():
#
def get_digest(self, cache_dir, element, element_key):
- cas = CASCache(str(cache_dir))
artifact_ref = element.get_artifact_name(element_key)
- digest = cas.resolve_ref(artifact_ref)
- return digest
+ artifact_dir = os.path.join(cache_dir, 'artifacts', 'refs')
+ artifact_proto = artifact_pb2.Artifact()
+ with open(os.path.join(artifact_dir, artifact_ref), 'rb') as f:
+ artifact_proto.ParseFromString(f.read())
+ return artifact_proto.files
# extract_buildtree():
#
@@ -691,9 +707,19 @@ class TestArtifact():
# (str): path to extracted buildtree directory, does not guarantee
# existence.
@contextmanager
- def extract_buildtree(self, tmpdir, digest):
- with self._extract_subdirectory(tmpdir, digest, 'buildtree') as extract:
- yield extract
+ def extract_buildtree(self, cache_dir, tmpdir, ref):
+ artifact = artifact_pb2.Artifact()
+ try:
+ with open(os.path.join(cache_dir, 'artifacts', 'refs', ref), 'rb') as f:
+ artifact.ParseFromString(f.read())
+ except FileNotFoundError:
+ yield None
+ else:
+ if str(artifact.buildtree):
+ with self._extract_subdirectory(tmpdir, artifact.buildtree) as f:
+ yield f
+ else:
+ yield None
# _extract_subdirectory():
#
@@ -709,12 +735,12 @@ class TestArtifact():
# (str): path to extracted subdir directory, does not guarantee
# existence.
@contextmanager
- def _extract_subdirectory(self, tmpdir, digest, subdir):
+ def _extract_subdirectory(self, tmpdir, digest):
with tempfile.TemporaryDirectory() as extractdir:
try:
cas = CASCache(str(tmpdir))
cas.checkout(extractdir, digest)
- yield os.path.join(extractdir, subdir)
+ yield extractdir
except FileNotFoundError:
yield None