🧑‍💻 Improve build_example

This commit is contained in:
Scott Lahteine 2024-08-26 12:58:04 -05:00
parent 90e5826256
commit fe56f5d3a6
3 changed files with 75 additions and 50 deletions

View file

@ -51,13 +51,13 @@ LIMIT=1000
while getopts 'aB:b:ce:fdhl:npr:sv-:' OFLAG; do while getopts 'aB:b:ce:fdhl:npr:sv-:' OFLAG; do
case "${OFLAG}" in case "${OFLAG}" in
a) ARCHIVE=1 ; bugout "Archiving" ;; a) ARCHIVE=1 ; bugout "Archiving" ;;
B) OPATH="$OPTARG" ; bugout "Base: $OPATH" ;; B) OPATH=$OPTARG ; bugout "Base: $OPATH" ;;
b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;; b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
f) NOFAIL=1 ; bugout "Continue on Fail" ;; f) NOFAIL=1 ; bugout "Continue on Fail" ;;
r) ISRES=1 ; FIRST_CONF="$OPTARG" ; bugout "Resume: $FIRST_CONF" ;; r) ISRES=1 ; FIRST_CONF=$OPTARG ; bugout "Resume: $FIRST_CONF" ;;
c) CONTINUE=1 ; bugout "Continue" ;; c) CONTINUE=1 ; bugout "Continue" ;;
s) CONTSKIP=1 ; bugout "Continue, skipping" ;; s) CONTSKIP=1 ; bugout "Continue, skipping" ;;
e) CEXPORT="$OPTARG" ; bugout "Export $CEXPORT" ;; e) CEXPORT=$OPTARG ; bugout "Export $CEXPORT" ;;
h) EXIT_USAGE=1 ; break ;; h) EXIT_USAGE=1 ; break ;;
l) LIMIT=$OPTARG ; bugout "Limit to $LIMIT build(s)" ;; l) LIMIT=$OPTARG ; bugout "Limit to $LIMIT build(s)" ;;
d|v) DEBUG=1 ; bugout "Debug ON" ;; d|v) DEBUG=1 ; bugout "Debug ON" ;;
@ -66,13 +66,13 @@ while getopts 'aB:b:ce:fdhl:npr:sv-:' OFLAG; do
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG" -) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
case "$ONAM" in case "$ONAM" in
archive) ARCHIVE=1 ; bugout "Archiving" ;; archive) ARCHIVE=1 ; bugout "Archiving" ;;
base) OPATH="$OVAL" ; bugout "Base: $OPATH" ;; base) OPATH=$OVAL ; bugout "Base: $OPATH" ;;
branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;; branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
nofail) NOFAIL=1 ; bugout "Continue on Fail" ;; nofail) NOFAIL=1 ; bugout "Continue on Fail" ;;
resume) ISRES=1 ; FIRST_CONF="$OVAL" ; bugout "Resume: $FIRST_CONF" ;; resume) ISRES=1 ; FIRST_CONF=$OVAL ; bugout "Resume: $FIRST_CONF" ;;
continue) CONTINUE=1 ; bugout "Continue" ;; continue) CONTINUE=1 ; bugout "Continue" ;;
skip) CONTSKIP=1 ; bugout "Continue, skipping" ;; skip) CONTSKIP=1 ; bugout "Continue, skipping" ;;
export) CEXPORT="$OVAL"; bugout "Export $EXPORT" ;; export) CEXPORT=$OVAL ; bugout "Export $EXPORT" ;;
limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT build(s)" ;; limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT build(s)" ;;
help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;; help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
debug) DEBUG=1 ; bugout "Debug ON" ;; debug) DEBUG=1 ; bugout "Debug ON" ;;
@ -98,7 +98,7 @@ echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
echo echo
[[ -n $PURGE ]] && rm -f "$STAT_FILE" [[ -n $PURGE ]] && rm -f "$STAT_FILE"
[[ -z $FIRST_CONF && -f $STAT_FILE ]] && IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE" [[ -z $FIRST_CONF && -f "$STAT_FILE" ]] && IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
# If -c is given start from the last attempted build # If -c is given start from the last attempted build
if ((CONTINUE)); then if ((CONTINUE)); then
@ -126,29 +126,29 @@ fi
# Create a temporary folder inside .pio # Create a temporary folder inside .pio
if [[ -n $OPATH ]]; then if [[ -n $OPATH ]]; then
TMP=$OPATH [[ -d "$OPATH" ]] || { echo "Given base -B $OPATH not found." ; exit ; }
[[ -d "$TMP" ]] || { echo "Given base -B $TMP not found." ; exit ; }
else else
# Make a Configurations temporary folder if needed # Make a Configurations temporary folder if needed
TMP=./.pio/build-$BRANCH OPATH=./.pio/build-$BRANCH
[[ -d "$TMP" ]] || mkdir -p $TMP [[ -d "$OPATH" ]] || mkdir -p "$OPATH"
# Download the specified Configurations branch if needed # Download the specified Configurations branch if needed
if [[ ! -e "$TMP/README.md" ]]; then if [[ ! -e "$OPATH/README.md" ]]; then
echo "Fetching Configurations from GitHub to $TMP" echo "Fetching Configurations from GitHub to $OPATH"
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$TMP" || { echo "Failed to clone the configuration repository"; exit ; } git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$OPATH" || { echo "Failed to clone the configuration repository"; exit ; }
fi fi
fi fi
# Build # Build
echo -e "=====================\nProceed with builds...\n=====================" echo -e "=====================\nProceed with builds...\n====================="
shopt -s nullglob shopt -s nullglob
shopt -s globstar
IFS=' IFS='
' '
CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" ) CONF_TREE=$( ls -d "$OPATH"/config/examples/**/ | grep -vE ".+\.(\w+)$" )
for CONF in $CONF_TREE ; do for CONF in $CONF_TREE ; do
# Get a config's directory name # Get a config's directory name
DIR=$( echo $CONF | "$SED" "s|$TMP/config/examples/||" ) DIR=$( echo "$CONF" | "$SED" "s|$OPATH/config/examples/||" )
# If looking for a config, skip others # If looking for a config, skip others
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
@ -159,10 +159,10 @@ for CONF in $CONF_TREE ; do
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; } [[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
# At least one config file is required here # At least one config file is required here
compgen -G "${CONF}Con*.h" > /dev/null || continue compgen -G "${CONF}Configuration*.h" > /dev/null || continue
# Command arguments for 'build_example' # Command arguments for 'build_example'
CARGS=("-b" "$TMP" "-c" "$DIR") CARGS=("-b" "$OPATH" "-c" "$DIR")
# Exporting? Add -e argument # Exporting? Add -e argument
((CEXPORT)) && CARGS+=("-e" "$CEXPORT") ((CEXPORT)) && CARGS+=("-e" "$CEXPORT")
@ -174,7 +174,7 @@ for CONF in $CONF_TREE ; do
((ARCHIVE)) && CARGS+=("-a") ((ARCHIVE)) && CARGS+=("-a")
# Build or print build command for --nobuild # Build or print build command for --nobuild
if [[ $DRYRUN ]]; then if ((DRYRUN)); then
echo -e "\033[0;32m[DRYRUN] build_example ${CARGS[@]}\033[0m" echo -e "\033[0;32m[DRYRUN] build_example ${CARGS[@]}\033[0m"
else else
# Remember where we are in case of failure # Remember where we are in case of failure

View file

@ -19,19 +19,20 @@ source "$HERE/mfutil"
annc() { echo -e "\033[0;32m$1\033[0m" ; } annc() { echo -e "\033[0;32m$1\033[0m" ; }
# Get arguments # Get arguments
CLEANER=1 BUILD=./.pio/build
ALLOW="" CLEANER=
ARCHIVE="" ALLOW=
BASE="" ARCHIVE=
CONFIG="" BASE=
REVEAL="" CONFIG=
EXPNUM="" REVEAL=
NOFAIL="" EXPNUM=
NOFAIL=
while getopts 'ab:c:e:hinr-:' OFLAG; do while getopts 'ab:c:e:hinr-:' OFLAG; do
case "${OFLAG}" in case "${OFLAG}" in
a) ARCHIVE=1 ;; a) ARCHIVE=1 ;;
b) BASE="$OPTARG" ;; b) BASE="${OPTARG%/}" ;;
c) CONFIG="$OPTARG" ;; c) CONFIG="${OPTARG%/}" ;;
e) EXPNUM="$OPTARG" ;; e) EXPNUM="$OPTARG" ;;
h) EXIT_USAGE=1 ; break ;; h) EXIT_USAGE=1 ; break ;;
n) NOFAIL=1 ;; n) NOFAIL=1 ;;
@ -40,8 +41,8 @@ while getopts 'ab:c:e:hinr-:' OFLAG; do
case "$ONAM" in case "$ONAM" in
archive) ARCHIVE=1 ;; archive) ARCHIVE=1 ;;
allow) ALLOW=1 ;; allow) ALLOW=1 ;;
base) BASE="$OVAL" ;; base) BASE="${OVAL%/}" ;;
config) CONFIG="$OVAL" ;; config) CONFIG="${OVAL%/}" ;;
export) EXPNUM="$OVAL" ;; export) EXPNUM="$OVAL" ;;
help) EXIT_USAGE=1 ; break ;; help) EXIT_USAGE=1 ; break ;;
nofail) NOFAIL=1 ;; nofail) NOFAIL=1 ;;
@ -52,28 +53,32 @@ while getopts 'ab:c:e:hinr-:' OFLAG; do
esac esac
done done
# Must be called from another script (or with --allow)
[[ $ALLOW || $SHLVL -gt 2 ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; } [[ $ALLOW || $SHLVL -gt 2 ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; }
# -b|--base and -c|--config are required
[[ -z $BASE ]] && { echo "-b|--base is required" ; exit 1 ; }
[[ -z $CONFIG ]] && { echo "-c|--config is required" ; exit 1 ; }
# Make sure the examples exist # Make sure the examples exist
SUB1="$BASE/config/examples" SUB1="$BASE/config/examples"
[[ -d "$SUB1" ]] || { echo "--base $BASE doesn't contain config/examples" ; exit 1 ; } [[ -d "$SUB1" ]] || { echo "-b|--base $BASE doesn't contain config/examples" ; exit 1 ; }
# Make sure the specific config folder exists # Make sure the specific config folder exists
SUB="$SUB1/$CONFIG" SUB="$SUB1/$CONFIG"
[[ -d "$SUB" ]] || { echo "--config $CONFIG doesn't exist" ; exit 1 ; } [[ -d "$SUB" ]] || { echo "-c|--config $CONFIG doesn't exist" ; exit 1 ; }
compgen -G "${SUB}Con*.h" > /dev/null || { echo "No configuration files found in $SUB" ; exit 1 ; } # ...and contains Configuration.h or Configuration_adv.h
[[ -n $(compgen -G "$SUB/Configuration*.h") ]] || { echo "No configuration files found in $SUB" ; exit 1 ; }
# Delete any previous exported configs # Delete any config files from previous builds
rm -f Marlin/Config.h Marlin/Config-export.h rm -f Marlin/_Bootscreen.h Marlin/_Statusscreen.h
# Copy configurations into the Marlin folder
echo "Getting configuration files from $SUB" echo "Getting configuration files from $SUB"
cp "$BASE/config/default"/*.h Marlin/ cp "$BASE/config/default"/*.h "$SUB"/*.h Marlin/ 2>/dev/null
cp "$SUB"/Config.h Marlin/ 2>/dev/null
cp "$SUB"/Configuration.h Marlin/ 2>/dev/null rm -f Marlin/Config.h Marlin/Config-export.h
cp "$SUB"/Configuration_adv.h Marlin/ 2>/dev/null
cp "$SUB"/_Bootscreen.h Marlin/ 2>/dev/null
cp "$SUB"/_Statusscreen.h Marlin/ 2>/dev/null
set -e set -e
@ -99,28 +104,35 @@ if ((CLEANER)); then
opt_add NO_HOMING_CURRENT_WARNING opt_add NO_HOMING_CURRENT_WARNING
fi fi
FNAME=("-name" "marlin_config.json" \ ENAME=("-name" "marlin_config.json" \
"-o" "-name" "config.ini" \ "-o" "-name" "config.ini" \
"-o" "-name" "schema.json" \ "-o" "-name" "schema.json" \
"-o" "-name" "schema.yml") "-o" "-name" "schema.yml")
BNAME=("-name" "*.bin" "-o" "-name" "*.hex") BNAME=("-type" "f" \
"-name" 'firmware*.hex' \
"-o" "-name" "firmware*.bin" \
"-o" "-name" "project*.bin" \
"-o" "-name" "Robin*.bin" \
"-o" "-name" "main_*.bin")
mkdir -p "$BUILD"
# If EXPNUM is set then apply to the config before build # If EXPNUM is set then apply to the config before build
if [[ $EXPNUM ]]; then if [[ $EXPNUM ]]; then
opt_set CONFIG_EXPORT $EXPNUM opt_set CONFIG_EXPORT $EXPNUM
# Clean up old exports # Clean up old exports
find ./.pio/build \( "${FNAME[@]}" \) -exec rm "{}" \; find "$BUILD" \( "${ENAME[@]}" \) -exec rm "{}" \;
fi fi
((ARCHIVE)) && find ./.pio/build \( "${BNAME[@]}" \) -exec rm "{}" \; ((ARCHIVE)) && find "$BUILD" \( "${BNAME[@]}" \) -exec rm "{}" \;
set +e set +e
echo "Building example $CONFIG ..." echo "Building example $CONFIG ..."
"$HERE/mftest" -s -a -n1 ; ERR=$? "$HERE/mftest" -s -a -n1 ; ERR=$?
[[ $ERR -eq 0 ]] && echo "Success" || echo "Failed" ((ERR)) && echo "Failed" || echo "Success"
set -e set -e
@ -128,10 +140,23 @@ set -e
if [[ -n $EXPNUM ]]; then if [[ -n $EXPNUM ]]; then
annc "Exporting $EXPNUM" annc "Exporting $EXPNUM"
[[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$SUB"/Config.h ; } [[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$SUB"/Config.h ; }
find ./.pio/build/ "${FNAME[@]}" -exec cp "{}" "$SUB" \; find "$BUILD" "${ENAME[@]}" -exec cp "{}" "$SUB" \;
fi fi
((ARCHIVE)) && { annc "Archiving" ; find ./.pio/build \( "${BNAME[@]}" \) -exec cp "{}" "$SUB" \; ; } if ((ARCHIVE)); then
annc "Archiving"
find "$BUILD" \( "${BNAME[@]}" \) -exec sh -c '
SUB="$1"
shift 1
for file in "$@"; do
cd "$(dirname "$file")"
base=$(basename "$file")
tar -czf "$SUB/$base.tar.gz" "$base"
rm "$base"
cd - >/dev/null
done
' sh "$SUB" {} +
fi
# Exit with error unless --nofail is set # Exit with error unless --nofail is set
[[ $ERR -gt 0 && -z $NOFAIL ]] && exit $ERR [[ $ERR -gt 0 && -z $NOFAIL ]] && exit $ERR

View file

@ -216,7 +216,7 @@ def compute_build_signature(env):
if not conf_schema: exit(1) if not conf_schema: exit(1)
# Start with a preferred @section ordering # Start with a preferred @section ordering
preorder = ('info','machine','extruder','stepper drivers','geometry','homing','endstops','probes','lcd','interface','host','reporting') preorder = ('info','user','machine','extruder','bed temp','fans','stepper drivers','geometry','homing','endstops','probes','lcd','interface','host','reporting')
sections = { key:{} for key in preorder } sections = { key:{} for key in preorder }
# Group options by schema @section # Group options by schema @section