Topics

RFC: Changing the `west build` command-line interface


Carles Cufi
 

Hi there,

As you know, west now allows users to build Zephyr applications with it, and many among us have started making use of this new functionality.

The signature for `west build` currently reads (and has done so from its introduction):

usage: west build [-h] [-b BOARD] [-s SOURCE_DIR] [-d BUILD_DIR] [-t TARGET]
[-c] [-f]
[cmake_opt [cmake_opt ...]]

Which means that, in order to specify the source directory (i.e. the sample that you want to build) you either invoke `west build` directly from it or you use the `-s` optional argument like so:

west build -b reel_board -s samples/hello_world

Since we anticipate `west build` to be widely used in the future, I am proposing a change whereby the source directory would be specified as the first optional argument:

west build -b reel_board samples/hello_world

to save some typing and also to be consistent with CMake, which is invoked automatically by west when required.

The new signature would look like:

usage: west build [-h] [-b BOARD] [-d BUILD_DIR]
[-t TARGET] [-c] [-f] [source_dir]
-- [cmake_opt [cmake_opt ...]]

This has a few implications worth discussing:

1. The change is not entirely backwards-compatible but we have kept the `-s` option (as a hidden one) in order to break as few existing scripts as possible
2. `west build` allows you to pass on additional arguments to CMake. Before this change, those were all and any positional arguments present in the invocation line. Now however, the first positional argument is always treated as the source directory, unless a `--` separator is present, in which case the source directory is assumed as implicit (CWD) and all arguments after `--` are treated as CMake options to be passed on to it.

Additional information can be found in the PR and its review comments:
https://github.com/zephyrproject-rtos/zephyr/pull/13635

Please add your feedback in the PR and let us know what you think of the proposed change.

Thanks,

Carles