Skip to content

Commit

Permalink
Add support for Zephyr snippets
Browse files Browse the repository at this point in the history
Zephyr 3.4.0 introduced a new feature called "snippets" which is a
replacement for "shields". Add support for specifying snippets in
Zephyr builder. Also, add a check to ensure that only one of "shields"
or "snippets" is specified.

Signed-off-by: Mykyta Poturai <[email protected]>
  • Loading branch information
Deedone committed Mar 5, 2024
1 parent 2580cc6 commit d5a171e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/user-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,9 @@ Optional parameters:
kernel into :code:`additional_deps` of zephyr's config. This will
ensure that zephyr will be built **after** DomU.

* :code:`shields` - list of shields should be integrated to zephyr board.
* :code:`shields` - list of shields should be integrated to zephyr board(For Zephyr < 3.4.0).

* :code:`snippets` - list of snippets should be integrated to zephyr board(For Zephyr >= 3.4.0).

* :code:`vars` - list of additional variables that should be passed to cmakw
via :code:`west build`.
Expand Down
14 changes: 13 additions & 1 deletion moulin/builders/zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from moulin import ninja_syntax
from moulin.utils import construct_fetcher_dep_cmd
from moulin import utils
from moulin.yaml_helpers import YAMLProcessingError


def get_builder(conf: YamlValue, name: str, build_dir: str, src_stamps: List[str],
Expand All @@ -29,7 +30,7 @@ def gen_build_rules(generator: ninja_syntax.Writer):
construct_fetcher_dep_cmd(),
"cd $build_dir",
"source zephyr/zephyr-env.sh",
"$env west build -p auto -b $board -d $work_dir $target -- $shields $vars",
"$env west build -p auto -b $board -d $work_dir $target $snippets -- $shields $vars",
])
generator.rule("zephyr_build",
command=f'bash -c "{cmd}"',
Expand Down Expand Up @@ -72,6 +73,16 @@ def gen_build(self):
else:
shields = ""

snippets_node = self.conf.get("snippets", None)
if snippets_node:
snippets = " ".join([f"-S {snip.as_str}" for snip in snippets_node])
else:
snippets = ""

if shields_node and snippets_node:
raise YAMLProcessingError("Both shields and snippets are specified, only one of them is allowed",
self.conf["snippets"].mark)

vars_node = self.conf.get("vars", None)
if vars_node:
vars_vals = [ZephyrBuilder.__escape_vars_vals(x.as_str) for x in vars_node]
Expand All @@ -86,6 +97,7 @@ def gen_build(self):
"target": self.conf["target"].as_str,
"work_dir": self.conf.get("work_dir", "zephyr/build").as_str,
"shields": shields,
"snippets": snippets,
"vars": vars_value,
"env": env,
}
Expand Down

0 comments on commit d5a171e

Please sign in to comment.