Skip to content

Commit bf98c16

Browse files
committed
πŸ§‘β€πŸ’» Improve scripts to build examples
1 parent 72603b6 commit bf98c16

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

β€Žbuildroot/bin/build_all_examples

+9-3
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ fi
151151
echo -e "=====================\nProceed with builds...\n====================="
152152
shopt -s nullglob
153153

154+
export PAUSE=1
155+
154156
# Get a list of all folders that contain a file matching "Configuration*.h"
155-
find -ds "$CBASE"/config/examples -type d -name 'Configuration.h' -o -name 'Configuration_adv.h' -print0 | while IFS= read -r -d '' CONF; do
157+
find -ds "$CBASE"/config/examples -type d -name 'Configuration.h' -o -name 'Configuration_adv.h' -print0 | while IFS= read -r -d $'\0' CONF; do
156158

157159
# Remove the file name and slash from the end of the path
158160
CONF=${CONF%/*}
@@ -198,10 +200,14 @@ find -ds "$CBASE"/config/examples -type d -name 'Configuration.h' -o -name 'Conf
198200
fi
199201

200202
echo
201-
((--LIMIT)) || { echo "Specified limit reached" ; PAUSE=1 ; break ; }
203+
((--LIMIT)) || { echo "Specified limit reached" ; break ; }
202204
echo
203205

206+
export PAUSE=0
207+
204208
done
205209

210+
echo "Exiting"
211+
206212
# Delete the build state if not paused early
207-
[[ $PAUSE ]] || rm -f "$STAT_FILE"
213+
((PAUSE)) || rm -f "$STAT_FILE"

β€Žbuildroot/bin/build_example

+45-35
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ PATH="$HERE:$PATH"
3737
. mfutil
3838

3939
annc() { echo -e "\033[0;32m$1\033[0m" ; }
40+
alrt() { echo -e "\033[0;31m$1\033[0m" ; }
4041

4142
# Get arguments
4243
BUILD=./.pio/build
@@ -153,8 +154,7 @@ ENAME=("-name" "marlin_config.json" \
153154
"-o" "-name" "schema.yml")
154155

155156
# Possible built firmware names (in the build folder)
156-
BNAME=("-type" "f" \
157-
"-name" 'firmware*.hex' \
157+
BNAME=("-name" 'firmware*.hex' \
158158
"-o" "-name" "firmware*.bin" \
159159
"-o" "-name" "project*.bin" \
160160
"-o" "-name" "Robin*.bin" \
@@ -176,44 +176,54 @@ set +e
176176
echo "Building example $CONFIG ..."
177177
mftest -s -a -n1 ; ERR=$?
178178

179-
((ERR)) && echo "Failed" || echo "Success"
179+
((ERR)) && alrt "Failed ($ERR)" || annc "Success"
180180

181181
set -e
182182

183-
# Copy exports back to the configs
184-
if [[ -n $EXPNUM ]]; then
185-
annc "Exporting $EXPNUM"
186-
[[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$ARCSUB"/Config.h ; }
187-
find "$BUILD" "${ENAME[@]}" -exec cp "{}" "$ARCSUB" \;
188-
fi
183+
if [[ $ERR -gt 0 ]]; then
189184

190-
# Copy potential firmware files into the config folder
191-
# TODO: Consider firmware that needs an STM32F4_UPDATE folder.
192-
# Currently only BOARD_CREALITY_F401RE env:STM32F401RE_creality
193-
if ((ARCHIVE)); then
194-
annc "Archiving"
195-
rm -f "$ARCSUB"/*.bin.tar.gz "$ARCSUB"/*.hex.tar.gz
196-
find "$BUILD" \( "${BNAME[@]}" \) -exec sh -c '
197-
ARCSUB="$1"
198-
CONFIG="$2"
199-
shift 2
200-
for FILE in "$@"; do
201-
cd "${FILE%/*}"
202-
BASE=${FILE##*/}
203-
SHRT=${BASE%.*}
204-
SHASUM=$(sha256sum "$BASE" | cut -d" " -f1)
205-
tar -czf "$ARCSUB/$SHRT.tar.gz" "$BASE"
206-
echo "$CONFIG\n$SHASUM" > "$ARCSUB/$BASE.sha256.txt"
207-
rm "$BASE"
208-
cd - >/dev/null
209-
done
210-
' sh "$ARCSUB" "$CONFIG" {} +
211-
fi
185+
# Error? For --nofail simply log. Otherwise return the error.
186+
if [[ -n $NOFAIL ]]; then
187+
date +"%F %T [FAIL] $CONFIG" >>./.pio/error-log.txt
188+
else
189+
exit $ERR
190+
fi
212191

213-
# Exit with error unless --nofail is set
214-
[[ $ERR -gt 0 && -z $NOFAIL ]] && exit $ERR
192+
else
215193

216-
# Reveal the configs after the build, if requested
217-
((REVEAL)) && { annc "Revealing $ARCSUB" ; open "$ARCSUB" ; }
194+
# Copy exports back to the configs
195+
if [[ -n $EXPNUM ]]; then
196+
annc "Exporting $EXPNUM"
197+
[[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$ARCSUB"/Config.h ; }
198+
find "$BUILD" \( "${ENAME[@]}" \) -exec cp "{}" "$ARCSUB" \;
199+
fi
200+
201+
# Copy potential firmware files into the config folder
202+
# TODO: Consider firmware that needs an STM32F4_UPDATE folder.
203+
# Currently only BOARD_CREALITY_F401RE env:STM32F401RE_creality
204+
if ((ARCHIVE)); then
205+
annc "Archiving"
206+
rm -f "$ARCSUB"/*.bin.tar.gz "$ARCSUB"/*.hex.tar.gz
207+
find "$BUILD" \( "${BNAME[@]}" \) -exec sh -c '
208+
ARCSUB="$1"
209+
CONFIG="$2"
210+
shift 2
211+
for FILE in "$@"; do
212+
cd "${FILE%/*}"
213+
NAME=${FILE##*/}
214+
SHRT=${NAME%.*}
215+
SHASUM=$(sha256sum "$NAME" | cut -d" " -f1)
216+
tar -czf "$ARCSUB/$SHRT.tar.gz" "$NAME"
217+
echo "$CONFIG\n$SHASUM" > "$ARCSUB/$NAME.sha256.txt"
218+
rm "$NAME"
219+
cd - >/dev/null
220+
done
221+
' sh "$ARCSUB" "$CONFIG" {} +
222+
fi
223+
224+
# Reveal the configs after the build, if requested
225+
((REVEAL)) && { annc "Revealing $ARCSUB" ; open "$ARCSUB" ; }
226+
227+
fi
218228

219229
exit 0

0 commit comments

Comments
Β (0)