From 79b6bdbab641a914edb9a0fbf088fe515e7c3996 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 26 Mar 2024 14:08:31 +0100 Subject: [PATCH] fix(prebuild): made shell script fully posix if called with other shell (example dash), shebang is ignored and so some syntax was not supported. Signed-off-by: Frederic Pillon --- system/extras/postbuild.sh | 2 +- system/extras/prebuild.sh | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/system/extras/postbuild.sh b/system/extras/postbuild.sh index 3588971e4a..36569f1435 100755 --- a/system/extras/postbuild.sh +++ b/system/extras/postbuild.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh - BUILD_PATH="$1" BUILD_SERIE="$2" diff --git a/system/extras/prebuild.sh b/system/extras/prebuild.sh index 91f878c66f..8be41a9035 100755 --- a/system/extras/prebuild.sh +++ b/system/extras/prebuild.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh - BUILD_PATH="$1" BUILD_SOURCE_PATH="$2" @@ -9,20 +9,38 @@ if [ ! -f "$BUILD_PATH/sketch" ]; then mkdir -p "$BUILD_PATH/sketch" fi -# Create empty build.opt if build_opt.h does not exists in the original sketch dir -# Then add or append -fmacro-prefix-map option to change __FILE__ absolute path of -# the board platform folder to a relative path by using '.'. -# (i.e. the folder containing boards.txt) +# Create empty build.opt or clear it if build_opt.h does not exists in the original sketch dir if [ ! -f "$BUILD_SOURCE_PATH/build_opt.h" ]; then - printf '\n-fmacro-prefix-map="%s"=.' "${BOARD_PLATFORM_PATH//\\/\\\\}" > "$BUILD_PATH/sketch/build.opt" + true >"$BUILD_PATH/sketch/build.opt" else # Else copy the build_opt.h as build.opt # Workaround to the header file preprocessing done by arduino-cli # See https://github.com/arduino/arduino-cli/issues/1338 - cp "$BUILD_SOURCE_PATH/build_opt.h" "$BUILD_PATH/sketch/build.opt" - printf '\n-fmacro-prefix-map="%s"=.' "${BOARD_PLATFORM_PATH//\\/\\\\}" >> "$BUILD_PATH/sketch/build.opt" + cp -f "$BUILD_SOURCE_PATH/build_opt.h" "$BUILD_PATH/sketch/build.opt" fi - +# On Windows, need to protect '\' in path +UNAME_OS="$(uname -s)" +case "${UNAME_OS}" in + Windows*) + i=1 + prefix="" + while [ "$i" -le "${#BOARD_PLATFORM_PATH}" ]; do + c=$(printf '%s' "$BOARD_PLATFORM_PATH" | cut -c $i) + prefix=${prefix}${c} + if [ "${c}" = "\\" ]; then + prefix=${prefix}"\\" + fi + i="$((i + 1))" + done + ;; + *) + prefix=${BOARD_PLATFORM_PATH} + ;; +esac +# Then append -fmacro-prefix-map option to change __FILE__ absolute path of +# the board platform folder to a relative path by using '.'. +# (i.e. the folder containing boards.txt) +printf '\n-fmacro-prefix-map="%s"=.' "${prefix}" >>"$BUILD_PATH/sketch/build.opt" # Force include of SrcWrapper library -echo "#include " > "$BUILD_PATH/sketch/SrcWrapper.cpp" +echo "#include " >"$BUILD_PATH/sketch/SrcWrapper.cpp"