diff options
-rw-r--r-- | buildstream/_frontend/cli.py | 3 | ||||
-rw-r--r-- | buildstream/_frontend/widget.py | 23 | ||||
-rw-r--r-- | tests/frontend/show.py | 25 |
3 files changed, 50 insertions, 1 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 49d5717b4..b3c4634a9 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -440,6 +440,9 @@ 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 + %{deps} A list of all dependencies + %{build-deps} A list of build dependencies + %{runtime-deps} A list of runtime dependencies The value of the %{symbol} without the leading '%' character is understood as a pythonic formatting string, so python formatting features apply, diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py index de122f8a3..b8e3d920a 100644 --- a/buildstream/_frontend/widget.py +++ b/buildstream/_frontend/widget.py @@ -27,7 +27,7 @@ from ruamel import yaml import click from . import Profile -from .. import Element, Consistency +from .. import Element, Consistency, Scope from .. import _yaml from .. import __version__ as bst_version from .._exceptions import ImplError @@ -435,6 +435,27 @@ class LogLine(Widget): line = p.fmt_subst( line, 'workspace-dirs', '') + # Dependencies + if "%{deps" in format_: + deps = [e.name for e in element.dependencies(Scope.ALL, recurse=False)] + line = p.fmt_subst( + line, 'deps', + yaml.safe_dump(deps, default_style=None).rstrip('\n')) + + # Build Dependencies + if "%{build-deps" in format_: + build_deps = [e.name for e in element.dependencies(Scope.BUILD, recurse=False)] + line = p.fmt_subst( + line, 'build-deps', + yaml.safe_dump(build_deps, default_style=False).rstrip('\n')) + + # Runtime Dependencies + if "%{runtime-deps" in format_: + runtime_deps = [e.name for e in element.dependencies(Scope.RUN, recurse=False)] + line = p.fmt_subst( + line, 'runtime-deps', + yaml.safe_dump(runtime_deps, default_style=False).rstrip('\n')) + report += line + '\n' return report.rstrip('\n') diff --git a/tests/frontend/show.py b/tests/frontend/show.py index ad3ae3591..ac1edebd6 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -400,3 +400,28 @@ def test_exceed_max_recursion_depth(cli, tmpdir, dependency_depth): assert result.exit_code == -1 shutil.rmtree(project_path) + + +############################################################### +# Testing format symbols # +############################################################### +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) +@pytest.mark.parametrize("dep_kind, expected_deps", [ + ('%{deps}', '[import-dev.bst, import-bin.bst]'), + ('%{build-deps}', '[import-dev.bst]'), + ('%{runtime-deps}', '[import-bin.bst]') +]) +def test_format_deps(cli, datafiles, dep_kind, expected_deps): + project = os.path.join(datafiles.dirname, datafiles.basename) + target = 'checkout-deps.bst' + result = cli.run(project=project, silent=True, args=[ + 'show', + '--deps', 'none', + '--format', '%{name}: ' + dep_kind, + target]) + result.assert_success() + + expected = '{name}: {deps}'.format(name=target, deps=expected_deps) + if result.output.strip() != expected: + raise AssertionError("Expected output:\n{}\nInstead received output:\n{}" + .format(expected, result.output)) |