From 3ac9068e0e8f6a7f46024b4cc4dcbfa503c4fe52 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 24 Dec 2025 17:02:24 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Add=20build=5Fexample=20--noxfer?= =?UTF-8?q?=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildroot/bin/build_example | 153 +++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 71 deletions(-) diff --git a/buildroot/bin/build_example b/buildroot/bin/build_example index d96047874c..809f3d565e 100755 --- a/buildroot/bin/build_example +++ b/buildroot/bin/build_example @@ -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= - 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