You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:55:55 UTC

[buildstream] 11/12: WIP: Add --logs flag to show

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch richardmaw/wip/log-show
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 9bae8ee8c896fb20441b8e964505b8fa645ddd27
Author: Richard Maw <ri...@codethink.co.uk>
AuthorDate: Thu Jun 14 13:52:01 2018 +0100

    WIP: Add --logs flag to show
    
    This is also possible by adding %{build-log} to the format string,
    but --logs to just append '\n%{build-log}' has been added for convenience.
---
 buildstream/_frontend/cli.py    |  8 +++++++-
 buildstream/_frontend/widget.py | 11 +++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index bd2ce8a..3078574 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -491,10 +491,12 @@ def push(app, elements, deps, remote):
 @click.option('--format', '-f', 'format_', metavar='FORMAT', default=None,
               type=click.STRING,
               help='Format string for each element')
+@click.option('--logs', 'logs', default=False,
+              is_flag=True, help='Display logs in summary')
 @click.argument('elements', nargs=-1,
                 type=click.Path(readable=False))
 @click.pass_obj
-def show(app, elements, deps, except_, order, format_):
+def show(app, elements, deps, except_, order, format_, logs):
     """Show elements in the pipeline
 
     By default this will show all of the dependencies of the
@@ -526,6 +528,7 @@ def show(app, elements, deps, except_, order, format_):
         %{public}         Public domain data
         %{workspaced}     If the element is workspaced
         %{workspace-dirs} A list of workspace directories
+        %{build-log}      Content of build log
 
     The value of the %{symbol} without the leading '%' character is understood
     as a pythonic formatting string, so python formatting features apply,
@@ -552,6 +555,9 @@ def show(app, elements, deps, except_, order, format_):
         if not format_:
             format_ = app.context.log_element_format
 
+        if logs:
+            format_ += "\n%{build-log}"
+
         report = app.logger.show_pipeline(dependencies, format_)
         click.echo(report, color=app.colors)
 
diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py
index c43dce6..d755a02 100644
--- a/buildstream/_frontend/widget.py
+++ b/buildstream/_frontend/widget.py
@@ -423,6 +423,17 @@ class LogLine(Widget):
                     line = p.fmt_subst(
                         line, 'workspace-dirs', '')
 
+            # Logs
+            if "%{build-log" in format_:
+                if element._cached():
+                    log_path = element._get_build_log()
+                    content = open(log_path, 'r').read()
+                    line = p.fmt_subst(
+                        line, 'build-log', content)
+                else:
+                    line = p.fmt_subst(
+                        line, 'build-log', '')
+
             report += line + '\n'
 
         return report.rstrip('\n')