Skip to content

Commit 3d2ef53

Browse files
committed
Document mixins referencing other mixins
Describe the reserved 'mixin' key which allows a mixin to be composed out of other mixins, the order in which the referenced mixins are applied and the 'application order' line shown by 'colcon mixin show'. Assisted-by: Claude Opus 5
1 parent f19adf8 commit 3d2ef53

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

reference/mixin-arguments.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,74 @@ In all other cases the latter value replaces the former value.
5252
both compiler options to be used.
5353

5454
Furthermore, the option values of a mixin used through the CLI override the default values of a :ref:`default file <configuration_defaults-yaml>`.
55+
56+
Mixins referencing other mixins
57+
-------------------------------
58+
59+
A mixin can be composed out of other mixins by using the reserved ``mixin``
60+
key.
61+
Its value is a list of names of other mixins defined for the same verb.
62+
63+
An example mixin file defining a mixin which references two other mixins:
64+
65+
.. code-block:: yaml
66+
67+
{
68+
"build": {
69+
"debug": {
70+
"cmake-args": ["-DCMAKE_BUILD_TYPE=Debug"]
71+
},
72+
"compile-commands": {
73+
"cmake-args": ["-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"]
74+
},
75+
"develop": {
76+
"mixin": ["debug", "compile-commands"],
77+
"cmake-args": ["-DCMAKE_VERBOSE_MAKEFILE=ON"]
78+
}
79+
}
80+
}
81+
82+
Invoking ``colcon build --mixin develop`` is equivalent to using the ``debug``
83+
and the ``compile-commands`` mixin followed by the arguments defined by the
84+
``develop`` mixin itself:
85+
86+
* ``cmake-args``: ``['-DCMAKE_BUILD_TYPE=Debug', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DCMAKE_VERBOSE_MAKEFILE=ON']``
87+
88+
The referenced mixins are always applied before the mixin referencing them.
89+
Therefore the referencing mixin is applied last and its values replace or
90+
extend the values of the mixins it references, following the same rules as
91+
described above.
92+
The ``mixin`` key itself is only used to resolve the references, it is never
93+
passed as a command line argument.
94+
95+
References are resolved recursively, so a referenced mixin can reference
96+
further mixins itself.
97+
The resolution happens depth first, meaning for each referenced mixin all of
98+
its own references are applied before it.
99+
If the same mixin is reached through more than one path it is applied once for
100+
each path to keep the semantic that the value applied last wins.
101+
102+
Values passed explicitly on the command line still take precedence over the
103+
values of all mixins, independent of whether a mixin was requested on the
104+
command line or through a reference.
105+
106+
The order in which a composed mixin is applied can be inspected using
107+
``colcon mixin show``.
108+
For every mixin referencing other mixins the output contains an additional
109+
``application order`` line:
110+
111+
.. code-block:: bash
112+
113+
$ colcon mixin show build develop
114+
mixin: ['debug', 'compile-commands']
115+
cmake-args: ['-DCMAKE_VERBOSE_MAKEFILE=ON']
116+
application order: debug -> compile-commands -> develop
117+
118+
.. note::
119+
120+
Using a mixin which can't be resolved results in an error.
121+
That is the case if a referenced mixin doesn't exist, if the references
122+
form a cycle or if the value of a ``mixin`` key isn't a list of strings.
123+
``colcon mixin show`` doesn't fail in these cases but reports the reason
124+
instead of the application order, e.g.
125+
``application order: unavailable (Circular mixin reference: a -> b -> a)``.

0 commit comments

Comments
 (0)