From 13bd00da7308097d6b3d95788fcdc345f9166510 Mon Sep 17 00:00:00 2001 From: James Ennis Date: Thu, 8 Aug 2019 12:40:53 +0100 Subject: Frontend: Fix bst artifact log This command now fetches the absolute paths of the log files in the local CAS cache and opens a pager for each path. The test has also been updated to ensure that a log file is actually obtained. --- src/buildstream/_artifact.py | 2 +- src/buildstream/_frontend/cli.py | 26 +++++++------------------- src/buildstream/_stream.py | 6 +++--- tests/frontend/artifact.py | 3 +++ 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/buildstream/_artifact.py b/src/buildstream/_artifact.py index 1512a10a5..ff5bae4a1 100644 --- a/src/buildstream/_artifact.py +++ b/src/buildstream/_artifact.py @@ -401,7 +401,7 @@ class Artifact(): artifact = self._get_proto() for logfile in artifact.logs: - if not self._cas.contains(logfile.digest.hash): + if not self._cas.contains_file(logfile.digest): return False return True diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 81ee4ad83..220d10477 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -1,8 +1,6 @@ import os import sys -from contextlib import ExitStack from functools import partial -from tempfile import TemporaryDirectory import fcntl import click @@ -1196,23 +1194,13 @@ def artifact_log(app, artifacts): # they are not somehow escaped. with app.initialized(): - logsdirs = app.stream.artifact_log(artifacts) - - with ExitStack() as stack: - extractdirs = [] - for logsdir in logsdirs: - # NOTE: If reading the logs feels unresponsive, here would be a good place - # to provide progress information. - td = stack.enter_context(TemporaryDirectory()) - logsdir.export_files(td, can_link=True) - extractdirs.append(td) - - for extractdir in extractdirs: - for log in (os.path.join(extractdir, log) for log in os.listdir(extractdir)): - # NOTE: Should click gain the ability to pass files to the pager this can be optimised. - with open(log) as f: - data = f.read() - click.echo_via_pager(data) + log_file_paths = app.stream.artifact_log(artifacts) + + for log in log_file_paths: + with open(log) as f: + data = f.read() + + click.echo_via_pager(data) ################################################################### diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 410b601b8..36610434b 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -603,7 +603,7 @@ class Stream(): # Return list of Element and/or ArtifactElement objects target_objects = self.load_selection(targets, selection=PipelineSelection.NONE, load_refs=True) - logsdirs = [] + log_file_paths = [] for obj in target_objects: ref = obj.get_artifact_name() if not obj._cached(): @@ -613,9 +613,9 @@ class Stream(): self._message(MessageType.WARN, "{} is cached without log files".format(ref)) continue - logsdirs.append(self._artifacts.get_artifact_logs(ref)) + log_file_paths.extend(obj.get_logs()) - return logsdirs + return log_file_paths # artifact_delete() # diff --git a/tests/frontend/artifact.py b/tests/frontend/artifact.py index eb187a168..177be8c30 100644 --- a/tests/frontend/artifact.py +++ b/tests/frontend/artifact.py @@ -56,6 +56,9 @@ def test_artifact_log(cli, datafiles): assert result.exit_code == 0 log = result.output + # Assert that there actually was a log file + assert log != '' + # Read the log via the key result = cli.run(project=project, args=['artifact', 'log', 'test/target/' + key]) assert result.exit_code == 0 -- cgit v1.2.1