Commit graph

24 commits

Author SHA1 Message Date
Torsten Rasmussen 13642fe013 cmake: west: west flash dependencies in sync with CMake flash target
This commit creates a list of a phony targets for each runner, that is:
`west_flash_depends`, `west_debug_depends`, and so on.
Those targets has identical dependencies as CMake runner target.
flash, debug, debugserver, attach targets.

As example `ninja flash` correctly ensures dependencies are taken into
consideration before calling `west flash`.

Unfortunately, calling `west flash` directly would not re-run the flash
dependencies, cause `west flash` would only build the default CMake
target.

Now, `west flash` calls the phony `west_flash_depends` target, ensuring
all deps are up-to-date before flashing (unless --skip-rebuild is given)

The same is true for the other mentioned runners.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-07-01 07:58:10 -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 f8e8e9229d runners: enforce RunnerCaps via create() indirection
Require all implementations to provide a do_create(), a new
ZephyrBinaryRunner abstract class method, and make create() itself
concrete.

This allows us to enforce common conventions related to individual
runner capabilities as each runner provides to the core via
RunnerCaps.

For now, just enforce that:

- common options related to capabilities are always added, so runners
  can't reuse them for different ends

- common options provided for runners which don't support them emit
  sensible error messages that should be easy to diagnose and support

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-06-25 12:14:25 +02:00
Martí Bolívar a5268773a6 scripts: run_common: don't dump stack on unavailable runner
Originally reported in #23539 (though that seems to have been another
problem), west flash and friends are dumping stack when used with an
unconfigured runner.

Let's just promote the warning about this to an error. The idea that
this ever could have worked without explicit support has not worked
out in practice, to my knowledge.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-25 19:43:30 +01:00
Martí Bolívar dc0948424e scripts: run_common: fix command line --hex-file and friends
This is yet another bug introduced by the move to runners.yaml.
Sigh. I should have tested this better.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-02-29 19:38:49 +02:00
Martí Bolívar f8cb3d4d53 scripts: run_common: rename 'args' to 'user_args'
This will also make the reason for a following bug fix easier to see.

Update a comment block to include all the work that needs doing.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-02-29 19:38:49 +02:00
Martí Bolívar 97dbda2088 scripts: run_common: rename unknown_args to user_runner_args
This makes its true value clearer, and will make a later bug fix patch
easier to understand.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-02-29 19:38:49 +02:00
Martí Bolívar eb95bed552 scripts: west_commands: fix argument handling with runners.yaml
Refactor the code to support the new runners.yaml file created by the
build system.

Compared to fishing around in the CMake cache, this makes it trivial
to put all the command line arguments to a runner-based command on
equal footing, regardless of if they're defined in the runners package
proper or defined in run_common.py.

This allows board.cmake files to do things like this:

   board_set_runner_args(foo
     --bin-file=${PROJECT_BINARY_DIR}/my-signed.bin)

While at it, make some other cleanups:

- Stop using the obsolete and deprecated west.cmake module while we're
  here in favor of the zcmake.py module which was added to Zephyr a long
  time ago. Yikes. I had forgotten this was still here.

- Stop using west.util's wrap function in favor of raw use of
  textwrap. The west function splits on hyphens, which is breaking
  runner names like "em-starterkit".

- Clean up the --context output a bit

Fixes: #22563
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-02-20 09:06:09 +02:00
Martí Bolívar cea6e3f17a scripts: west_commands: fix help text for flash
The 'command' variable points at a python command object, not a
string. Take its name so the help text for west flash -h correctly
says 'flash' instead of 'debug'.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-02-06 23:06:04 -05:00
Martí Bolívar 8837469492 scripts: runners: improve error handling CLI
Catch RuntimeError when calling runner.run() and print a message
instead of dumping stack unless in verbose mode.

This improves the command line interface when runners raise exceptions.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-01-16 10:20:39 -05:00
Ulf Magnusson bf128d09b3 west: runners: Fix typo'd log.wrn() call
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>
2019-09-07 08:05:57 -04:00
Ulf Magnusson 4699375162 west: run_common.py: Remove redundant 'if'
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>
2019-09-07 07:57:46 -04:00
Carles Cufi 41f1f648f6 west: runners: Guess build folder
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>
2019-06-26 11:50:26 -04:00
Marti Bolivar f08935fa73 scripts: west_commands: improve run_common error handling
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>
2019-06-26 01:25:54 +02:00
Marti Bolivar ec8dbf34dc scripts: tweak runner-related command output
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>
2019-06-26 01:25:54 +02:00
Marti Bolivar ddce583ca2 scripts: west_commands: decouple runners pkg from west
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>
2019-06-26 01:25:54 +02:00
Marti Bolivar 6440514bec scripts: west_commands: fix help string
The option name is wrong.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-06-26 01:25:54 +02:00
Marti Bolivar c07267a26a scripts: runners: abstract jlink's missing program support
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>
2019-06-17 15:06:21 +02:00
Marti Bolivar 8718d5c84b scripts: west: improve error message on missing cache
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>
2019-06-10 17:46:27 -05: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
Carles Cufi 49c4b1c303 west: Use find_build_dir in run_common
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>
2019-06-11 00:00:34 +02:00
Marti Bolivar b3674f596b scripts: fix west TypeError on unknown arguments
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>
2019-05-16 14:00:53 +02:00
Marti Bolivar 8c095285d1 scripts: west_commands: refactor run_common.py
Pull out some more common functionality we will need elsewhere into a
separate file.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2019-02-07 08:44:19 -05:00
Marti Bolivar ab82264ace scripts: add west build, flash, and debug commands
West now supports a mechanism for extension commands. Use it to move
the command implementations that are tightly coupled with boards and
the zephyr build system back into the Zephyr repository.

This patch doesn't include test cases. Those will be moved over in a
subsequent patch.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2019-01-29 10:15:01 +01:00