🔨 Add build_example --noxfer flag
Some checks are pending
CI - Build Tests / Build Test (push) Waiting to run
CI - Unit Tests / Unit Test (push) Waiting to run
CI - Validate Source Files / Validate Source Files (push) Waiting to run

This commit is contained in:
Scott Lahteine 2025-12-24 17:02:24 -06:00
parent 4fccfa14e9
commit 3ac9068e0e

View file

@ -11,6 +11,7 @@
# [-o|--output] - Redirect export / archiving to another location
# (By default export to origin config folder)
# [-f|--nofail] - Don't stop on a failed build
# [-x|--noxfer] - Skip the build if the env ends with _xfer. Implied with --many.
# [-w|--nowarn] - Suppress warnings with extra config options
# [-r|--reveal] - Reveal the config/export folder after the build
# [-h|--help] - Print usage and exit
@ -28,6 +29,7 @@ build_example -b|--base=<path> - Configurations root folder (e.g., ./.pio/bu
[-o|--output] - Redirect export / archiving to another location
(By default export to origin config folder)
[-f|--nofail] - Don't stop on a failed build
[-x|--noxfer] - Skip the build if the env ends with _xfer. Implied with --many.
[-w|--nowarn] - Suppress warnings with extra config options
[-r|--reveal] - Reveal the config/export folder after the build
[-h|--help] - Print usage and exit
@ -56,8 +58,9 @@ NOFAIL=
OUTBASE=
BUILDINDEX=1
MANY=
NOXFER=
while getopts 'ab:c:e:fhmn:o:r-:' OFLAG; do
while getopts 'ab:c:e:fhmn:o:r-:x' OFLAG; do
case "${OFLAG}" in
a) ARCHIVE=1 ;;
b) BASE="${OPTARG%/}" ;;
@ -65,23 +68,25 @@ while getopts 'ab:c:e:fhmn:o:r-:' OFLAG; do
e) EXPNUM="$OPTARG" ;;
f) NOFAIL=1 ;;
h) EXIT_USAGE=1 ; break ;;
m) MANY=1 ;;
m) MANY=1 ; NOXFER=1 ;;
n) BUILDINDEX="$OPTARG" ;;
o) OUTBASE="${OPTARG%/}" ;;
r) REVEAL=1 ;;
x) NOXFER=1 ;;
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
case "$ONAM" in
archive) ARCHIVE=1 ;;
allow) ALLOW=1 ;;
base) BASE="${OVAL%/}" ;;
config) CONFIG="${OVAL%/}" ;;
many) MANY=1 ;;
many) MANY=1 ; NOXFER=1 ;;
index) BUILDINDEX="$OVAL" ;;
export) EXPNUM="$OVAL" ;;
output) OUTBASE="${OVAL%/}" ;;
help) EXIT_USAGE=1 ; break ;;
nofail) NOFAIL=1 ;;
reveal) REVEAL=1 ;;
noxfer) NOXFER=1 ;;
*) EXIT_USAGE=2 ; echo "$SELF: unrecognized option \`--$ONAM'" ; break ;;
esac
;;
@ -203,83 +208,89 @@ fi
while true; do
set +e
# Skip over "_xfer" environments when building many
((MANY)) && [[ ${ENVARRAY[BUILDINDEX-1]} =~ _xfer$ ]] && { ((BUILDINDEX++)) ; continue; }
# Skip over "_xfer" environments when specified
if [[ -n $NOXFER && ${ENVARRAY[BUILDINDEX-1]} =~ _xfer$ ]]; then
echo "Building example $CONFIG ($BUILDINDEX)..."
# Run a build and record the error number
mftest -s -a -n$BUILDINDEX ; ERR=$?
# "Index out of range" can fail without an error
((MANY)) && ((ERR == 66)) && ERR=0 && break # "index out of range"
set -e
if [[ $ERR -gt 0 ]]; then
alrt "Failed ($ERR)"
# Error? For --nofail simply log. Otherwise return the error.
if [[ -n $NOFAIL ]]; then
date +"%F %T [FAIL] $CONFIG ($BUILDINDEX)" >>./.pio/error-log.txt
else
exit $ERR
fi
echo "Skipping example $CONFIG ($BUILDINDEX)..."
else
annc "Success"
echo "Building example $CONFIG ($BUILDINDEX)..."
# Copy exports back to the configs
if [[ -n $EXPNUM ]]; then
annc "Exporting $EXPNUM"
[[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$ARCSUB"/Config.h ; }
find "$BUILD" -type f \( "${ENAME[@]}" \) -exec cp "{}" "$ARCSUB" \;
fi
# Run a build and record the error number
mftest -s -a -n$BUILDINDEX ; ERR=$?
# "Index out of range" can fail without an error
((MANY)) && ((ERR == 66)) && ERR=0 && break # "index out of range"
set -e
if [[ $ERR -gt 0 ]]; then
alrt "Failed ($ERR)"
# Error? For --nofail simply log. Otherwise return the error.
if [[ -n $NOFAIL ]]; then
date +"%F %T [FAIL] $CONFIG ($BUILDINDEX)" >>./.pio/error-log.txt
else
exit $ERR
fi
# When building many, create sub-folders for each build env name
if [[ -n $MANY ]]; then
ENV=${ENVARRAY[BUILDINDEX-1]}
ARCENVSUB="$ARCSUB/$ENV"
else
ARCENVSUB="$ARCSUB"
fi
# Copy potential firmware files into the config folder
# TODO: Consider firmware that needs an STM32F4_UPDATE folder.
# Currently only BOARD_CREALITY_F401RE env:STM32F401RE_creality
if ((ARCHIVE)); then
annc "Archiving"
find "$BUILD" -type f \( "${BNAME[@]}" \) -exec sh -c '
ARCDIR="$1" ; CONFIG="$2" ; FILE="$3" ; shift 3
NAME=${FILE##*/} ; SHRT=${NAME%.*} ; DIR=${FILE%/*}
ZIPX=
if [[ $CONFIG == *Simulator* ]]; then
case $(uname | tr '[:upper:]' '[:lower:]') in
darwin) SUB="macOS" ; ZIPX="-X" ;;
*linux) SUB="Linux" ;;
win*) SUB="Windows" ;;
msys*) SUB="Windows" ;;
cygwin*) SUB="Windows" ;;
mingw*) SUB="Windows" ;;
*) SUB='Unix' ;;
esac
ARCH=$(uname -m | tr '[:lower:]' '[:upper:]')
ARCDIR="$ARCDIR/$SUB-$ARCH"
fi
mkdir -p "$ARCDIR"
rm -f "$ARCDIR"/*.zip "$ARCDIR"/*.sha256.txt
cd "$DIR"
SHASUM=$(sha256sum "$NAME" | cut -d" " -f1)
echo "$CONFIG\n$SHASUM" > "$ARCDIR/$NAME.sha256.txt"
zip $ZIPX "$ARCDIR/$SHRT.zip" "$NAME" && rm "$NAME"
cd - >/dev/null
' sh "$ARCENVSUB" "$CONFIG" {} +
fi
annc "Success"
# Reveal the configs after the build, if requested
((REVEAL)) && { annc "Revealing $ARCENVSUB" ; open "$ARCENVSUB" ; }
# Copy exports back to the configs
if [[ -n $EXPNUM ]]; then
annc "Exporting $EXPNUM"
[[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$ARCSUB"/Config.h ; }
find "$BUILD" -type f \( "${ENAME[@]}" \) -exec cp "{}" "$ARCSUB" \;
fi
# When building many, create sub-folders for each build env name
if [[ -n $MANY ]]; then
ENV=${ENVARRAY[BUILDINDEX-1]}
ARCENVSUB="$ARCSUB/$ENV"
else
ARCENVSUB="$ARCSUB"
fi
# Copy potential firmware files into the config folder
# TODO: Consider firmware that needs an STM32F4_UPDATE folder.
# Currently only BOARD_CREALITY_F401RE env:STM32F401RE_creality
if ((ARCHIVE)); then
annc "Archiving"
find "$BUILD" -type f \( "${BNAME[@]}" \) -exec sh -c '
ARCDIR="$1" ; CONFIG="$2" ; FILE="$3" ; shift 3
NAME=${FILE##*/} ; SHRT=${NAME%.*} ; DIR=${FILE%/*}
ZIPX=
if [[ $CONFIG == *Simulator* ]]; then
case $(uname | tr '[:upper:]' '[:lower:]') in
darwin) SUB="macOS" ; ZIPX="-X" ;;
*linux) SUB="Linux" ;;
win*) SUB="Windows" ;;
msys*) SUB="Windows" ;;
cygwin*) SUB="Windows" ;;
mingw*) SUB="Windows" ;;
*) SUB='Unix' ;;
esac
ARCH=$(uname -m | tr '[:lower:]' '[:upper:]')
ARCDIR="$ARCDIR/$SUB-$ARCH"
fi
mkdir -p "$ARCDIR"
rm -f "$ARCDIR"/*.zip "$ARCDIR"/*.sha256.txt
cd "$DIR"
SHASUM=$(sha256sum "$NAME" | cut -d" " -f1)
echo "$CONFIG\n$SHASUM" > "$ARCDIR/$NAME.sha256.txt"
zip $ZIPX "$ARCDIR/$SHRT.zip" "$NAME" && rm "$NAME"
cd - >/dev/null
' sh "$ARCENVSUB" "$CONFIG" {} +
fi # ARCHIVE
# Reveal the configs after the build, if requested
((REVEAL)) && { annc "Revealing $ARCENVSUB" ; open "$ARCENVSUB" ; }
fi # Success
fi