cli: apply parameters (`--params` option) to leftovers
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 31 Jul 2019 21:40:56 +0000 (17:40 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Aug 2019 18:05:20 +0000 (14:05 -0400)
commit459f81ca42d756f372f547a1094bb2a02fe25983
treedb9cad0fa880b68e7c5e22e504fac6a83ec888dd
parent65e2817310e684a2e0a05ba127e949694331dc55
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.027001 seconds and 4 git commands to generate.