2021-02-15 05:48:11 -06:00
|
|
|
#!/usr/bin/env bash
|
2021-02-16 18:41:00 -06:00
|
|
|
#
|
2022-07-22 19:30:29 -05:00
|
|
|
# Usage:
|
2021-02-16 18:41:00 -06:00
|
|
|
#
|
2022-07-26 14:54:54 -05:00
|
|
|
# build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo
|
|
|
|
# [-c|--continue] - Continue the paused build
|
|
|
|
# [-d|--debug] - Print extra debug output
|
|
|
|
# [-i|--ini] - Archive ini/json/yml files in the temp config folder
|
|
|
|
# [-l|--limit=#] - Limit the number of builds in this run
|
|
|
|
# [-n|--nobuild] - Don't actually build anything.
|
|
|
|
# [-r|--resume=<path>] - Start at some config in the filesystem order
|
|
|
|
# [-s|--skip] - Do the thing
|
2022-07-22 19:30:29 -05:00
|
|
|
#
|
|
|
|
# build_all_examples [...] branch [resume-from]
|
|
|
|
#
|
|
|
|
|
|
|
|
. mfutil
|
2021-02-15 05:48:11 -06:00
|
|
|
|
2021-02-16 18:41:00 -06:00
|
|
|
GITREPO=https://github.com/MarlinFirmware/Configurations.git
|
|
|
|
STAT_FILE=./.pio/.buildall
|
2021-02-15 05:48:11 -06:00
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
usage() { echo "
|
|
|
|
Usage: $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-r|--resume=<path>]
|
|
|
|
$SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-c|--continue]
|
|
|
|
$SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-s|--skip]
|
|
|
|
$SELF [-b|--branch=<branch>] [-d|--debug] [-n|--nobuild]
|
|
|
|
$SELF [...] branch [resume-point]
|
|
|
|
"
|
|
|
|
}
|
2021-02-16 18:41:00 -06:00
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
# Assume the most recent configs
|
|
|
|
BRANCH=import-2.1.x
|
|
|
|
unset FIRST_CONF
|
|
|
|
EXIT_USAGE=
|
|
|
|
LIMIT=1000
|
2021-02-16 18:41:00 -06:00
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
while getopts 'b:cdhil:nqr:sv-:' OFLAG; do
|
|
|
|
case "${OFLAG}" in
|
|
|
|
b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
|
|
|
|
r) FIRST_CONF="$OPTARG" ; bugout "Resume: $FIRST_CONF" ;;
|
|
|
|
c) CONTINUE=1 ; bugout "Continue" ;;
|
|
|
|
s) CONTSKIP=1 ; bugout "Continue, skipping" ;;
|
2022-07-26 14:54:54 -05:00
|
|
|
i) COPY_INI=1 ; bugout "Archive INI/JSON/YML files" ;;
|
2022-07-22 19:30:29 -05:00
|
|
|
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" ;;
|
|
|
|
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
|
|
|
|
case "$ONAM" in
|
|
|
|
branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
|
|
|
|
resume) FIRST_CONF="$OVAL" ; bugout "Resume: $FIRST_CONF" ;;
|
|
|
|
continue) CONTINUE=1 ; bugout "Continue" ;;
|
|
|
|
skip) CONTSKIP=2 ; bugout "Continue, skipping" ;;
|
|
|
|
limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT build(s)" ;;
|
2022-07-26 14:54:54 -05:00
|
|
|
ini) COPY_INI=1 ; bugout "Archive INI/JSON/YML files" ;;
|
2022-07-22 19:30:29 -05:00
|
|
|
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" ;;
|
|
|
|
*) EXIT_USAGE=2 ; echo "$SELF: unrecognized option \`--$ONAM'" ; break ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*) EXIT_USAGE=2 ; break ;;
|
|
|
|
esac
|
|
|
|
done
|
2021-02-15 05:48:11 -06:00
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
# Extra arguments count as BRANCH, FIRST_CONF
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
[[ $# > 0 ]] && { BRANCH=$1 ; shift 1 ; bugout "BRANCH=$BRANCH" ; }
|
|
|
|
[[ $# > 0 ]] && { FIRST_CONF=$1 ; shift 1 ; bugout "FIRST_CONF=$FIRST_CONF" ; }
|
|
|
|
[[ $# > 0 ]] && { EXIT_USAGE=2 ; echo "too many arguments" ; }
|
2021-02-15 05:48:11 -06:00
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
|
2021-02-15 05:48:11 -06:00
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
echo "This script downloads each Configuration and attempts to build it."
|
2021-02-16 18:41:00 -06:00
|
|
|
echo "On failure the last-built configs will be left in your working copy."
|
|
|
|
echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
|
|
|
|
|
2021-03-01 05:39:31 -06:00
|
|
|
if [[ -f "$STAT_FILE" ]]; then
|
|
|
|
IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
|
|
|
|
fi
|
|
|
|
|
2021-02-16 18:41:00 -06:00
|
|
|
# If -c is given start from the last attempted build
|
2022-07-22 19:30:29 -05:00
|
|
|
if ((CONTINUE)); then
|
2021-03-01 05:39:31 -06:00
|
|
|
if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
|
2021-02-16 18:41:00 -06:00
|
|
|
echo "Nothing to continue"
|
|
|
|
exit
|
|
|
|
fi
|
2022-07-22 19:30:29 -05:00
|
|
|
elif ((CONTSKIP)); then
|
2021-03-01 05:39:31 -06:00
|
|
|
if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
|
|
|
|
SKIP_CONF=1
|
|
|
|
else
|
|
|
|
echo "Nothing to skip"
|
|
|
|
exit
|
|
|
|
fi
|
2021-02-15 05:48:11 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if the current repository has unmerged changes
|
2021-03-01 05:39:31 -06:00
|
|
|
if [[ $SKIP_CONF ]]; then
|
|
|
|
echo "Skipping $FIRST_CONF"
|
|
|
|
elif [[ $FIRST_CONF ]]; then
|
2021-02-16 18:41:00 -06:00
|
|
|
echo "Resuming from $FIRST_CONF"
|
2021-03-01 05:39:31 -06:00
|
|
|
else
|
|
|
|
git diff --quiet || { echo "The working copy is modified. Commit or stash changes before proceeding."; exit ; }
|
2021-02-15 05:48:11 -06:00
|
|
|
fi
|
|
|
|
|
2021-02-16 18:41:00 -06:00
|
|
|
# Create a temporary folder inside .pio
|
|
|
|
TMP=./.pio/build-$BRANCH
|
|
|
|
[[ -d "$TMP" ]] || mkdir -p $TMP
|
2021-02-15 05:48:11 -06:00
|
|
|
|
2021-02-16 18:41:00 -06:00
|
|
|
# Download Configurations into the temporary folder
|
|
|
|
if [[ ! -e "$TMP/README.md" ]]; then
|
2022-07-22 19:30:29 -05:00
|
|
|
echo "Fetching Configurations from GitHub to $TMP"
|
2021-02-16 18:41:00 -06:00
|
|
|
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$TMP" || { echo "Failed to clone the configuration repository"; exit ; }
|
|
|
|
else
|
2022-07-22 19:30:29 -05:00
|
|
|
echo "Using cached Configurations at $TMP"
|
2021-02-15 05:48:11 -06:00
|
|
|
fi
|
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
echo -e "Start build...\n====================="
|
2021-02-15 05:48:11 -06:00
|
|
|
shopt -s nullglob
|
2021-02-16 18:41:00 -06:00
|
|
|
IFS='
|
|
|
|
'
|
|
|
|
CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" )
|
|
|
|
for CONF in $CONF_TREE ; do
|
2022-07-22 19:30:29 -05:00
|
|
|
|
2021-03-01 05:39:31 -06:00
|
|
|
# Get a config's directory name
|
2021-02-16 18:41:00 -06:00
|
|
|
DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" )
|
2022-07-22 19:30:29 -05:00
|
|
|
|
2021-03-01 05:39:31 -06:00
|
|
|
# If looking for a config, skip others
|
|
|
|
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
|
|
|
|
# Once found, stop looking
|
2021-02-16 18:41:00 -06:00
|
|
|
unset FIRST_CONF
|
2022-07-22 19:30:29 -05:00
|
|
|
|
2021-03-01 05:39:31 -06:00
|
|
|
# If skipping, don't build the found one
|
|
|
|
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
|
2022-07-22 19:30:29 -05:00
|
|
|
|
2021-03-01 05:39:31 -06:00
|
|
|
# ...if skipping, don't build this one
|
2021-02-16 18:41:00 -06:00
|
|
|
compgen -G "${CONF}Con*.h" > /dev/null || continue
|
2022-07-22 19:30:29 -05:00
|
|
|
|
2022-07-26 14:54:54 -05:00
|
|
|
# Build or print build command for --nobuild
|
2022-07-22 19:30:29 -05:00
|
|
|
if [[ $DRYRUN ]]; then
|
2022-07-26 14:54:54 -05:00
|
|
|
echo -e "\033[0;32m[DRYRUN] build_example internal \"$TMP\" \"$DIR\"\033[0m"
|
2022-07-22 19:30:29 -05:00
|
|
|
else
|
2022-07-26 14:54:54 -05:00
|
|
|
# Remember where we are in case of failure
|
|
|
|
echo "${BRANCH}*${DIR}" >"$STAT_FILE"
|
|
|
|
# Build folder is unknown so delete all report files
|
|
|
|
if [[ $COPY_INI ]]; then
|
|
|
|
IFIND='find ./.pio/build/ -name "config.ini" -o -name "schema.json" -o -name "schema.yml"'
|
|
|
|
$IFIND -exec rm "{}" \;
|
|
|
|
fi
|
|
|
|
((DEBUG)) && echo "\"$HERE/build_example\" internal \"$TMP\" \"$DIR\""
|
|
|
|
"$HERE/build_example" internal "$TMP" "$DIR" || { echo "Failed to build $DIR"; exit ; }
|
|
|
|
# Build folder is unknown so copy all report files
|
|
|
|
[[ $COPY_INI ]] && $IFIND -exec cp "{}" "$CONF" \;
|
2022-07-22 19:30:29 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
((--LIMIT)) || { echo "Limit reached" ; PAUSE=1 ; break ; }
|
|
|
|
|
2021-02-15 05:48:11 -06:00
|
|
|
done
|
|
|
|
|
2022-07-22 19:30:29 -05:00
|
|
|
# Delete the build state if not paused early
|
|
|
|
[[ $PAUSE ]] || rm "$STAT_FILE"
|
|
|
|
|
|
|
|
# Delete the temp folder if not preserving generated INI files
|
|
|
|
if [[ -e "$TMP/config/examples" ]]; then
|
2022-07-26 14:54:54 -05:00
|
|
|
if [[ $COPY_INI ]]; then
|
2022-07-22 19:30:29 -05:00
|
|
|
OPEN=$( which gnome-open xdg-open open | head -n1 )
|
|
|
|
$OPEN "$TMP"
|
|
|
|
elif [[ ! $PAUSE ]]; then
|
|
|
|
rm -rf "$TMP"
|
|
|
|
fi
|
|
|
|
fi
|