summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2019-01-31 12:01:55 +0000
committerChandan Singh <csingh43@bloomberg.net>2019-02-12 15:50:52 +0530
commit9b6c18e45cf96fad15bc15d767c627124a1722ee (patch)
tree0a292ff505dca5c5b660e44eb80a3768bec86554
parent86a9048a587f67fbb562f1188f9d04db0c220f75 (diff)
downloadbuildstream-9b6c18e45cf96fad15bc15d767c627124a1722ee.tar.gz
_frontend: Allow printing dependencies using `bst show`
At present, there isn't an easy way to print anything from `bst show` that would give the users an idea of what the dependency graph looks like. One could use things like `--deps build`, but that will just print a list, without any information about the dependency edges. Add `%{deps}`, `%{build-deps}` and `%{runtime-deps}` format strings to `bst show` that would simply print the list of all dependencies, build dependencies and runtime dependencies respectively. Summary of changes: * buildstream/_frontend/cli.py: Add help for new format symbols. * buildstream/_frontend/widget.py: Add support for new format symbols for dependencies. * tests/frontend/show.py: Add tests for new format symbols.
-rw-r--r--buildstream/_frontend/cli.py3
-rw-r--r--buildstream/_frontend/widget.py23
-rw-r--r--tests/frontend/show.py25
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))