@@ -52,3 +52,59 @@ 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+ .. note ::
107+
108+ Using a mixin which can't be resolved results in an error.
109+ That is the case if a referenced mixin doesn't exist, if the references
110+ form a cycle or if the value of a ``mixin `` key isn't a list of strings.
0 commit comments