When guessing the build folder, the current path might not exist at all,
leading to an uncaught exception when trying to list its folders. Fix
this by making sure the path exists at all first.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
A recent developer experience study has pointed out that it's very
common for people to miss that the minimum cmake version required by
zephyr is higher than that which is commonly packaged by Linux
distributions.
Since this is a serious usability issue, it's worth adding extra
checking from zcmake.py to make sure that west commands which run
cmake always print a sensible error message if the cmake version used
is too old. Make that happen.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Getting slightly subjective, but fixes this pylint warning:
scripts/west_commands/zcmake.py:186:13: R1714: Consider merging
these comparisons with "in" to "type_ in ('STRING', 'INTERNAL')"
(consider-using-in)
Use a set literal instead of a tuple literal, as recent Python 3
versions optimize set literals with constant keys nicely.
Getting rid of pylint warnings for a CI check. I could disable any
controversial ones (it's already a list of warnings to enable anyway).
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Empty sequences are falsy in Python, so len() can be skipped.
Fixing pylint warnings for a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
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>
Remove a trailing comma that generated a single-element tuple and made
pylint warn:
scripts/west_commands/boards.py:50:8: W0106: Expression
"(parser.add_argument(...), )" is assigned to nothing
(expression-not-assigned)
No functional change.
Fixing pylint warnings for a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Removing these doesn't change behavior, since the
subprocess.CalledProcessError is just immediately re-raised when caught.
Fixes this pylint warning:
W0706: The except handler raises immediately (try-except-raise)
Fixing pylint warnings for a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
These just pass their arguments through to the base class constructor.
Removing them means the base class constructor gets called directly
instead.
Fixes this pylint warning:
W0235: Useless super delegation in method '__init__'
(useless-super-delegation)
Fixing pylint warnings for a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Should be wrn() instead of warn(). Reported by pylint.
Also remove a {} from the message. It's not being formatted.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Fixes this pylint warning:
R0201: Method could be a function (no-self-use)
Another option would be to turn them into regular functions, but that'd
be a bigger change.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
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>
Fixes this pylint warning:
scripts/west_commands/run_common.py:175:12: R1719: The if expression
can be replaced with 'test' (simplifiable-if-expression)
Fixing pylint warnings for a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Newer pyocd versions (specifically the 0.21.0 we have in our
requirements.txt) no longer support -b and have moved the same option
to -u. Keep up.
Fixes: #17554
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This is a band-aid to make it more obvious to potential users of 'west
sign' and 'west flash' which hex file they are flashing, when they are
falling back on a binary file, and erroring out when a hex file does
not exist.
Fixes: #18201
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Add a check to make sure the hex file exists as that is what we utilize
in openocd to flash. If its missing we report that its likely due to
not having CONFIG_BUILD_OUTPUT_HEX set.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Use hex file for flash command, instead of elf file. This allows to
flash signed firmware, which is not available in elf format, by
specifying --hex-file command line argument.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
So far zephyr.elf file was hardcoded in cmake files. Remove it from
there and use cfg.elf_file from python, which can be overwritten by
specifying --elf-file command line option.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
The pytest.raises context manager is now returning an ExceptionInfo
whose str() doesn't contain the str() of the underlying exception
object. Take str(e.value) directly to make sure we're looking at the
exception string.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
The main change is the elimination of the bootstrapper, a design flaw
/ misfeature.
Update the documentation to be compatible with the 0.6.x releases as
well. This has to be done atomically, as there were incompatible
changes. Make use of the versionchanged and versionadded directives
to begin keeping track of how these APIs are evolving.
(Note that west 0.6.0 will remain compatible with the extension
commands in Zephyr v1.14 LTS as long as that is still alive. This
change is targeted towards Zephyr 2.0 users.)
This requires a bump in the shippable container and allows us to
simplify the west_commands test procedure.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
When using a build folder format with build.dir-fmt that includes any
parameters that need resolving, the west runners cannot find the folder
since the required information (board, source dir or app) is not
available.
Add a very simple heuristic to support the case where a build folder
starts with a hardcoded prefix (for example 'build/') and a single build
is present under that prefix.
The heuristic is gated behind a new configuration option:
build.guess-dir
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Print a friendlier error message on ValueError, but don't throw away
the stack trace.
Move another call to log.die().
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
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>
Having common log handlers now lets us improve our logging output so
that info messages are prefixed with the runner they came from, and
doing something similar with the high level steps as we go, like this:
-- west <command>: using runners
-- runners.RUNNER_NAME: doing something
<output from RUNNER_NAME subprocesses go here>
-- runners.RUNNER_NAME: all done, bye
We can also colorize the west output to make it stand out better from
subprocesses, using the same output formatting style that west
commands like west list do.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
I've had some requests to be able to use code in the runners package
without having west installed.
It turns out to be pretty easy to make this happen, as west is
currently only used for west.log and some trivial helper methods:
- To replace west log, use the standard logging module
- Add an appropriate handler for each runner's logger in
run_common.py which delegates to west.log, to keep
output working as expected.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Add self.require() checks before running commands. Increase test
coverage, including for this feature, while we are here.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
The runners/jlink.py script has a mechanism for erroring out if a host
tool is not installed. Abstract it into runners/core.py and handle it
from run_common.py. This will let it be used in more places.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Check the CONFIG_BUILD_OUTPUT_HEX and CONFIG_BUILD_OUTPUT_BIN options
are enabled before attempting to build signed versions of these formats.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Add more error handling and warnings. Doing this nicely requires a bit
of re-work to the control flow.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
When signing binaries from multiple build directories, it is
inconvenient to have to specify the output file locations by hand each
time. It's also a little weird that they're not next to zephyr.bin and
zephyr.hex.
Move them to the build directory, next to their unsigned variants.
Suggested by Piotr Mienkowski.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Let's leave self.args as the actual parsed argument namespace.
Pass the final computed build directory separately.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This got broken in the patches which added the build.dir-fmt config
option when BUiLD_DIR_DESCRIPTION was renamed.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
In the west flash/debug commands, if the user gives an invalid build
directory, they'll get a stack trace instead of a helpful error
message when the cache can't be built.
Fix that.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
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>
In preparation for upcoming changes to the way the default build folder
is defined, switch to using the common find_build_dir() function in the
runners.
This actually changes the behavior for the west build command slightly,
since the current working directory (cwd) will now be checked after the
default build folder ('build'). This brings it in line with what is
used for the runners.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Adds a new argument to the jlink runner to reset the device after
loading code to flash. This fixes a problem with the lpcxpresso54114
board where it was necessary to manually reset the board to get new code
to start running after the 'ninja flash' command. This new argument is
optional and false by default because there are some cases were we must
not reset after load, such as when we load the application into ITCM on
imx rt devices.
Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
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>
Let's not mess with CommandContextError here, as the APIs have gotten
messed around a bit in various versions. Just use log.die() as that
will work with current and future west versions, and is clearer anyway.
Fixes west 247.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Add a completion command that dumps the contents of a shell
completion file present in the zephyr repository.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This file was previously located in the west repository, under scripts/.
Since it now includes knowledge about specific behavior ef zephyr
extension commands, we move it here after overhauling it completely.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
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>