From 8d8b02ef7d25118da94635e4764fa64188a97b8e Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Wed, 3 May 2023 22:44:36 +0900 Subject: [PATCH] doc: snippets: Clarify snippet processing order This commit clarifies the snippet processing order when multiple snippets are specified. Signed-off-by: Stephanos Ioannidis --- doc/build/snippets/writing.rst | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/build/snippets/writing.rst b/doc/build/snippets/writing.rst index 5a60a7e7383..92979d99d05 100644 --- a/doc/build/snippets/writing.rst +++ b/doc/build/snippets/writing.rst @@ -98,9 +98,31 @@ The build system looks for snippets in these places: Processing order **************** -The order that snippets are processed is currently not defined. -Therefore, you should write your :file:`snippet.yml` file so that -it is not dependent on other snippets. +Snippets are processed in the order they are listed in the :makevar:`SNIPPET` +variable, or in the order of the ``-S`` arguments if using west. + +To apply ``bar`` after ``foo``: + +.. code-block:: console + + cmake -Sapp -Bbuild -DSNIPPET="foo;bar" [...] + cmake --build build + +The same can be achieved with west as follows: + +.. code-block:: console + + west build -S foo -S bar [...] app + +When multiple snippets set the same configuration, the configuration value set +by the last processed snippet ends up in the final configurations. + +For instance, if ``foo`` sets ``CONFIG_FOO=1`` and ``bar`` sets +``CONFIG_FOO=2`` in the above example, the resulting final configuration will +be ``CONFIG_FOO=2`` because ``bar`` is processed after ``foo``. + +This principle applies to both Kconfig fragments (``.conf`` files) and +devicetree overlays (``.overlay`` files). .. _snippets-devicetree-overlays: