mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-07-24 15:13:54 -06:00
🧑💻 Improve build_example
This commit is contained in:
parent
90e5826256
commit
fe56f5d3a6
3 changed files with 75 additions and 50 deletions
|
@ -51,13 +51,13 @@ LIMIT=1000
|
|||
while getopts 'aB:b:ce:fdhl:npr:sv-:' OFLAG; do
|
||||
case "${OFLAG}" in
|
||||
a) ARCHIVE=1 ; bugout "Archiving" ;;
|
||||
B) OPATH="$OPTARG" ; bugout "Base: $OPATH" ;;
|
||||
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" ;;
|
||||
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" ;;
|
||||
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" ;;
|
||||
|
@ -66,13 +66,13 @@ while getopts 'aB:b:ce:fdhl:npr:sv-:' OFLAG; do
|
|||
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
|
||||
case "$ONAM" in
|
||||
archive) ARCHIVE=1 ; bugout "Archiving" ;;
|
||||
base) OPATH="$OVAL" ; bugout "Base: $OPATH" ;;
|
||||
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" ;;
|
||||
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" ;;
|
||||
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" ;;
|
||||
|
@ -98,7 +98,7 @@ echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
|
|||
echo
|
||||
|
||||
[[ -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 ((CONTINUE)); then
|
||||
|
@ -126,29 +126,29 @@ fi
|
|||
|
||||
# Create a temporary folder inside .pio
|
||||
if [[ -n $OPATH ]]; then
|
||||
TMP=$OPATH
|
||||
[[ -d "$TMP" ]] || { echo "Given base -B $TMP not found." ; exit ; }
|
||||
[[ -d "$OPATH" ]] || { echo "Given base -B $OPATH not found." ; exit ; }
|
||||
else
|
||||
# Make a Configurations temporary folder if needed
|
||||
TMP=./.pio/build-$BRANCH
|
||||
[[ -d "$TMP" ]] || mkdir -p $TMP
|
||||
OPATH=./.pio/build-$BRANCH
|
||||
[[ -d "$OPATH" ]] || mkdir -p "$OPATH"
|
||||
# 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 ; }
|
||||
if [[ ! -e "$OPATH/README.md" ]]; then
|
||||
echo "Fetching Configurations from GitHub to $OPATH"
|
||||
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$OPATH" || { echo "Failed to clone the configuration repository"; exit ; }
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build
|
||||
echo -e "=====================\nProceed with builds...\n====================="
|
||||
shopt -s nullglob
|
||||
shopt -s globstar
|
||||
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
|
||||
|
||||
# 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
|
||||
[[ $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 ; }
|
||||
|
||||
# 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'
|
||||
CARGS=("-b" "$TMP" "-c" "$DIR")
|
||||
CARGS=("-b" "$OPATH" "-c" "$DIR")
|
||||
|
||||
# Exporting? Add -e argument
|
||||
((CEXPORT)) && CARGS+=("-e" "$CEXPORT")
|
||||
|
@ -174,7 +174,7 @@ for CONF in $CONF_TREE ; do
|
|||
((ARCHIVE)) && CARGS+=("-a")
|
||||
|
||||
# Build or print build command for --nobuild
|
||||
if [[ $DRYRUN ]]; then
|
||||
if ((DRYRUN)); then
|
||||
echo -e "\033[0;32m[DRYRUN] build_example ${CARGS[@]}\033[0m"
|
||||
else
|
||||
# Remember where we are in case of failure
|
||||
|
|
|
@ -19,19 +19,20 @@ source "$HERE/mfutil"
|
|||
annc() { echo -e "\033[0;32m$1\033[0m" ; }
|
||||
|
||||
# Get arguments
|
||||
CLEANER=1
|
||||
ALLOW=""
|
||||
ARCHIVE=""
|
||||
BASE=""
|
||||
CONFIG=""
|
||||
REVEAL=""
|
||||
EXPNUM=""
|
||||
NOFAIL=""
|
||||
BUILD=./.pio/build
|
||||
CLEANER=
|
||||
ALLOW=
|
||||
ARCHIVE=
|
||||
BASE=
|
||||
CONFIG=
|
||||
REVEAL=
|
||||
EXPNUM=
|
||||
NOFAIL=
|
||||
while getopts 'ab:c:e:hinr-:' OFLAG; do
|
||||
case "${OFLAG}" in
|
||||
a) ARCHIVE=1 ;;
|
||||
b) BASE="$OPTARG" ;;
|
||||
c) CONFIG="$OPTARG" ;;
|
||||
b) BASE="${OPTARG%/}" ;;
|
||||
c) CONFIG="${OPTARG%/}" ;;
|
||||
e) EXPNUM="$OPTARG" ;;
|
||||
h) EXIT_USAGE=1 ; break ;;
|
||||
n) NOFAIL=1 ;;
|
||||
|
@ -40,8 +41,8 @@ while getopts 'ab:c:e:hinr-:' OFLAG; do
|
|||
case "$ONAM" in
|
||||
archive) ARCHIVE=1 ;;
|
||||
allow) ALLOW=1 ;;
|
||||
base) BASE="$OVAL" ;;
|
||||
config) CONFIG="$OVAL" ;;
|
||||
base) BASE="${OVAL%/}" ;;
|
||||
config) CONFIG="${OVAL%/}" ;;
|
||||
export) EXPNUM="$OVAL" ;;
|
||||
help) EXIT_USAGE=1 ; break ;;
|
||||
nofail) NOFAIL=1 ;;
|
||||
|
@ -52,28 +53,32 @@ while getopts 'ab:c:e:hinr-:' OFLAG; do
|
|||
esac
|
||||
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 ; }
|
||||
|
||||
# -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
|
||||
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
|
||||
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
|
||||
rm -f Marlin/Config.h Marlin/Config-export.h
|
||||
# Delete any config files from previous builds
|
||||
rm -f Marlin/_Bootscreen.h Marlin/_Statusscreen.h
|
||||
|
||||
# Copy configurations into the Marlin folder
|
||||
echo "Getting configuration files from $SUB"
|
||||
cp "$BASE/config/default"/*.h Marlin/
|
||||
cp "$SUB"/Config.h Marlin/ 2>/dev/null
|
||||
cp "$SUB"/Configuration.h Marlin/ 2>/dev/null
|
||||
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
|
||||
cp "$BASE/config/default"/*.h "$SUB"/*.h Marlin/ 2>/dev/null
|
||||
|
||||
rm -f Marlin/Config.h Marlin/Config-export.h
|
||||
|
||||
set -e
|
||||
|
||||
|
@ -99,28 +104,35 @@ if ((CLEANER)); then
|
|||
opt_add NO_HOMING_CURRENT_WARNING
|
||||
fi
|
||||
|
||||
FNAME=("-name" "marlin_config.json" \
|
||||
ENAME=("-name" "marlin_config.json" \
|
||||
"-o" "-name" "config.ini" \
|
||||
"-o" "-name" "schema.json" \
|
||||
"-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 ]]; then
|
||||
opt_set CONFIG_EXPORT $EXPNUM
|
||||
# Clean up old exports
|
||||
find ./.pio/build \( "${FNAME[@]}" \) -exec rm "{}" \;
|
||||
find "$BUILD" \( "${ENAME[@]}" \) -exec rm "{}" \;
|
||||
fi
|
||||
|
||||
((ARCHIVE)) && find ./.pio/build \( "${BNAME[@]}" \) -exec rm "{}" \;
|
||||
((ARCHIVE)) && find "$BUILD" \( "${BNAME[@]}" \) -exec rm "{}" \;
|
||||
|
||||
set +e
|
||||
|
||||
echo "Building example $CONFIG ..."
|
||||
"$HERE/mftest" -s -a -n1 ; ERR=$?
|
||||
|
||||
[[ $ERR -eq 0 ]] && echo "Success" || echo "Failed"
|
||||
((ERR)) && echo "Failed" || echo "Success"
|
||||
|
||||
set -e
|
||||
|
||||
|
@ -128,10 +140,23 @@ set -e
|
|||
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" \;
|
||||
find "$BUILD" "${ENAME[@]}" -exec cp "{}" "$SUB" \;
|
||||
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
|
||||
[[ $ERR -gt 0 && -z $NOFAIL ]] && exit $ERR
|
||||
|
|
|
@ -216,7 +216,7 @@ def compute_build_signature(env):
|
|||
if not conf_schema: exit(1)
|
||||
|
||||
# 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 }
|
||||
|
||||
# Group options by schema @section
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue