From 8cf4c0515dd0de31e586b735c9f5b0a476a72f56 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 23 Jul 2022 00:36:03 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Keep=20stat?= =?UTF-8?q?e=20for=20build=5Fall=5Fexamples=20--limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildroot/bin/build_all_examples | 37 +++++++++----------------------- buildroot/bin/build_example | 4 ++-- buildroot/bin/mfutil | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 29 deletions(-) create mode 100755 buildroot/bin/mfutil diff --git a/buildroot/bin/build_all_examples b/buildroot/bin/build_all_examples index ee1b489fd3..73619ab472 100755 --- a/buildroot/bin/build_all_examples +++ b/buildroot/bin/build_all_examples @@ -14,27 +14,11 @@ # build_all_examples [...] branch [resume-from] # -set -e +. mfutil GITREPO=https://github.com/MarlinFirmware/Configurations.git STAT_FILE=./.pio/.buildall -# Check dependencies -which curl 1>/dev/null 2>&1 || { echo "curl not found! Please install it."; exit ; } -which git 1>/dev/null 2>&1 || { echo "git not found! Please install it."; exit ; } - -SED=$(command -v gsed 2>/dev/null || command -v sed 2>/dev/null) -[[ -z "$SED" ]] && { echo "No sed found, please install sed" ; exit 1 ; } - -SELF=`basename "$0"` -HERE=`dirname "$0"` - -# Check if called in the right location -[[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; } - -perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; } -bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; } - usage() { echo " Usage: $SELF [-b|--branch=] [-d|--debug] [-i|--ini] [-r|--resume=] $SELF [-b|--branch=] [-d|--debug] [-i|--ini] [-c|--continue] @@ -58,7 +42,7 @@ while getopts 'b:cdhil:nqr:sv-:' OFLAG; do s) CONTSKIP=1 ; bugout "Continue, skipping" ;; i) CREATE_INI=1 ; bugout "Generate an INI file" ;; h) EXIT_USAGE=1 ; break ;; - l) LIMIT=$OPTARG ; bugout "Limit to $LIMIT configs" ;; + 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" @@ -67,7 +51,7 @@ while getopts 'b:cdhil:nqr:sv-:' OFLAG; do 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 configs" ;; + limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT build(s)" ;; ini) CREATE_INI=1 ; bugout "Generate an INI file" ;; help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;; debug) DEBUG=1 ; bugout "Debug ON" ;; @@ -125,18 +109,17 @@ TMP=./.pio/build-$BRANCH # Download Configurations into the temporary folder if [[ ! -e "$TMP/README.md" ]]; then - echo "Downloading Configurations from GitHub into $TMP" + 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 ; } else - echo "Using previously downloaded Configurations at $TMP" + echo "Using cached Configurations at $TMP" fi -echo -e "Start building now...\n=====================" +echo -e "Start build...\n=====================" shopt -s nullglob IFS=' ' CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" ) -DOSKIP=0 for CONF in $CONF_TREE ; do # Get a config's directory name @@ -168,19 +151,19 @@ for CONF in $CONF_TREE ; do [[ $CREATE_INI ]] && find ./.pio/build/ -name "config.ini" -exec cp "{}" "$CONF" \; fi - ((LIMIT--)) || { echo "Limit reached" ; break ; } + ((--LIMIT)) || { echo "Limit reached" ; PAUSE=1 ; break ; } done -# Delete the build state -rm "$STAT_FILE" +# 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 if [[ $CREATE_INI ]]; then OPEN=$( which gnome-open xdg-open open | head -n1 ) $OPEN "$TMP" - else + elif [[ ! $PAUSE ]]; then rm -rf "$TMP" fi fi diff --git a/buildroot/bin/build_example b/buildroot/bin/build_example index a1e4fbacbd..34549769bb 100755 --- a/buildroot/bin/build_example +++ b/buildroot/bin/build_example @@ -5,6 +5,8 @@ # Usage: build_example internal config-home config-folder # +. mfutil + # Require 'internal' as the first argument [[ "$1" == "internal" ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; } @@ -25,14 +27,12 @@ cp "$SUB"/_Statusscreen.h Marlin/ 2>/dev/null set -e # Strip #error lines from Configuration.h -SED=$(which gsed sed | head -n1) IFS=$'\n'; set -f $SED -i~ -e "20,30{/#error/d}" Marlin/Configuration.h rm Marlin/Configuration.h~ unset IFS; set +f echo "Building the firmware now..." -HERE=`dirname "$0"` $HERE/mftest -s -a -n1 || { echo "Failed"; exit 1; } echo "Success" diff --git a/buildroot/bin/mfutil b/buildroot/bin/mfutil new file mode 100755 index 0000000000..75a2791cfe --- /dev/null +++ b/buildroot/bin/mfutil @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# mfutil - check env and define helpers +# + +# Check dependencies +which curl 1>/dev/null 2>&1 || { echo "curl not found! Please install it."; exit ; } +which git 1>/dev/null 2>&1 || { echo "git not found! Please install it."; exit ; } + +SED=$(command -v gsed 2>/dev/null || command -v sed 2>/dev/null) +[[ -z "$SED" ]] && { echo "No sed found, please install sed" ; exit 1 ; } + +OPEN=$( which gnome-open xdg-open open | head -n1 ) + +SELF=`basename "$0"` +HERE=`dirname "$0"` + +# Check if called in the right location +[[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; } + +perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; } +bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }