Skip to content

Commit 79b6bdb

Browse files
committed
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 <[email protected]>
1 parent 081354f commit 79b6bdb

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

system/extras/postbuild.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh -
22

33
BUILD_PATH="$1"
44
BUILD_SERIE="$2"

system/extras/prebuild.sh

+28-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh -
22

33
BUILD_PATH="$1"
44
BUILD_SOURCE_PATH="$2"
@@ -9,20 +9,38 @@ if [ ! -f "$BUILD_PATH/sketch" ]; then
99
mkdir -p "$BUILD_PATH/sketch"
1010
fi
1111

12-
# Create empty build.opt if build_opt.h does not exists in the original sketch dir
13-
# Then add or append -fmacro-prefix-map option to change __FILE__ absolute path of
14-
# the board platform folder to a relative path by using '.'.
15-
# (i.e. the folder containing boards.txt)
12+
# Create empty build.opt or clear it if build_opt.h does not exists in the original sketch dir
1613
if [ ! -f "$BUILD_SOURCE_PATH/build_opt.h" ]; then
17-
printf '\n-fmacro-prefix-map="%s"=.' "${BOARD_PLATFORM_PATH//\\/\\\\}" > "$BUILD_PATH/sketch/build.opt"
14+
true >"$BUILD_PATH/sketch/build.opt"
1815
else
1916
# Else copy the build_opt.h as build.opt
2017
# Workaround to the header file preprocessing done by arduino-cli
2118
# See https://github.com/arduino/arduino-cli/issues/1338
22-
cp "$BUILD_SOURCE_PATH/build_opt.h" "$BUILD_PATH/sketch/build.opt"
23-
printf '\n-fmacro-prefix-map="%s"=.' "${BOARD_PLATFORM_PATH//\\/\\\\}" >> "$BUILD_PATH/sketch/build.opt"
19+
cp -f "$BUILD_SOURCE_PATH/build_opt.h" "$BUILD_PATH/sketch/build.opt"
2420
fi
25-
21+
# On Windows, need to protect '\' in path
22+
UNAME_OS="$(uname -s)"
23+
case "${UNAME_OS}" in
24+
Windows*)
25+
i=1
26+
prefix=""
27+
while [ "$i" -le "${#BOARD_PLATFORM_PATH}" ]; do
28+
c=$(printf '%s' "$BOARD_PLATFORM_PATH" | cut -c $i)
29+
prefix=${prefix}${c}
30+
if [ "${c}" = "\\" ]; then
31+
prefix=${prefix}"\\"
32+
fi
33+
i="$((i + 1))"
34+
done
35+
;;
36+
*)
37+
prefix=${BOARD_PLATFORM_PATH}
38+
;;
39+
esac
40+
# Then append -fmacro-prefix-map option to change __FILE__ absolute path of
41+
# the board platform folder to a relative path by using '.'.
42+
# (i.e. the folder containing boards.txt)
43+
printf '\n-fmacro-prefix-map="%s"=.' "${prefix}" >>"$BUILD_PATH/sketch/build.opt"
2644

2745
# Force include of SrcWrapper library
28-
echo "#include <SrcWrapper.h>" > "$BUILD_PATH/sketch/SrcWrapper.cpp"
46+
echo "#include <SrcWrapper.h>" >"$BUILD_PATH/sketch/SrcWrapper.cpp"

0 commit comments

Comments
 (0)