Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/buildstream/_artifactelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ def _load_artifact(self, *, pull, strict=None): # pylint: disable=useless-super
# Always operate in strict mode as artifact key has been specified explicitly.
return super()._load_artifact(pull=pull, strict=True)

# An ArtifactElement is identified by its artifact name (which includes
# its cache key) rather than by its element name, since it may not even
# belong to a loaded project. Cache key is not yet known
# when this is first called from Plugin.__init__(), before our own
# __init__() has had a chance to set it via artifact_key.
def _get_full_name(self):
if self._get_cache_key() is None:
return super()._get_full_name()
return self.get_artifact_name()

# Once we've finished loading an artifact, we assume the
# state of the loaded artifact. This is also used if the
# artifact is loaded after pulling.
Expand Down
7 changes: 2 additions & 5 deletions src/buildstream/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def artifact_log(self, targets):
self._context.messenger.warn("{} is cached without log files".format(ref))
continue

artifact_logs[obj.name] = obj._get_logs()
artifact_logs[obj._get_full_name()] = obj._get_logs()

return artifact_logs

Expand All @@ -869,15 +869,12 @@ def artifact_list_contents(self, targets):
ref = obj.get_artifact_name()
if not obj._cached():
self._context.messenger.warn("{} is not cached".format(ref))
obj.name = {ref: "No artifact cached"}
continue
if isinstance(obj, ArtifactElement):
obj.name = ref

# Just hand over a Directory here
artifact = obj._get_artifact()
files = artifact.get_files()
elements_to_files[obj.name] = files
elements_to_files[obj._get_full_name()] = files

return elements_to_files

Expand Down
38 changes: 38 additions & 0 deletions tests/frontend/artifact_list_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@
from buildstream._testing import cli # pylint: disable=unused-import
from buildstream.exceptions import ErrorDomain

from tests.testutils import generate_junction

# Project directory
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"artifact_list_contents",
)

# Shared project directory, used for cross junction tests since it already
# has a subproject set up
CROSS_JUNCTION_DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"project",
)


def prepare_symlink(project):
# Create the link before running the tests.
Expand Down Expand Up @@ -158,3 +167,32 @@ def test_artifact_list_exact_contents_glob(cli, datafiles):

for artifact in expected_artifacts:
assert artifact in result.output


@pytest.mark.datafiles(CROSS_JUNCTION_DATA_DIR)
def test_artifact_list_contents_cross_junction(cli, tmpdir, datafiles):
project = str(datafiles)
subproject_path = os.path.join(project, "files", "sub-project")
junction_path = os.path.join(project, "elements", "junction.bst")

# Create a repo to hold the subproject and generate a junction element for it
generate_junction(tmpdir, subproject_path, junction_path)

# Ensure we have artifacts to read
result = cli.run(project=project, args=["build", "import-bin.bst", "junction.bst:import-etc.bst"])
result.assert_success()

# List the contents of the cross junction element, alongside a regular
# top-level element which happens to share a basename with it.
result = cli.run(
project=project, args=["artifact", "list-contents", "import-bin.bst", "junction.bst:import-etc.bst"]
)
result.assert_success()

# The full element name, including the owning junction prefix, must be
# used as the header for the cross junction element's contents -- using
# only the bare element name would make it indistinguishable from an
# element of the same name in the top level project or another junction.
assert "import-bin.bst:\n" in result.output
assert "junction.bst:import-etc.bst:\n" in result.output
assert "etc/animal.conf" in result.output
32 changes: 32 additions & 0 deletions tests/frontend/artifact_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from buildstream._testing import cli # pylint: disable=unused-import

from tests.testutils import generate_junction

# Project directory
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
Expand Down Expand Up @@ -101,3 +103,33 @@ def test_artifact_log_files(cli, datafiles):
with open(import_bin, "r", encoding="utf-8") as f:
data = f.read()
assert len(re.findall(pattern, data, re.MULTILINE)) > 0


@pytest.mark.datafiles(DATA_DIR)
def test_artifact_log_cross_junction(cli, tmpdir, datafiles):
project = str(datafiles)
subproject_path = os.path.join(project, "files", "sub-project")
junction_path = os.path.join(project, "elements", "junction.bst")

# Create a repo to hold the subproject and generate a junction element for it
generate_junction(tmpdir, subproject_path, junction_path)

# Ensure we have an artifact to read, alongside a regular top-level
# element which happens to share a basename with it.
result = cli.run(project=project, args=["build", "import-bin.bst", "junction.bst:import-etc.bst"])
result.assert_success()

logfiles = os.path.join(project, "logfiles")

result = cli.run(
project=project,
args=["artifact", "log", "--out", logfiles, "import-bin.bst", "junction.bst:import-etc.bst"],
)
result.assert_success()

# The log file for the cross junction element must be named using the
# full element name, including the owning junction prefix, and not just
# the bare element name -- otherwise it would collide with the log file
# of a same-named element in the top level project or another junction.
assert os.path.exists(os.path.join(logfiles, "import-bin.log"))
assert os.path.exists(os.path.join(logfiles, "junction.bst:import-etc.log"))