0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-03-15 02:36:19 +00:00

🧑‍💻 build_all_examples --base --archive

This commit is contained in:
Scott Lahteine 2024-08-25 23:03:18 -05:00
parent d193c814d3
commit 4c1f76567c
2 changed files with 67 additions and 38 deletions

View file

@ -3,6 +3,7 @@
# Usage:
#
# build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo (import-2.1.x)
# [-B|--base] - Base path of configurations, overriding -b
# [-c|--continue] - Continue the paused build
# [-p|--purge] - Purge the status file and start over
# [-s|--skip] - Continue the paused build, skipping one
@ -10,6 +11,7 @@
# [-e|--export=N] - Set CONFIG_EXPORT and export into each config folder
# [-d|--debug] - Print extra debug output (after)
# [-l|--limit=#] - Limit the number of builds in this run
# [-a|--archive] - Copy the binary to the export location
# [-n|--nobuild] - Don't actually build anything
# [-f|--nofail] - Don't stop on a failed build
# [-h|--help] - Print usage and exit
@ -25,6 +27,7 @@ STAT_FILE=./.pio/.buildall
usage() { echo "Usage:
build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo (import-2.1.x)
[-B|--base] - Base path of configurations, overriding -b
[-c|--continue] - Continue the paused build
[-p|--purge] - Purge the status file and start over
[-s|--skip] - Continue the paused build, skipping one
@ -32,6 +35,7 @@ build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations
[-e|--export=N] - Set CONFIG_EXPORT and export into each config folder
[-d|--debug] - Print extra debug output (after)
[-l|--limit=#] - Limit the number of builds in this run
[-a|--archive] - Copy the binary to the export location
[-n|--nobuild] - Don't actually build anything
[-f|--nofail] - Don't stop on a failed build
[-h|--help] - Print usage and exit
@ -44,32 +48,36 @@ unset FIRST_CONF
EXIT_USAGE=
LIMIT=1000
while getopts 'b:ce:fdhl:npr:sv-:' OFLAG; do
while getopts 'aB:b:ce:fdhl:npr:sv-:' OFLAG; do
case "${OFLAG}" in
b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
f) NOFAIL=1 ; bugout "Continue on Fail" ;;
a) ARCHIVE=1 ; bugout "Archiving" ;;
B) OPATH="$OPTARG" ; bugout "Base: $OPATH" ;;
b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
f) NOFAIL=1 ; bugout "Continue on Fail" ;;
r) ISRES=1 ; FIRST_CONF="$OPTARG" ; bugout "Resume: $FIRST_CONF" ;;
c) CONTINUE=1 ; bugout "Continue" ;;
s) CONTSKIP=1 ; bugout "Continue, skipping" ;;
e) CEXPORT="$OPTARG" ; bugout "Export $CEXPORT" ;;
c) CONTINUE=1 ; bugout "Continue" ;;
s) CONTSKIP=1 ; bugout "Continue, skipping" ;;
e) CEXPORT="$OPTARG" ; bugout "Export $CEXPORT" ;;
h) EXIT_USAGE=1 ; break ;;
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" ;;
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" ;;
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
case "$ONAM" in
branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
nofail) NOFAIL=1 ; bugout "Continue on Fail" ;;
archive) ARCHIVE=1 ; bugout "Archiving" ;;
base) OPATH="$OVAL" ; bugout "Base: $OPATH" ;;
branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
nofail) NOFAIL=1 ; bugout "Continue on Fail" ;;
resume) ISRES=1 ; FIRST_CONF="$OVAL" ; bugout "Resume: $FIRST_CONF" ;;
continue) CONTINUE=1 ; bugout "Continue" ;;
skip) CONTSKIP=1 ; bugout "Continue, skipping" ;;
export) CEXPORT="$OVAL" ; bugout "Export $EXPORT" ;;
limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT build(s)" ;;
continue) CONTINUE=1 ; bugout "Continue" ;;
skip) CONTSKIP=1 ; bugout "Continue, skipping" ;;
export) CEXPORT="$OVAL"; bugout "Export $EXPORT" ;;
limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT build(s)" ;;
help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
debug) DEBUG=1 ; bugout "Debug ON" ;;
nobuild) DRYRUN=1 ; bugout "Dry Run" ;;
purge) PURGE=1 ; bugout "Purge stat file" ;;
debug) DEBUG=1 ; bugout "Debug ON" ;;
nobuild) DRYRUN=1 ; bugout "Dry Run" ;;
purge) PURGE=1 ; bugout "Purge stat file" ;;
*) EXIT_USAGE=2 ; echo "$SELF: unrecognized option \`--$ONAM'" ; break ;;
esac
;;
@ -117,18 +125,22 @@ else
fi
# Create a temporary folder inside .pio
TMP=./.pio/build-$BRANCH
[[ -d "$TMP" ]] || mkdir -p $TMP
# Download Configurations into the temporary folder
if [[ ! -e "$TMP/README.md" ]]; then
echo "Fetching Configurations from GitHub to $TMP"
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$TMP" || { echo "Failed to clone the configuration repository"; exit ; }
if [[ -n $OPATH ]]; then
TMP=$OPATH
[[ -d "$TMP" ]] || { echo "Given base -B $TMP not found." ; exit ; }
else
echo "Using cached Configurations at $TMP"
# Make a Configurations temporary folder if needed
TMP=./.pio/build-$BRANCH
[[ -d "$TMP" ]] || mkdir -p $TMP
# Download the specified Configurations branch if needed
if [[ ! -e "$TMP/README.md" ]]; then
echo "Fetching Configurations from GitHub to $TMP"
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$TMP" || { echo "Failed to clone the configuration repository"; exit ; }
fi
fi
echo -e "Start build...\n====================="
# Build
echo -e "=====================\nProceed with builds...\n====================="
shopt -s nullglob
IFS='
'
@ -146,7 +158,7 @@ for CONF in $CONF_TREE ; do
# If skipping, don't build the found one
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
# ...if skipping, don't build this one
# At least one config file is required here
compgen -G "${CONF}Con*.h" > /dev/null || continue
# Command arguments for 'build_example'
@ -158,6 +170,9 @@ for CONF in $CONF_TREE ; do
# Continue on fail? Add -n argument
((NOFAIL)) && CARGS+=("-n")
# Archive the build? Add -a argument
((ARCHIVE)) && CARGS+=("-a")
# Build or print build command for --nobuild
if [[ $DRYRUN ]]; then
echo -e "\033[0;32m[DRYRUN] build_example ${CARGS[@]}\033[0m"
@ -165,6 +180,7 @@ for CONF in $CONF_TREE ; do
# Remember where we are in case of failure
echo "${BRANCH}*${DIR}" >"$STAT_FILE"
((DEBUG)) && echo "\"$HERE/build_example\" ${CARGS[@]}"
# Invoke build_example
"$HERE"/build_example "${CARGS[@]}" || { echo "Failed to build $DIR" ; exit ; }
fi

View file

@ -2,29 +2,34 @@
#
# Usage:
#
# build_example -b|--base=<folder> - Configurations root folder (e.g., ./.pio/build-BRANCH)
# -c|--config=<path> - Path of the configs to build (within config/examples)
# build_example -b|--base=<path> - Configurations root folder (e.g., ./.pio/build-BRANCH)
# -c|--config=<rel> - Sub-path of the configs to build (within config/examples)
# [-e|--export=N] - Set CONFIG_EXPORT before build and export into the config folder
# [-n|--nofail] - Don't stop on a failed build
# [-r|--reveal] - Reveal the config folder after the build
# [-h|--help] - Print usage and exit
# [-a|--archive] - Archive the build (to the export location)
# [--allow] - Allow this script to run standalone
#
HERE=`dirname $0`
. "$HERE/mfutil"
source "$HERE/mfutil"
annc() { echo -e "\033[0;32m$1\033[0m" ; }
# Get arguments
CLEANER=1
ALLOW=""
ARCHIVE=""
BASE=""
CONFIG=""
REVEAL=""
EXPNUM=""
NOFAIL=""
while getopts 'b:c:e:hinr-:' OFLAG; do
while getopts 'ab:c:e:hinr-:' OFLAG; do
case "${OFLAG}" in
a) ARCHIVE=1 ;;
b) BASE="$OPTARG" ;;
c) CONFIG="$OPTARG" ;;
e) EXPNUM="$OPTARG" ;;
@ -33,6 +38,7 @@ while getopts 'b:c:e:hinr-:' OFLAG; do
r) REVEAL=1 ;;
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
case "$ONAM" in
archive) ARCHIVE=1 ;;
allow) ALLOW=1 ;;
base) BASE="$OVAL" ;;
config) CONFIG="$OVAL" ;;
@ -53,7 +59,7 @@ SUB1="$BASE/config/examples"
[[ -d "$SUB1" ]] || { echo "--base $BASE doesn't contain config/examples" ; exit 1 ; }
# Make sure the specific config folder exists
SUB=$SUB1/$CONFIG
SUB="$SUB1/$CONFIG"
[[ -d "$SUB" ]] || { echo "--config $CONFIG doesn't exist" ; exit 1 ; }
compgen -G "${SUB}Con*.h" > /dev/null || { echo "No configuration files found in $SUB" ; exit 1 ; }
@ -90,6 +96,7 @@ if ((CLEANER)); then
opt_add NO_LCD_CONTRAST_WARNING
opt_add NO_MICROPROBE_WARNING
opt_add NO_CONFIGURATION_EMBEDDING_WARNING
opt_add NO_HOMING_CURRENT_WARNING
fi
FNAME=("-name" "marlin_config.json" \
@ -97,6 +104,8 @@ FNAME=("-name" "marlin_config.json" \
"-o" "-name" "schema.json" \
"-o" "-name" "schema.yml")
BNAME=("-name" "*.bin" "-o" "-name" "*.hex")
# If EXPNUM is set then apply to the config before build
if [[ $EXPNUM ]]; then
opt_set CONFIG_EXPORT $EXPNUM
@ -104,9 +113,11 @@ if [[ $EXPNUM ]]; then
find ./.pio/build \( "${FNAME[@]}" \) -exec rm "{}" \;
fi
((ARCHIVE)) && find ./.pio/build \( "${BNAME[@]}" \) -exec rm "{}" \;
set +e
echo "Building the firmware now..."
echo "Building example $CONFIG ..."
"$HERE/mftest" -s -a -n1 ; ERR=$?
[[ $ERR -eq 0 ]] && echo "Success" || echo "Failed"
@ -114,16 +125,18 @@ echo "Building the firmware now..."
set -e
# Copy exports back to the configs
if [[ $EXPNUM ]]; then
echo "Exporting $EXPNUM"
if [[ -n $EXPNUM ]]; then
annc "Exporting $EXPNUM"
[[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$SUB"/Config.h ; }
find ./.pio/build/ "${FNAME[@]}" -exec cp "{}" "$SUB" \;
fi
((ARCHIVE)) && { annc "Archiving" ; find ./.pio/build \( "${BNAME[@]}" \) -exec cp "{}" "$SUB" \; ; }
# Exit with error unless --nofail is set
[[ $ERR -gt 0 && -z $NOFAIL ]] && exit $ERR
# Reveal the configs after the build, if requested
((REVEAL)) && { echo "Revealing $SUB" ; open "$SUB" ; }
((REVEAL)) && { annc "Revealing $SUB" ; open "$SUB" ; }
exit 0