Skip to content

CLI improvements - #224

Merged
pablogs9 merged 5 commits into
micro-ROS:foxyfrom
RobertWilbrandt:improve_cli
Nov 5, 2020
Merged

CLI improvements#224
pablogs9 merged 5 commits into
micro-ROS:foxyfrom
RobertWilbrandt:improve_cli

Conversation

@RobertWilbrandt

Copy link
Copy Markdown
Contributor

This contains a set of cli improvements for the build step, mainly centered around the zephyr RTOS:

  • Add option to pass arbitrary commands to cmake for zephyr builds. This uses the following syntax: ros2 run micro_ros_setup build_firmware.sh -f -- -DCMAKE_EXPORT_COMPILE_COMMANDS=on. This is consistent with the way west handles these arguments. Use cases are:

    • Passing -DCMAKE_EXPORT_COMPILE_COMMANDS=on is useful to provide better ide integration
    • Passing -DZEPHYR_EXTRA_MODULES=/path/to/module can be useful if you rely on e.g. out-of-tree zephyr device drivers.

    While both these could get implemented as extra flags to build_firmware.sh, i think this is the more versatile approach (after all, micro_ros_setup shouldn't have to know about every possibly useful west argument). It might make sense to add support for this feature to other RTOSes too, even for make-based build systems passing things like -j 4 might be useful.

  • Use getopts to parse cli arguments and provide a useful help message. This is just generally more robust then handmade parsing and allows for the feature above.

  • Print build information for verbose zephyr builds (=> only done if -v is used). See example below.

  • Some small cleanups.

Example help message:

Usage: ros2 run micro_ros_setup build_firmware.sh [options] -- [build_args]
Options:
  -v   Print verbose build output.
  -f   Activate Fast-Build. Without this, mcu_ws will get rebuilt completely.
Build args: These options will get directly forwarded to the build system (currently only supported for zephyr).

Example verbose build output:

> UROS_CUSTOM_APP_FOLDER=~/projects/micro-ROS_zephyr_display_demo/apps ros2 run micro_ros_setup build_firmware.sh -f -v -- -DCMAKE_EXPORT_COMPILE_COMMANDS=on
Fast-Build active, ROS workspace will not be re-built!
Building in verbose mode
Crosscompiled environment: cleaning path
Building firmware for zephyr platform stm32f429i_disc1
Selected app: display_demo
Unrecognized board: stm32f429i_disc1. Trying to build
Configuration: Using transport-specific serial.conf

-----------------------------
| Verbose build information |
-----------------------------
Fast build:                  on
App name:                    display_demo
Full app path:               /home/wilbrandt/projects/micro-ROS_zephyr_display_demo/apps/display_demo
Zephyr board:                stm32f429i_disc1
Zephyr configuration file:   /home/wilbrandt/projects/micro-ROS_zephyr_display_demo/apps/display_demo/serial.conf
Extra build arguments:       -DCMAKE_EXPORT_COMPILE_COMMANDS=on
Full build command:           west build -b stm32f429i_disc1 -p auto /home/wilbrandt/projects/micro-ROS_zephyr_display_demo/apps/display_demo -- -DCONF_FILE=/home/wilbrandt/projects/micro-ROS_zephyr_display_demo/apps/display_demo/serial.conf -G'Unix Makefiles' -DCMAKE_VERBOSE_MAKEFILE=on -DMICRO_ROS_FIRMWARE_DIR=/home/wilbrandt/projects/microros_zephyr/firmware -DCMAKE_EXPORT_COMPILE_COMMANDS=on

-- west build: generating a build system
[...]

This is not really needed as the variable is always set in
build_firmware.sh. It was also implemented incorrectly, as the -z check
does not work for unset variables (the correct way would be to use [ -z
${UROS_VERBOSE_BUILD+x} ]).

Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de>
This will output a line for the configuration file in every build and
also prevent the double-output in case of PLATFORM=host with no
transport-specific config.

Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de>
This is a much more robust solution for custom argument parsing and
allows for providing a useful help message.

Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de>
There are some use cases where this feature is useful, e.g.:
- It is quite common to use -DCMAKE_EXPORT_COMPILE_COMMANDS for better
  IDE support
- In zephyr specifically, you might want to pass
  -DZEPHYR_EXTRA_MODULES=[...] so you can use e.g. out-of-tree device
  drivers

The syntax used here is consistent with the way west can forward
arguments directly to cmake.

Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de>
Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de>
@pablogs9

pablogs9 commented Nov 5, 2020

Copy link
Copy Markdown
Member

Hello @RobertWilbrandt, this looks amazing. Thank you very much for your contributions!

@pablogs9
pablogs9 merged commit 12da774 into micro-ROS:foxy Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants