Skip to content

Commit 12da774

Browse files
CLI improvements (#224)
* Remove incorrect variable check for UROS_VERBOSE_BUILD 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> * Made zephyr configuration file selection more consistent 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> * Use getopts for build_firmware.sh argument parsing 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> * Add option to pass through build arguments to west 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> * Add verbose build output to zephyr build Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de>
1 parent ccd22a8 commit 12da774

2 files changed

Lines changed: 61 additions & 24 deletions

File tree

config/zephyr/generic/build.sh

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,52 @@ pushd $FW_TARGETDIR >/dev/null
5252
export BOARD=$PLATFORM
5353
fi
5454

55-
# Use transport specific conf if given and exists.
56-
if [ -z "$TRANSPORT" ];then
55+
# Choose configuration based on transport and host
56+
if [ -z "$TRANSPORT" ]; then
57+
echo "Configuration: No transport set, using prj.conf"
5758
export CONF_FILE="prj.conf"
59+
60+
elif [ "$PLATFORM" = "host" ]; then
61+
echo "Configuration: Platform 'host' detected, using host-udp.conf"
62+
export CONF_FILE="host-udp.conf"
63+
5864
else
5965
if [ ! -f "$UROS_APP_FOLDER/$TRANSPORT.conf" ]; then
60-
echo "Specific config for transport not found. Using prj.conf."
66+
echo "Configuration: Specific config for transport $TRANSPORT not found, using prj.conf"
6167
export CONF_FILE="prj.conf"
6268
else
69+
echo "Configuration: Using transport-specific $TRANSPORT.conf"
6370
export CONF_FILE="$TRANSPORT.conf"
6471
fi
6572
fi
6673

67-
if [ "$PLATFORM" = "host" ]; then
68-
echo "Zephyr native-posix detected. Using host-udp.conf."
74+
UROS_BUILD_CMD="
75+
west build
76+
-b $BOARD
77+
-p auto
78+
$UROS_APP_FOLDER
79+
-- -DCONF_FILE=$UROS_APP_FOLDER/$CONF_FILE
80+
-G'Unix Makefiles'
81+
-DCMAKE_VERBOSE_MAKEFILE=$UROS_VERBOSE_BUILD
82+
-DMICRO_ROS_FIRMWARE_DIR=$FW_TARGETDIR
83+
${UROS_EXTRA_BUILD_ARGS[@]}"
6984

70-
export CONF_FILE="host-udp.conf"
85+
if [ "$UROS_VERBOSE_BUILD" = "on" ]; then
86+
echo ""
87+
echo "-----------------------------"
88+
echo "| Verbose build information |"
89+
echo "-----------------------------"
90+
echo "Fast build: $UROS_FAST_BUILD"
91+
echo "App name: $UROS_APP"
92+
echo "Full app path: $UROS_APP_FOLDER"
93+
echo "Zephyr board: $BOARD"
94+
echo "Zephyr configuration file: $UROS_APP_FOLDER/$CONF_FILE"
95+
echo "Extra build arguments: ${UROS_EXTRA_BUILD_ARGS[@]}"
96+
echo "Full build command: "${UROS_BUILD_CMD[@]}
97+
echo ""
7198
fi
7299

73-
# Check build argument parameters
74-
if [ -z "$UROS_VERBOSE_BUILD" ]; then
75-
UROS_VERBOSE_BUILD=off
76-
fi
100+
# Build zephyr + app
101+
eval ${UROS_BUILD_CMD[@]}
77102

78-
# Build Zephyr + app
79-
west build -b $BOARD -p auto $UROS_APP_FOLDER -- -DCONF_FILE=$UROS_APP_FOLDER/$CONF_FILE -G'Unix Makefiles' -DCMAKE_VERBOSE_MAKEFILE=$UROS_VERBOSE_BUILD -DMICRO_ROS_FIRMWARE_DIR=$FW_TARGETDIR
80103
popd >/dev/null

scripts/build_firmware.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,38 @@ PREFIX=$(ros2 pkg prefix micro_ros_setup)
1111
# Parse cli arguments
1212
UROS_FAST_BUILD=off
1313
UROS_VERBOSE_BUILD=off
14-
for param in "$@"
14+
UROS_EXTRA_BUILD_ARGS=""
15+
16+
while getopts "vf" o
1517
do
16-
case $param in
17-
"-f")
18-
echo "Fast-Build active, ROS workspace will not be re-built!"
19-
UROS_FAST_BUILD=on
20-
shift
21-
;;
22-
"-v")
23-
echo "Building in verbose mode"
24-
UROS_VERBOSE_BUILD=on
25-
shift
26-
;;
18+
case "$o" in
19+
f)
20+
echo "Fast-Build active, ROS workspace will not be re-built!"
21+
UROS_FAST_BUILD=on
22+
;;
23+
v)
24+
echo "Building in verbose mode"
25+
UROS_VERBOSE_BUILD=on
26+
;;
27+
[?])
28+
echo "Usage: ros2 run micro_ros_setup build_firmware.sh [options] -- [build_args]"
29+
echo "Options:"
30+
echo " -v Print verbose build output."
31+
echo " -f Activate Fast-Build. Without this, mcu_ws will get rebuilt completely."
32+
echo "Build args: These options will get directly forwarded to the build system (currently only supported for zephyr)."
33+
exit 1
34+
;;
2735
esac
2836
done
37+
shift $((OPTIND-1))
38+
39+
if [[ -n "$@" ]]; then
40+
UROS_EXTRA_BUILD_ARGS=("$@")
41+
fi
2942

3043
export UROS_FAST_BUILD
3144
export UROS_VERBOSE_BUILD
45+
export UROS_EXTRA_BUILD_ARGS
3246

3347
# Checking if firmware exists
3448
if [ -d $FW_TARGETDIR ]; then

0 commit comments

Comments
 (0)