Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» build_all_examples --base --archive
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 26, 2024
1 parent d193c81 commit 4c1f765
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 38 deletions.
74 changes: 45 additions & 29 deletions buildroot/bin/build_all_examples
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
# 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
# [-r|--resume=<path>] - Start at some config in the filesystem order
# [-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
Expand All @@ -25,13 +27,15 @@ 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
[-r|--resume=<path>] - Start at some config in the filesystem order
[-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
Expand All @@ -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
;;
Expand Down Expand Up @@ -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='
'
Expand All @@ -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'
Expand All @@ -158,13 +170,17 @@ 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"
else
# 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

Expand Down
31 changes: 22 additions & 9 deletions buildroot/bin/build_example
Original file line number Diff line number Diff line change
Expand Up @@ -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" ;;
Expand All @@ -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" ;;
Expand All @@ -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 ; }
Expand Down Expand Up @@ -90,40 +96,47 @@ 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" \
"-o" "-name" "config.ini" \
"-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
# Clean up old exports
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"

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

0 comments on commit 4c1f765

Please sign in to comment.