Commit graph

62 commits

Author SHA1 Message Date
Henrik Brix Andersen 519813b3ce scripts: west: commands: build: fix pylint issue
Do not end except block with a useless return, use a pass instead. This
fixes pylint R1711: "Useless return at end of function or method
(useless-return)".

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-05-21 16:47:24 -04:00
Henrik Brix Andersen 5197660073 scripts: west: commands: build: add argument for specifying shields
Add "west build" argument for specifying shields. This saves users from
having to do "west build ... -- -DSHIELD=...", making shields a much better
integrated feature.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-05-21 16:47:24 -04:00
Henrik Brix Andersen b93361e89c scripts: west: build: add snippet argument to usage output
Add example snippet argument to usage output of the "west build" command
and use the singular "SNIPPET" in the generated help text.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-05-21 16:47:24 -04:00
Chaitanya Tata 6b05af6e43 twister: handle quotes for configuration options
Add support handling quotes for configuration options in extra args by
escaping them properly instead of removing the quotes altogether. For
other options in extra_args quotes are removes as usual.

Add similar support in west build command also.

Add a unit test to check this functionality.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-08 06:04:48 -04:00
Jamie McCrae bc97d8fb1e twister: Add support for required snippets
Adds support for twister to require using snippets on tests

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-09-06 16:40:53 +02:00
Maciej Perkowski fb9a6af700 scripts: west_commands: Allow passing source dir when looking for test
Before, only following way of getting test-item build was supported:
`west build -b <BOARD> -T <PATH_TO_SOURCE/TEST_NAME>`
This commit allows to also call it by:
`west build -b <BOARD> <PATH_TO_SOURCE> -T <TEST_NAME>`

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
2023-08-31 12:06:18 -07:00
Anas Nashif d4b0c48892 west: build: fail early if path to test item is not valid
Fail early in case the path to the test item (--test-item) is not valid
or does not exist.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-28 09:17:42 -07:00
Anas Nashif 47102de474 west: build: support additional configuration with --test-item
Also support extra_conf_files, extra_overlay_confs, extra_dtc_overlay_files

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-07-24 11:09:12 -04:00
Anas Nashif 6fdfc91a6c west: build: also parse common section in yaml file
Parse common section and append to cmake args if available when using
--test-item option of west build.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-07-24 11:09:12 -04:00
Maciej Perkowski 93031ad5a0 west_commands: Fix parsing of extra args for test-item
An arg --test-item makes west loading twister's test configurations
form sample/testcase.yaml. It has to mirror twister's behavior.
It was not the case with "extra_args" section. Quotation  marks were
not removed in west as they were in twister. The quotation marks
have to be removed from the extra_args section but left in
extra_configs. The commit adds differentiation for those.

fixes: #60297

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
2023-07-18 21:33:00 -04:00
Emil Obalski e8a7c6706f scripts: west: Check for sysbuild flag when parsing test item
If build is used with -T option, sysbuild flag was ignored
neverthelesss being present in sample.yaml/testcase.yaml
file.

Signed-off-by: Emil Obalski <Emil.Obalski@nordicsemi.no>
2023-07-07 10:27:23 +02:00
Anas Nashif 522624d6c6 west: build: keep kconfig quotes from testcase.yaml
When parsing extra configs from the yaml file, keep quotes.

Fixes #56248

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-05-31 10:02:28 -04:00
Torsten Rasmussen c03e1900ae scripts: adjust WEST_PYTHON to posix path
Adjust WEST_PYTHON to posix path to be consistent with other Python
scripts which passes paths to the Zephyr CMake build system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-05-15 08:13:40 -07:00
Martí Bolívar 1f9ab85354 west: build: appease the linter
The linter is complaining about unnecessary parens.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2023-03-26 16:12:41 +02:00
Marti Bolivar 5880feee33 west: build: add -S <snippet> argument
Writing '-S foo' is a convenience shorthand for adding snippets at
CMake time without having to add '-- -DSNIPPET=foo' to the west build
command line. It is worth adding a new one-letter command line option
because snippets are anticipated to be a very commonly used feature.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2023-03-26 16:12:41 +02:00
Anas Nashif 79b955c80a west: build: allow --test-item to accept twister style instance names
This will allow something like this:

west build -b qemu_x86  -T samples/hello_world/sample.basic.helloworld

instead of:

cd samples/hello_world
west build -b qemu_x86  -T sample.basic.helloworld

Using this option will allow to take twister output and just pass it to
west to reproduce failures.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-01-28 17:05:19 -05:00
Anas Nashif 1008124358 west: build: handler errors in west build with --test-item
Handle errors and wrong test meta-data when using --test-item.

Fixes #52614

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-01-28 17:05:19 -05:00
Torsten Rasmussen 69f4fa6a4e west: adding --domain to west build synopsis
Adding `--domain DOMAIN` to the west build synopsis.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-04 13:06:13 +02:00
Torsten Rasmussen 8408af6d7c scripts: west commands to support --domain
This commit extends the west commands build, flash, and debug to support
--domain when having multiple domains (images) defined in a domains.yaml
build file.

The domains.yaml uses the following yaml format to specify the
build directory of each domain in the multi image build:
> default: <domain-n>
> domains:
>   <domain-1>:
>     build_dir: <build_dir-domain-1>
>   <domain-2>:
>     build_dir: <build_dir-domain-2>
>   ...

`west <build|flash|debug>` has been extended to support
`--domain <domain>`.

`west build` calls CMake to create the build system, and if `--domain`
is given, then the build tool will be invoked afterwards for the
specified domain.

`west flash` will default flash all domains, but `--domain <domain>`
argument can be used to select a specific domain to flash, for example:
> west flash --domain mcuboot

`west debug` only a single domain can be debugged at any given time.
If `--domain` is not specified, then the default domain specified in the
domains.yml file will be used.
Users can still select a different domain, for example with:
> west debug --domain mcuboot

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Torsten Rasmussen 5fe5d6b43d scripts: extend west build command to support sysbuild CMake project
west build now support the sysbuild CMake project which allows users
to easily enable and build a bootloader together with any sample.

This will allow for cleaning up samples and boards which already does
custom multi image in a non-generic way, for example:
- mps2_an521 which includes a build for remote board
- samples/ipc/ which includes a samples for remote board
- esp32 which includes custom bootloaders

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Gregers Gram Rygg 4680180944 scripts: add board revision help text for west build
west build supports specifying the board revision using @revision, but
it's not mentioned in the help text. This commit updates the help text
to describe how to specify the board revision.

Signed-off-by: Gregers Gram Rygg <gregers.gram.rygg@nordicsemi.no>
2022-02-24 13:44:01 -08:00
Marc Herbert c2524a07a6 west: build.py: resolve symlinks in cached source directory check
Fixes the following error:

ERROR: Build directory "<whatever>" is for application "<symbolic source
  dir in CMakeCache.txt>", but source directory "<resolved source dir>"
  was specified; please clean it, use --pristine, or use --build-dir to
  set another build directory
FATAL ERROR: refusing to proceed without --force due to above error

Fixes initial commit ab82264ace ("scripts: add west build, flash, and
debug commands")

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2021-11-10 08:27:16 -05:00
Anas Nashif 070cf6a7fc west: parse options from testcase.yaml/sample.yaml during build
Allow the use of build configurations from testcase/sample yaml files.
This addition makes it easy to build a sample or a test with the options
provided in the test file by pointing to the test section to be built on
the command line of `west build`.

Fixes #31993

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-06-11 20:56:10 -04:00
Martí Bolívar af5a79f6c1 west build: fix board detection
We can't trust the cache to have a CACHED_BOARD just because it exists.

Fixes: #31800

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-02-02 14:08:57 -05:00
Torsten Rasmussen 774103d050 cmake: pristine.cmake requires SOURCE_DIR and BINARY_DIR as arguments
Calling cmake/pristine.cmake now requires SOURCE_DIR and BINARY_DIR as
arguments.

This ensures that pristine.cmake can evaluate if pristine is requested
on in-source builds, and bail out in such case with an error message.

All uses of `pristine.cmake` has been updated to use the new arguments.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-01-23 08:31:13 -05:00
Martí Bolívar c19c6fb438 Revert "scripts: west build: default build.pristine to auto"
This reverts commit c505ca38cf.

Fixes: #31358

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-01-17 08:58:54 -06:00
Martí Bolívar 0d5e6c13e9 boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.

Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.

Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.

Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.

Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.

Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-01-15 15:07:49 -05:00
Martí Bolívar c505ca38cf scripts: west build: default build.pristine to auto
I've repeatedly seen that people are not aware of the existence of
this configuration option.

I've been using build.pristine=auto daily for years and never had any
problems. I've also asked around on Slack a couple of times over
various points to see if anybody objects to making this change. Nobody
has, so let's just turn it on by default.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-09-05 11:06:39 +02:00
Torsten Rasmussen ef3c5e5516 cmake: west: invoke west using same python as rest of build system
When running CMake, then Python3 will be used.
This is detected through FindPython3, with a preference for using the
python or python3 in path, if any of those matches the required Python
minimal version in Zephyr.

It is also possible for users to specify a different Python, as example
by using:
`cmake -DPYTHON_PREFER=/usr/bin/python3.x`

However, when running `west` as native command, then west will be
invoked on linux based on the python defined in:
`west` launcher, which could be: `#!/usr/bin/python3.y`

Thus there could be mismatch in Pythons used for `west` and the python
used for other scripts.

This is even worse on windows, where a user might experience:
```
>.\opt\bin\Scripts\west.exe --version
Traceback (most recent call last):
  File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  ...
  File "C:\Python37\lib\socket.py", line 49, in <module>
    import _socket
ImportError: Module use of python38.dll conflicts with this version of
Python.
```

when testing out a newer Python, but the python in path is still a 3.7.

By importing `west` into zephyr_module.py and by using, as example
`python -c "from west.util import west_topdir; print(topdir())"`
we ensure the same python is used in all python scripts.

Also it allows the user to control the python to use for west.

It also ensures that the west version being tested, is also the version
being used, where old code would test the version imported by python,
but using the west in path (which could be a different version)

If the west version installed in the current Python, and west invocation
is using a different Python interpreter, then an additional help text
is printed, to easier assist users with debugging.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-07-08 23:23:04 -04:00
Martí Bolívar 6e4c2b9be9 scripts: clean up west build/flash/debug help
Just changes to the west help output; no functional changes expected.

Make option descriptions lowercase to match the argparse module's
conventions. When multiple sentences are required, move them to parser
prolog/epilog or argument group description sections.

Clarify some points that have confused multiple people.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-06-29 08:47:04 -04:00
Martí Bolívar 877fc59e30 scripts: west build: handle missing CMAKE_PROJECT_NAME
If there is an error in the CMake configuration phase (this can happen
if a script run using execute_process() fails, for instance), the
build system is incompletely generated and future attempts to run
'west build' will fail. This manifests in the following error:

    Error: could not find CMAKE_PROJECT_NAME in Cache

Whenever we see that the cache exists but this variable is missing,
let's just force CMake to run again. This avoids the error in my
testing and is a bit more user friendly. I've seen multiple users
asking what to do in this situation; the answer is always "just build
it again", so we might as well do it for them.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-11 15:04:04 -04:00
Torsten Rasmussen e819fa46cd scripts: west-commands: Updates needed when removing ZEPHYR_BASE env
This commit includes the following fixes in order to remove environment
setting of ZEPHYR_BASE is west extension commands.

- Build command
  west build --pristine will now use the ZEPHYR_BASE variable found
  in CMakeCache.txt in the build folder.

  This ensures that the pristine command is executed from the same
  Zephyr that was used for compilation.

- Board command
  The west boards command no longer sets Zephyr base before invoking
  cmake -P cmake/boards.cmake

  Instead boards.cmake uses find_package(Zephyr) to ensure consistent
  behavior with Zephyr samples, so that the detection of Zephyr base is
  uniform across CMake commands.

  It also changes BOARD_ROOT_SPACE_SEPARATED to BOARD_ROOT in order to
  be consistent with existing user documentation.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Martí Bolívar 34a59168d5 build: clean up west build
The header printed at the beginning of every west build is kind of
annoying. Let's remove it and just print the application source
directory at cmake time instead. The build directory and board are
already printed there, anyway, and that's all IDE users will see.

Let's clean up the BOARD to make it say "board" instead. That matches
the west build --board option name a bit more closely and is still
legible.

Likewise, let's not print any west build messages if we're just
incrementally recompiling. That's noisy.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-10 14:53:28 +02:00
Mikkel Jakobsen 98eb316bdf scripts: build.py: make _sanity_check() case insensitive on windows
When checking build directory against cache on windows, certain
corner cases can end up failing the comparison because of case
difference on an otherwise identical path. This can be avoided
by ignoring case on windows.

Signed-off-by: Mikkel Jakobsen <mikkel.aunsbjerg@prevas.dk>
2020-03-10 12:19:35 +02:00
Martí Bolívar 150eb6575c scripts: west build: slight --help tweak
We have an open request to make the help for the -t option a little
easier. Try to do that without adding too much length to the short
help.

Fixes: #16202
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2019-12-19 11:29:39 +01:00
Martí Bolívar 0186eade51 scripts: add new west build "build.cmake-args" config option
This option, if set, will add arguments to CMake whenever a new build
system is being generated.

It doesn't affect other invocations of CMake, such as when cmake(1) is
run in build tool mode to actually compile the application.

See the documentation changes for details.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2019-12-10 16:19:18 +01:00
Ulf Magnusson 5d307c98fe west: build.py: Remove len() from conditional to fix pylint warning
Non-empty sequences are truthy in Python, so len() can be skipped.

Fixing pylint warnings for a CI check.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-09-07 08:11:02 -04:00
Ulf Magnusson 89efaeda74 west: build.py: Rename unused variable from unpacking to _
This is a common Python idiom, and it's easy to look up what the unused
value is in this case if you need to. Fixes this pylint warning:

    scripts/west_commands/build.py:227:15: W0612: Unused variable
    'origin' (unused-variable)

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-09-07 08:00:57 -04:00
Marti Bolivar e6873b8d7e scripts: tweak west build output
Follow along with changes made in west flash/debug/etc to make it
easier to see the output steps visually.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-06-26 01:25:54 +02:00
Carles Cufi 98980c6b7c west: build: Configurable build folder format
Add the possibility of configuring the build folder format in west's
configuration system.
The build.dir-fmt configuration option controls how west will create
build folders when not specified, the following parameters are currently
accepted:

- board: The board name
- source_dir: The relative path from CWD to the source directory
- app: The name of the source directory

If CWD is below source_dir in the directory hierarchy then source_dir is
set to an empty string.

This means that if one sets:

[build]
dir-fmt = build/{board}/{source_dir}

Then when building samples/hello_world from zephyr's root for the
reel_board the build folder will be:

./build/reel_board/samples/hello_world

but when building it from inside the samples/hello_world folder it will
instead be:

./build/reel_board

Fixes https://github.com/zephyrproject-rtos/west/issues/124

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-06-11 00:00:34 +02:00
Marti Bolivar 8b9b7e7c8a scripts: avoid unnecessary 'west build --force'
Commit 88fb8bacfb ("scripts: improve west build's board handling")
lets us specify the board with a build.board config or BOARD
environment variable.

However, under some conditions, e.g. if the use has
build.pristine=auto and build.board=some_board, the following fails a
check_force call:

west build samples/hello_world
west build samples/philosophers

The problem is that the check_force wasn't made aware of the other
places a board can come from. Fix that.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-24 11:07:18 +02:00
Marti Bolivar 0396b6e64c scripts: west build: propagate verbosity to cmake generator
When run as "west -v build", make sure that the underlying build tool
is run in verbose mode as well (if the generator is known to support
it, which is the case for Unix Makefiles and Ninja based generators).

The per-generator hacks here are needed to support CMake 3.13. If we
move to CMake 3.14 or later, we can just run "cmake --build BUILD -v"
and be done with it.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-07 15:49:16 +02:00
Marti Bolivar 83a5fd8d4c scripts: make west build -h fit on a screen
The west build --help output no longer fits in a single page.  Move
details and examples into the documentation, so the -h output doesn't
require scrolling around.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00
Marti Bolivar 3a486a85bc scripts: add --build-opt option to west build
This allows passing arguments to the underlying build tool (ninja,
make, etc.).

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00
Marti Bolivar 8465cf25c8 scripts: add --dry-run flags to west build
Analogously to the Make options with the same names, these print the
commands which would have run without running them.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00
Marti Bolivar a1ef6962ae scripts: fix up west build verbosity levels
Adjust them so "west build -v" prints ZEPHYR_BASE and any CMake
commands, but none of the other more esoteric bits of information.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00
Marti Bolivar bbe890ab30 scripts: add build.generator config option for west build
This can be used to override the default CMake generator
permanently. Its values are the same as those acceptable to cmake's -G
option.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00
Marti Bolivar 1f5e6d897f scripts: add --cmake-only to west build
This forces CMake to run, but skips running any build system target
afterwards.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00
Marti Bolivar 88fb8bacfb scripts: improve west build's board handling
- Respect the BOARD environment setting.
- Don't require --force if the board can't be figured out: it might be
  set in CMakeLists.txt, for example. Instead, downgrade to a warning
  which can be disabled with "west config build.board_warn false".
- Add a build.board configuration option used as a final BOARD fallback
  after CACHED_BOARD (in the CMake cache), --board (command line), and
  BOARD (environment).
- Keep the config docs up to date.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00
Marti Bolivar d15950353d scripts: add helpers to west build for getting config options
These will be used more in a later patch.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-06 16:30:05 -04:00