From 73b6ba8fe3216fca99422b160a180d1224bc996e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 16 Sep 2024 15:36:39 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20More=20comp?= =?UTF-8?q?atible=20Build=20Scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to d36d9cb506 --- buildroot/bin/build_all_examples | 57 +++++++++++++++++--------------- buildroot/bin/build_example | 8 +++-- buildroot/bin/mftest | 2 -- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/buildroot/bin/build_all_examples b/buildroot/bin/build_all_examples index 7c4e8cb0ca..31957caa84 100755 --- a/buildroot/bin/build_all_examples +++ b/buildroot/bin/build_all_examples @@ -20,8 +20,9 @@ # HERE=`dirname $0` +PATH="$HERE:$PATH" -. "$HERE/mfutil" +. mfutil GITREPO=https://github.com/MarlinFirmware/Configurations.git STAT_FILE=./.pio/.buildall @@ -55,7 +56,7 @@ LIMIT=1000 while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do case "${OFLAG}" in a) ARCHIVE=1 ; bugout "Archiving" ;; - B) OPATH=${OPTARG%/} ; bugout "Base: $OPATH" ;; + B) CBASE=${OPTARG%/} ; bugout "Base: $CBASE" ;; b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;; f) NOFAIL=1 ; bugout "Continue on Fail" ;; r) ISRES=1 ; FIRST_CONF=$OPTARG ; bugout "Resume: $FIRST_CONF" ;; @@ -71,7 +72,7 @@ while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do -) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}" case "$ONAM" in archive) ARCHIVE=1 ; bugout "Archiving" ;; - base) OPATH=${OVAL%/} ; bugout "Base: $OPATH" ;; + base) CBASE=${OVAL%/} ; bugout "Base: $CBASE" ;; branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;; nofail) NOFAIL=1 ; bugout "Continue on Fail" ;; resume) ISRES=1 ; FIRST_CONF=$OVAL ; bugout "Resume: $FIRST_CONF" ;; @@ -131,45 +132,47 @@ else git diff --quiet || { echo "The working copy is modified. Commit or stash changes before proceeding."; exit ; } fi -# Create a temporary folder inside .pio -if [[ -n $OPATH ]]; then - [[ -d "$OPATH" ]] || { echo "Given base -B $OPATH not found." ; exit ; } +# Check for the given base path +if [[ -n $CBASE ]]; then + CBASE="${CBASE/#\~/$HOME}" + [[ -d "$CBASE" ]] || { echo "Given base -B $CBASE not found." ; exit ; } else # Make a Configurations temporary folder if needed - OPATH=./.pio/build-$BRANCH - [[ -d "$OPATH" ]] || mkdir -p "$OPATH" + CBASE=./.pio/build-$BRANCH + [[ -d "$CBASE" ]] || mkdir -p "$CBASE" # Download the specified Configurations branch if needed - 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 ; } + 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 ; } fi fi # Build echo -e "=====================\nProceed with builds...\n=====================" shopt -s nullglob -shopt -s globstar -IFS=' -' -CONF_TREE=$( ls -d "$OPATH"/config/examples/**/ | grep -vE ".+\.(\w+)$" ) -for CONF in $CONF_TREE ; do + +# 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%/*} # Get a config's directory name - DIR=${CONF#$OPATH/config/examples/} + DIR=${CONF#$CBASE/config/examples/} # If looking for a config, skip others - [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue + [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && { ((DEBUG)) && echo "[SKIP] $DIR" ; continue ; } # Once found, stop looking unset FIRST_CONF # If skipping, don't build the found one [[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; } - # At least one config file is required here - compgen -G "${CONF}Configuration*.h" > /dev/null || continue + # Either Configuration.h or Configuration_adv.h must exist + [[ -f "$CONF"/Configuration.h || -f "$CONF"/Configuration_adv.h ]] || { echo "[NONE] $DIR" ; continue ; } # Command arguments for 'build_example' - CARGS=("-b" "$OPATH" "-c" "$DIR") + CARGS=("-b" "$CBASE" "-c" "$DIR") # Exporting? Add -e argument ((CEXPORT)) && CARGS+=("-e" "$CEXPORT") @@ -189,16 +192,16 @@ for CONF in $CONF_TREE ; do else # Remember where we are in case of failure echo "${BRANCH}*${DIR}" >"$STAT_FILE" - ((DEBUG)) && echo "\"$HERE/build_example\" ${CARGS[@]}" + ((DEBUG)) && echo "build_example ${CARGS[@]}" # Invoke build_example - "$HERE"/build_example "${CARGS[@]}" || { echo "Failed to build $DIR" ; exit ; } + build_example "${CARGS[@]}" || { echo "Failed to build $DIR" ; exit ; } fi - ((--LIMIT)) || { echo "Limit reached" ; PAUSE=1 ; break ; } - - echo ; echo + echo + ((--LIMIT)) || { echo "Specified limit reached" ; PAUSE=1 ; break ; } + echo done # Delete the build state if not paused early -[[ $PAUSE ]] || rm "$STAT_FILE" +[[ $PAUSE ]] || rm -f "$STAT_FILE" diff --git a/buildroot/bin/build_example b/buildroot/bin/build_example index 711346ac3a..7c075e700c 100755 --- a/buildroot/bin/build_example +++ b/buildroot/bin/build_example @@ -32,8 +32,9 @@ build_example -b|--base= - Configurations root folder (e.g., ./.pio/bu } HERE=`dirname $0` +PATH="$HERE:$PATH" -source "$HERE/mfutil" +. mfutil annc() { echo -e "\033[0;32m$1\033[0m" ; } @@ -100,7 +101,7 @@ SUB="$SUB1/$CONFIG" [[ -d "$SUB" ]] || { echo "-c|--config $CONFIG doesn't exist" ; 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 ; } +[[ -f "$SUB"/Configuration.h || -f "$SUB"/Configuration_adv.h ]] || { echo "No configuration files found in $SUB" ; exit 1 ; } # Get the location for exports and archives if [[ -n $OUTBASE ]]; then @@ -173,7 +174,7 @@ fi set +e echo "Building example $CONFIG ..." -"$HERE/mftest" -s -a -n1 ; ERR=$? +mftest -s -a -n1 ; ERR=$? ((ERR)) && echo "Failed" || echo "Success" @@ -191,6 +192,7 @@ fi # Currently only BOARD_CREALITY_F401RE env:STM32F401RE_creality if ((ARCHIVE)); then annc "Archiving" + rm -f "$ARCSUB"/*.bin.tar.gz "$ARCSUB"/*.hex.tar.gz find "$BUILD" \( "${BNAME[@]}" \) -exec sh -c ' ARCSUB="$1" shift 1 diff --git a/buildroot/bin/mftest b/buildroot/bin/mftest index 1b0ac85754..492ef6c146 100755 --- a/buildroot/bin/mftest +++ b/buildroot/bin/mftest @@ -167,8 +167,6 @@ if ((AUTO_BUILD)); then MB=$(awk "$ACODE" Marlin/Configuration.h 2>/dev/null) [[ -z $MB ]] && MB=$(awk "$ACODE" Marlin/Config.h 2>/dev/null) [[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; } - echo "Got $MB" - exit BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h ) BNUM=$( sed -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" ) BDESC=$( sed -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )