cli: apply parameters (`--params` option) to leftovers
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 31 Jul 2019 21:40:56 +0000 (17:40 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 3 Aug 2019 14:21:39 +0000 (10:21 -0400)
commit1ead9076477cc6be07b0c48ce02fa40e49ddc2f0
treed7ac5b76b6405b78d69c33ae3d2112709a2bd256
parent612a98703cbf22bd57f49bb9a22154acb214fbf1
cli: apply parameters (`--params` option) to leftovers

It is currently not possible to apply --params after a leftover.

This patch proposes a way to allow it and to deal with the ambiguity
that it poses.

In the simple case, we have:

    babeltrace2 my-traces --params=foo=2

All source components auto-discovered from the `my-traces` leftover will
receive the `foo=2` parameter.

If we have more than one leftover, but _no_ cross-leftover grouping,
then it is also intuitive:

    babeltrace2 my-traces-1 --params=foo=2 my-traces-2 --params=bar=3

... all source components discovered from `my-traces-1` will receive
`foo=2` and all source components discovered from `my-traces-2` will
receive `bar=3`.

It becomes less obvious when components are given inputs coming from
multiple leftovers (because of the auto-discovery grouping feature):
which parameters do they receive?  For example, if the following line:

    babeltrace2 my-traces-1 --params=foo=2,bar=3 my-traces-2 --params=foo=4

leads to these components getting instantiated, with these inputs:

 * Source component X with inputs `my-traces-1/x` and `my-traces-2/x`.
 * Source component Y with input `my-traces-1/y`

In this case, each component receives the parameters of all leftovers
that contributed to its inputs, in the same order as they are provided
on the command line.  The resulting `run` command line for the example
above could therefore look like:

    ... --component x:src.my.comp --params=foo=2,bar=3 --params=foo=4 \
        --component y:src.my.comp --params=foo=2,bar=3

resulting in these parameters being passed to the components:

 * Source component X receives parameters `foo=4,bar=3`
 * Source component Y receives parameters `foo=2,bar=3`

Implementation details
----------------------
The auto discovery mechanism now returns, for each result, which
input from the passed `inputs` array contributed to that result.
This allows us, for the component that we create from a given result, to
get the parameters from the leftovers that have contributed to it.

Change-Id: Ic048e4e137c2e1f93b6da13a62629343500cb75a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1809
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cli/babeltrace2-cfg-cli-args.c
src/cli/babeltrace2-cfg-src-auto-disc.c
src/cli/babeltrace2-cfg-src-auto-disc.h
tests/cli/convert/test_auto_source_discovery_params [new file with mode: 0755]
tests/cli/convert/test_convert_args
tests/data/cli/convert/auto-source-discovery-params/bt_plugin_test.py [new file with mode: 0644]
tests/data/cli/convert/auto-source-discovery-params/dir-a/aaa [new file with mode: 0644]
tests/data/cli/convert/auto-source-discovery-params/dir-ab/aaa [new file with mode: 0644]
tests/data/cli/convert/auto-source-discovery-params/dir-ab/bbb [new file with mode: 0644]
tests/data/cli/convert/auto-source-discovery-params/dir-b/bbb [new file with mode: 0644]
This page took 0.025321 seconds and 4 git commands to generate.