2021-02-15 11:48:11 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-02-17 00:41:00 +00:00
|
|
|
#
|
2022-07-23 00:30:29 +00:00
|
|
|
# Usage:
|
|
|
|
#
|
2024-08-24 20:56:47 +00:00
|
|
|
# build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo (import-2.1.x)
|
2024-08-26 04:03:18 +00:00
|
|
|
# [-B|--base] - Base path of configurations, overriding -b
|
2022-07-26 19:54:54 +00:00
|
|
|
# [-c|--continue] - Continue the paused build
|
2024-08-24 20:56:47 +00:00
|
|
|
# [-p|--purge] - Purge the status file and start over
|
|
|
|
# [-s|--skip] - Continue the paused build, skipping one
|
2022-07-26 19:54:54 +00:00
|
|
|
# [-r|--resume=<path>] - Start at some config in the filesystem order
|
2024-08-24 20:56:47 +00:00
|
|
|
# [-l|--limit=#] - Limit the number of builds in this run
|
2024-09-01 21:34:35 +00:00
|
|
|
# [-d|--debug] - Print extra debug output (after)
|
2024-08-24 20:56:47 +00:00
|
|
|
# [-n|--nobuild] - Don't actually build anything
|
|
|
|
# [-f|--nofail] - Don't stop on a failed build
|
2024-09-01 21:34:35 +00:00
|
|
|
# [-e|--export=N] - Set CONFIG_EXPORT and export into each config folder
|
|
|
|
# [-a|--archive] - Copy the binary to the export location
|
|
|
|
# [-o|--output] - Redirect export / archiving to another location
|
|
|
|
# (By default export to origin config folders)
|
2024-08-24 20:56:47 +00:00
|
|
|
# [-h|--help] - Print usage and exit
|
2021-02-17 00:41:00 +00:00
|
|
|
#
|
2021-02-15 11:48:11 +00:00
|
|
|
|
2024-01-23 05:31:04 +00:00
|
|
|
HERE=`dirname $0`
|
2024-09-16 20:36:39 +00:00
|
|
|
PATH="$HERE:$PATH"
|
2024-01-23 05:31:04 +00:00
|
|
|
|
2024-09-16 20:36:39 +00:00
|
|
|
. mfutil
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2021-02-17 00:41:00 +00:00
|
|
|
GITREPO=https://github.com/MarlinFirmware/Configurations.git
|
|
|
|
STAT_FILE=./.pio/.buildall
|
2021-02-15 11:48:11 +00:00
|
|
|
|
2024-08-24 20:56:47 +00:00
|
|
|
usage() { echo "Usage:
|
|
|
|
|
|
|
|
build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo (import-2.1.x)
|
2024-08-26 04:03:18 +00:00
|
|
|
[-B|--base] - Base path of configurations, overriding -b
|
2024-08-24 20:56:47 +00:00
|
|
|
[-c|--continue] - Continue the paused build
|
|
|
|
[-p|--purge] - Purge the status file and start over
|
|
|
|
[-s|--skip] - Continue the paused build, skipping one
|
|
|
|
[-r|--resume=<path>] - Start at some config in the filesystem order
|
2024-09-01 21:34:35 +00:00
|
|
|
[-e|--export=N] - Set CONFIG_EXPORT and export to the export location
|
|
|
|
[-a|--archive] - Copy the binary to the export location
|
|
|
|
[-o|--output] - Redirect export / archiving to another location
|
|
|
|
(By default export to origin config folders)
|
2024-08-24 20:56:47 +00:00
|
|
|
[-d|--debug] - Print extra debug output (after)
|
|
|
|
[-l|--limit=#] - Limit the number of builds in this run
|
|
|
|
[-n|--nobuild] - Don't actually build anything
|
|
|
|
[-f|--nofail] - Don't stop on a failed build
|
|
|
|
[-h|--help] - Print usage and exit
|
2022-07-23 00:30:29 +00:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Assume the most recent configs
|
|
|
|
BRANCH=import-2.1.x
|
|
|
|
unset FIRST_CONF
|
|
|
|
EXIT_USAGE=
|
|
|
|
LIMIT=1000
|
2021-02-15 11:48:11 +00:00
|
|
|
|
2024-09-01 21:34:35 +00:00
|
|
|
while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
|
2022-07-23 00:30:29 +00:00
|
|
|
case "${OFLAG}" in
|
2024-09-01 21:34:35 +00:00
|
|
|
a) ARCHIVE=1 ; bugout "Archiving" ;;
|
2024-09-16 20:36:39 +00:00
|
|
|
B) CBASE=${OPTARG%/} ; bugout "Base: $CBASE" ;;
|
2024-09-01 21:34:35 +00:00
|
|
|
b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
|
|
|
|
f) NOFAIL=1 ; bugout "Continue on Fail" ;;
|
2024-08-26 17:58:04 +00:00
|
|
|
r) ISRES=1 ; FIRST_CONF=$OPTARG ; bugout "Resume: $FIRST_CONF" ;;
|
2024-09-01 21:34:35 +00:00
|
|
|
c) CONTINUE=1 ; bugout "Continue" ;;
|
|
|
|
s) CONTSKIP=1 ; bugout "Continue, skipping" ;;
|
|
|
|
e) CEXPORT=$OPTARG ; bugout "Export $CEXPORT" ;;
|
|
|
|
o) OUTBASE="${OPTARG%/}" ; bugout "Archive to $OUTBASE" ;;
|
2022-07-23 00:30:29 +00:00
|
|
|
h) EXIT_USAGE=1 ; break ;;
|
2024-09-01 21:34:35 +00:00
|
|
|
l) LIMIT=$OPTARG ; bugout "Limit to $LIMIT build(s)" ;;
|
|
|
|
d|v) DEBUG=1 ; bugout "Debug ON" ;;
|
|
|
|
n) DRYRUN=1 ; bugout "Dry Run" ;;
|
|
|
|
p) PURGE=1 ; bugout "Purge stat file" ;;
|
2024-09-05 17:00:20 +00:00
|
|
|
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
|
2022-07-23 00:30:29 +00:00
|
|
|
case "$ONAM" in
|
2024-09-01 21:34:35 +00:00
|
|
|
archive) ARCHIVE=1 ; bugout "Archiving" ;;
|
2024-09-16 20:36:39 +00:00
|
|
|
base) CBASE=${OVAL%/} ; bugout "Base: $CBASE" ;;
|
2024-09-01 21:34:35 +00:00
|
|
|
branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
|
|
|
|
nofail) NOFAIL=1 ; bugout "Continue on Fail" ;;
|
2024-08-26 17:58:04 +00:00
|
|
|
resume) ISRES=1 ; FIRST_CONF=$OVAL ; bugout "Resume: $FIRST_CONF" ;;
|
2024-09-01 21:34:35 +00:00
|
|
|
continue) CONTINUE=1 ; bugout "Continue" ;;
|
|
|
|
skip) CONTSKIP=1 ; bugout "Continue, skipping" ;;
|
|
|
|
export) CEXPORT=$OVAL ; bugout "Export $EXPORT" ;;
|
|
|
|
output) OUTBASE="${OVAL%/}" ; bugout "Archive to $OUTBASE" ;;
|
|
|
|
limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT build(s)" ;;
|
2022-07-23 00:30:29 +00:00
|
|
|
help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
|
2024-09-01 21:34:35 +00:00
|
|
|
debug) DEBUG=1 ; bugout "Debug ON" ;;
|
|
|
|
nobuild) DRYRUN=1 ; bugout "Dry Run" ;;
|
|
|
|
purge) PURGE=1 ; bugout "Purge stat file" ;;
|
2022-07-23 00:30:29 +00:00
|
|
|
*) EXIT_USAGE=2 ; echo "$SELF: unrecognized option \`--$ONAM'" ; break ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*) EXIT_USAGE=2 ; break ;;
|
|
|
|
esac
|
|
|
|
done
|
2024-09-05 17:00:20 +00:00
|
|
|
shift $((OPTIND - 1))
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2024-08-24 20:56:47 +00:00
|
|
|
# Check for mixed continue, skip, resume arguments. Only one should be used.
|
|
|
|
((CONTINUE + CONTSKIP + ISRES + PURGE > 1)) && { echo "Don't mix -c, -p, -s, and -r options" ; echo ; EXIT_USAGE=2 ; }
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2024-08-24 20:56:47 +00:00
|
|
|
# Exit with helpful usage information
|
2022-07-23 00:30:29 +00:00
|
|
|
((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
|
|
|
|
|
2024-08-24 20:56:47 +00:00
|
|
|
echo
|
|
|
|
echo "This script downloads all example configs and attempts to build them."
|
|
|
|
echo "On failure the last-built configs are left in your working copy."
|
2021-02-17 00:41:00 +00:00
|
|
|
echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
|
2024-08-24 20:56:47 +00:00
|
|
|
echo
|
2021-02-17 00:41:00 +00:00
|
|
|
|
2024-08-24 20:56:47 +00:00
|
|
|
[[ -n $PURGE ]] && rm -f "$STAT_FILE"
|
2024-08-26 17:58:04 +00:00
|
|
|
[[ -z $FIRST_CONF && -f "$STAT_FILE" ]] && IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
|
2021-03-01 11:39:31 +00:00
|
|
|
|
2021-02-17 00:41:00 +00:00
|
|
|
# If -c is given start from the last attempted build
|
2022-07-23 00:30:29 +00:00
|
|
|
if ((CONTINUE)); then
|
2021-03-01 11:39:31 +00:00
|
|
|
if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
|
2021-02-17 00:41:00 +00:00
|
|
|
echo "Nothing to continue"
|
|
|
|
exit
|
|
|
|
fi
|
2022-07-23 00:30:29 +00:00
|
|
|
elif ((CONTSKIP)); then
|
2021-03-01 11:39:31 +00:00
|
|
|
if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
|
|
|
|
SKIP_CONF=1
|
|
|
|
else
|
|
|
|
echo "Nothing to skip"
|
|
|
|
exit
|
|
|
|
fi
|
2021-02-15 11:48:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if the current repository has unmerged changes
|
2024-08-24 20:56:47 +00:00
|
|
|
if ((SKIP_CONF)); then
|
2021-03-01 11:39:31 +00:00
|
|
|
echo "Skipping $FIRST_CONF"
|
2024-08-24 20:56:47 +00:00
|
|
|
elif [[ -n $FIRST_CONF ]]; then
|
2021-02-17 00:41:00 +00:00
|
|
|
echo "Resuming from $FIRST_CONF"
|
2021-03-01 11:39:31 +00:00
|
|
|
else
|
|
|
|
git diff --quiet || { echo "The working copy is modified. Commit or stash changes before proceeding."; exit ; }
|
2021-02-15 11:48:11 +00:00
|
|
|
fi
|
|
|
|
|
2024-09-16 20:36:39 +00:00
|
|
|
# Check for the given base path
|
|
|
|
if [[ -n $CBASE ]]; then
|
|
|
|
CBASE="${CBASE/#\~/$HOME}"
|
|
|
|
[[ -d "$CBASE" ]] || { echo "Given base -B $CBASE not found." ; exit ; }
|
2021-02-17 00:41:00 +00:00
|
|
|
else
|
2024-08-26 04:03:18 +00:00
|
|
|
# Make a Configurations temporary folder if needed
|
2024-09-16 20:36:39 +00:00
|
|
|
CBASE=./.pio/build-$BRANCH
|
|
|
|
[[ -d "$CBASE" ]] || mkdir -p "$CBASE"
|
2024-08-26 04:03:18 +00:00
|
|
|
# Download the specified Configurations branch if needed
|
2024-09-16 20:36:39 +00:00
|
|
|
if [[ ! -e "$CBASE/README.md" ]]; then
|
|
|
|
echo "Fetching Configurations from GitHub to $CBASE"
|
|
|
|
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$CBASE" || { echo "Failed to clone the configuration repository"; exit ; }
|
2024-08-26 04:03:18 +00:00
|
|
|
fi
|
2021-02-15 11:48:11 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-26 04:03:18 +00:00
|
|
|
# Build
|
|
|
|
echo -e "=====================\nProceed with builds...\n====================="
|
2021-02-15 11:48:11 +00:00
|
|
|
shopt -s nullglob
|
2024-09-16 20:36:39 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Remove the file name and slash from the end of the path
|
|
|
|
CONF=${CONF%/*}
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2021-03-01 11:39:31 +00:00
|
|
|
# Get a config's directory name
|
2024-09-16 20:36:39 +00:00
|
|
|
DIR=${CONF#$CBASE/config/examples/}
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2021-03-01 11:39:31 +00:00
|
|
|
# If looking for a config, skip others
|
2024-09-16 20:36:39 +00:00
|
|
|
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && { ((DEBUG)) && echo "[SKIP] $DIR" ; continue ; }
|
2021-03-01 11:39:31 +00:00
|
|
|
# Once found, stop looking
|
2021-02-17 00:41:00 +00:00
|
|
|
unset FIRST_CONF
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2021-03-01 11:39:31 +00:00
|
|
|
# If skipping, don't build the found one
|
|
|
|
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2024-09-16 20:36:39 +00:00
|
|
|
# Either Configuration.h or Configuration_adv.h must exist
|
|
|
|
[[ -f "$CONF"/Configuration.h || -f "$CONF"/Configuration_adv.h ]] || { echo "[NONE] $DIR" ; continue ; }
|
2022-07-23 00:30:29 +00:00
|
|
|
|
2024-08-24 20:56:47 +00:00
|
|
|
# Command arguments for 'build_example'
|
2024-09-16 20:36:39 +00:00
|
|
|
CARGS=("-b" "$CBASE" "-c" "$DIR")
|
2024-08-24 20:56:47 +00:00
|
|
|
|
|
|
|
# Exporting? Add -e argument
|
|
|
|
((CEXPORT)) && CARGS+=("-e" "$CEXPORT")
|
|
|
|
|
2024-09-01 21:34:35 +00:00
|
|
|
# Continue on fail? Add -f argument
|
|
|
|
((NOFAIL)) && CARGS+=("-f")
|
2024-08-24 20:56:47 +00:00
|
|
|
|
2024-08-26 04:03:18 +00:00
|
|
|
# Archive the build? Add -a argument
|
|
|
|
((ARCHIVE)) && CARGS+=("-a")
|
|
|
|
|
2024-09-01 21:34:35 +00:00
|
|
|
# Redirecting the export/archive output? Add -o argument
|
|
|
|
[[ -n $OUTBASE ]] && CARGS+=("-o" "$OUTBASE")
|
|
|
|
|
2022-07-26 19:54:54 +00:00
|
|
|
# Build or print build command for --nobuild
|
2024-08-26 17:58:04 +00:00
|
|
|
if ((DRYRUN)); then
|
2024-08-24 20:56:47 +00:00
|
|
|
echo -e "\033[0;32m[DRYRUN] build_example ${CARGS[@]}\033[0m"
|
2022-07-23 00:30:29 +00:00
|
|
|
else
|
2022-07-26 19:54:54 +00:00
|
|
|
# Remember where we are in case of failure
|
|
|
|
echo "${BRANCH}*${DIR}" >"$STAT_FILE"
|
2024-09-16 20:36:39 +00:00
|
|
|
((DEBUG)) && echo "build_example ${CARGS[@]}"
|
2024-08-26 04:03:18 +00:00
|
|
|
# Invoke build_example
|
2024-09-16 20:36:39 +00:00
|
|
|
build_example "${CARGS[@]}" || { echo "Failed to build $DIR" ; exit ; }
|
2022-07-23 00:30:29 +00:00
|
|
|
fi
|
|
|
|
|
2024-09-16 20:36:39 +00:00
|
|
|
echo
|
|
|
|
((--LIMIT)) || { echo "Specified limit reached" ; PAUSE=1 ; break ; }
|
|
|
|
echo
|
2024-08-24 20:56:47 +00:00
|
|
|
|
2021-02-15 11:48:11 +00:00
|
|
|
done
|
|
|
|
|
2022-07-23 05:36:03 +00:00
|
|
|
# Delete the build state if not paused early
|
2024-09-16 20:36:39 +00:00
|
|
|
[[ $PAUSE ]] || rm -f "$STAT_FILE"
|