Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Improve scripts to build examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Nov 19, 2024
1 parent 72603b6 commit bf98c16
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
12 changes: 9 additions & 3 deletions buildroot/bin/build_all_examples
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ fi
echo -e "=====================\nProceed with builds...\n====================="
shopt -s nullglob

export PAUSE=1

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

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

echo
((--LIMIT)) || { echo "Specified limit reached" ; PAUSE=1 ; break ; }
((--LIMIT)) || { echo "Specified limit reached" ; break ; }
echo

export PAUSE=0

done

echo "Exiting"

# Delete the build state if not paused early
[[ $PAUSE ]] || rm -f "$STAT_FILE"
((PAUSE)) || rm -f "$STAT_FILE"
80 changes: 45 additions & 35 deletions buildroot/bin/build_example
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ PATH="$HERE:$PATH"
. mfutil

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

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

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

((ERR)) && echo "Failed" || echo "Success"
((ERR)) && alrt "Failed ($ERR)" || annc "Success"

set -e

# 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" "${ENAME[@]}" -exec cp "{}" "$ARCSUB" \;
fi
if [[ $ERR -gt 0 ]]; then

# 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"
rm -f "$ARCSUB"/*.bin.tar.gz "$ARCSUB"/*.hex.tar.gz
find "$BUILD" \( "${BNAME[@]}" \) -exec sh -c '
ARCSUB="$1"
CONFIG="$2"
shift 2
for FILE in "$@"; do
cd "${FILE%/*}"
BASE=${FILE##*/}
SHRT=${BASE%.*}
SHASUM=$(sha256sum "$BASE" | cut -d" " -f1)
tar -czf "$ARCSUB/$SHRT.tar.gz" "$BASE"
echo "$CONFIG\n$SHASUM" > "$ARCSUB/$BASE.sha256.txt"
rm "$BASE"
cd - >/dev/null
done
' sh "$ARCSUB" "$CONFIG" {} +
fi
# Error? For --nofail simply log. Otherwise return the error.
if [[ -n $NOFAIL ]]; then
date +"%F %T [FAIL] $CONFIG" >>./.pio/error-log.txt
else
exit $ERR
fi

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

# Reveal the configs after the build, if requested
((REVEAL)) && { annc "Revealing $ARCSUB" ; open "$ARCSUB" ; }
# 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" \( "${ENAME[@]}" \) -exec cp "{}" "$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"
rm -f "$ARCSUB"/*.bin.tar.gz "$ARCSUB"/*.hex.tar.gz
find "$BUILD" \( "${BNAME[@]}" \) -exec sh -c '
ARCSUB="$1"
CONFIG="$2"
shift 2
for FILE in "$@"; do
cd "${FILE%/*}"
NAME=${FILE##*/}
SHRT=${NAME%.*}
SHASUM=$(sha256sum "$NAME" | cut -d" " -f1)
tar -czf "$ARCSUB/$SHRT.tar.gz" "$NAME"
echo "$CONFIG\n$SHASUM" > "$ARCSUB/$NAME.sha256.txt"
rm "$NAME"
cd - >/dev/null
done
' sh "$ARCSUB" "$CONFIG" {} +
fi

# Reveal the configs after the build, if requested
((REVEAL)) && { annc "Revealing $ARCSUB" ; open "$ARCSUB" ; }

fi

exit 0

0 comments on commit bf98c16

Please sign in to comment.