Merge tag '2.1.2'
This commit is contained in:
		
							
								
								
									
										171
									
								
								buildroot/bin/build_all_examples
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										171
									
								
								buildroot/bin/build_all_examples
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,171 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
# Usage:
 | 
			
		||||
#
 | 
			
		||||
#  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
 | 
			
		||||
#
 | 
			
		||||
# build_all_examples [...] branch [resume-from]
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
. mfutil
 | 
			
		||||
 | 
			
		||||
GITREPO=https://github.com/MarlinFirmware/Configurations.git
 | 
			
		||||
STAT_FILE=./.pio/.buildall
 | 
			
		||||
 | 
			
		||||
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]
 | 
			
		||||
"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Assume the most recent configs
 | 
			
		||||
BRANCH=import-2.1.x
 | 
			
		||||
unset FIRST_CONF
 | 
			
		||||
EXIT_USAGE=
 | 
			
		||||
LIMIT=1000
 | 
			
		||||
 | 
			
		||||
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" ;;
 | 
			
		||||
    i) COPY_INI=1           ; bugout "Archive INI/JSON/YML files" ;;
 | 
			
		||||
    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)" ;;
 | 
			
		||||
          ini) COPY_INI=1   ; bugout "Archive INI/JSON/YML files" ;;
 | 
			
		||||
         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
 | 
			
		||||
 | 
			
		||||
# 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" ; }
 | 
			
		||||
 | 
			
		||||
((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
 | 
			
		||||
 | 
			
		||||
echo "This script downloads each Configuration and attempts to build it."
 | 
			
		||||
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'."
 | 
			
		||||
 | 
			
		||||
if [[ -f "$STAT_FILE" ]]; then
 | 
			
		||||
  IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# If -c is given start from the last attempted build
 | 
			
		||||
if ((CONTINUE)); then
 | 
			
		||||
  if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
 | 
			
		||||
    echo "Nothing to continue"
 | 
			
		||||
    exit
 | 
			
		||||
  fi
 | 
			
		||||
elif ((CONTSKIP)); then
 | 
			
		||||
  if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
 | 
			
		||||
    SKIP_CONF=1
 | 
			
		||||
  else
 | 
			
		||||
    echo "Nothing to skip"
 | 
			
		||||
    exit
 | 
			
		||||
  fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Check if the current repository has unmerged changes
 | 
			
		||||
if [[ $SKIP_CONF ]]; then
 | 
			
		||||
  echo "Skipping $FIRST_CONF"
 | 
			
		||||
elif [[ $FIRST_CONF ]]; then
 | 
			
		||||
  echo "Resuming from $FIRST_CONF"
 | 
			
		||||
else
 | 
			
		||||
  git diff --quiet || { echo "The working copy is modified. Commit or stash changes before proceeding."; exit ; }
 | 
			
		||||
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 ; }
 | 
			
		||||
else
 | 
			
		||||
  echo "Using cached Configurations at $TMP"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
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+)$" )
 | 
			
		||||
for CONF in $CONF_TREE ; do
 | 
			
		||||
 | 
			
		||||
  # Get a config's directory name
 | 
			
		||||
  DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" )
 | 
			
		||||
 | 
			
		||||
  # If looking for a config, skip others
 | 
			
		||||
  [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
 | 
			
		||||
  # Once found, stop looking
 | 
			
		||||
  unset FIRST_CONF
 | 
			
		||||
 | 
			
		||||
  # If skipping, don't build the found one
 | 
			
		||||
  [[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
 | 
			
		||||
 | 
			
		||||
  # ...if skipping, don't build this one
 | 
			
		||||
  compgen -G "${CONF}Con*.h" > /dev/null || continue
 | 
			
		||||
 | 
			
		||||
  # Build or print build command for --nobuild
 | 
			
		||||
  if [[ $DRYRUN ]]; then
 | 
			
		||||
    echo -e "\033[0;32m[DRYRUN] build_example internal \"$TMP\" \"$DIR\"\033[0m"
 | 
			
		||||
  else
 | 
			
		||||
    # 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" \;
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  ((--LIMIT)) || { echo "Limit reached" ; PAUSE=1 ; break ; }
 | 
			
		||||
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# 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 [[ $COPY_INI ]]; then
 | 
			
		||||
    OPEN=$( which gnome-open xdg-open open | head -n1 )
 | 
			
		||||
    $OPEN "$TMP"
 | 
			
		||||
  elif [[ ! $PAUSE ]]; then
 | 
			
		||||
    rm -rf "$TMP"
 | 
			
		||||
  fi
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										38
									
								
								buildroot/bin/build_example
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										38
									
								
								buildroot/bin/build_example
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
# build_example
 | 
			
		||||
#
 | 
			
		||||
# 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 ; }
 | 
			
		||||
 | 
			
		||||
echo "Testing $3:"
 | 
			
		||||
 | 
			
		||||
SUB=$2/config/examples/$3
 | 
			
		||||
[[ -d "$SUB" ]] || { echo "$SUB is not a good path" ; exit 1 ; }
 | 
			
		||||
 | 
			
		||||
compgen -G "${SUB}Con*.h" > /dev/null || { echo "No configuration files found in $SUB" ; exit 1 ; }
 | 
			
		||||
 | 
			
		||||
echo "Getting configuration files from $SUB"
 | 
			
		||||
cp "$2/config/default"/*.h    Marlin/
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
# Strip #error lines from Configuration.h
 | 
			
		||||
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/mftest -s -a -n1 || { echo "Failed"; exit 1; }
 | 
			
		||||
 | 
			
		||||
echo "Success"
 | 
			
		||||
							
								
								
									
										14
									
								
								buildroot/bin/ci_src_filter
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										14
									
								
								buildroot/bin/ci_src_filter
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
# exit on first failure
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
SED=$(which gsed sed | head -n1)
 | 
			
		||||
FN="platformio.ini"
 | 
			
		||||
 | 
			
		||||
if [[ $1 == "-n" ]]; then
 | 
			
		||||
  "${SED}" -i "s/default_src_filter/org_src_filter/" $FN
 | 
			
		||||
  "${SED}" -i "/org_src_filter/ s/^/default_src_filter = +<src\/*>\n/" $FN
 | 
			
		||||
else
 | 
			
		||||
  git checkout $FN 2>/dev/null
 | 
			
		||||
fi
 | 
			
		||||
@@ -4,47 +4,35 @@
 | 
			
		||||
#
 | 
			
		||||
# Make a Version.h file to accompany CUSTOM_VERSION_FILE
 | 
			
		||||
#
 | 
			
		||||
# Authors: jbrazio, thinkyhead, InsanityAutomation, rfinnie
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
DIR=${1:-"Marlin"}
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
# MRCC3=$( git merge-base HEAD upstream/bugfix-2.0.x 2>/dev/null )
 | 
			
		||||
# MRCC2=$( git merge-base HEAD upstream/bugfix-1.1.x 2>/dev/null )
 | 
			
		||||
# MRCC1=$( git merge-base HEAD upstream/1.1.x 2>/dev/null )
 | 
			
		||||
DIR="${1:-Marlin}"
 | 
			
		||||
READ_FILE="${READ_FILE:-${DIR}/Version.h}"
 | 
			
		||||
WRITE_FILE="${WRITE_FILE:-${READ_FILE}}"
 | 
			
		||||
 | 
			
		||||
# BASE='?'
 | 
			
		||||
# if [[ -n $MRCC3 && $MRCC3 != $MRCC2 ]]; then
 | 
			
		||||
#   BASE=bugfix-2.0.x
 | 
			
		||||
# elif [[ -n $MRCC2 ]]; then
 | 
			
		||||
#   BASE=bugfix-1.1.x
 | 
			
		||||
# elif [[ -n $MRCC1 ]]; then
 | 
			
		||||
#   BASE=1.1.x
 | 
			
		||||
# fi
 | 
			
		||||
BRANCH="$(git -C "${DIR}" symbolic-ref -q --short HEAD 2>/dev/null || true)"
 | 
			
		||||
VERSION="$(git -C "${DIR}" describe --tags --first-parent 2>/dev/null || true)"
 | 
			
		||||
 | 
			
		||||
BUILDATE=$(date '+%s')
 | 
			
		||||
DISTDATE=$(date '+%Y-%m-%d %H:%M')
 | 
			
		||||
 | 
			
		||||
BRANCH=$(git -C "${DIR}" symbolic-ref -q --short HEAD)
 | 
			
		||||
VERSION=$(git -C "${DIR}" describe --tags --first-parent 2>/dev/null)
 | 
			
		||||
 | 
			
		||||
[ -z "${BRANCH}" ] && BRANCH=$(echo "${TRAVIS_BRANCH}")
 | 
			
		||||
[ -z "${VERSION}" ] && VERSION=$(git -C "${DIR}" describe --tags --first-parent --always 2>/dev/null)
 | 
			
		||||
 | 
			
		||||
SHORT_BUILD_VERSION=$(echo "${BRANCH}")
 | 
			
		||||
DETAILED_BUILD_VERSION=$(echo "${BRANCH}-${VERSION}")
 | 
			
		||||
STRING_DISTRIBUTION_DATE="${STRING_DISTRIBUTION_DATE:-$(date '+%Y-%m-%d %H:%M')}"
 | 
			
		||||
SHORT_BUILD_VERSION="${SHORT_BUILD_VERSION:-${BRANCH}}"
 | 
			
		||||
DETAILED_BUILD_VERSION="${DETAILED_BUILD_VERSION:-${BRANCH}-${VERSION}}"
 | 
			
		||||
 | 
			
		||||
# Gets some misc options from their defaults
 | 
			
		||||
DEFAULT_MACHINE_UUID=$(awk -F'"' \
 | 
			
		||||
  '/#define DEFAULT_MACHINE_UUID/{ print $2 }' < "${DIR}/Version.h")
 | 
			
		||||
MACHINE_NAME=$(awk -F'"' \
 | 
			
		||||
  '/#define MACHINE_NAME/{ print $2 }' < "${DIR}/Version.h")
 | 
			
		||||
PROTOCOL_VERSION=$(awk -F'"' \
 | 
			
		||||
  '/#define PROTOCOL_VERSION/{ print $2 }' < "${DIR}/Version.h")
 | 
			
		||||
SOURCE_CODE_URL=$(awk -F'"' \
 | 
			
		||||
  '/#define SOURCE_CODE_URL/{ print $2 }' < "${DIR}/Version.h")
 | 
			
		||||
WEBSITE_URL=$(awk -F'"' \
 | 
			
		||||
  '/#define WEBSITE_URL/{ print $2 }' < "${DIR}/Version.h")
 | 
			
		||||
DEFAULT_MACHINE_UUID="${DEFAULT_MACHINE_UUID:-$(awk -F'"' \
 | 
			
		||||
  '/#define DEFAULT_MACHINE_UUID/{ print $2 }' < "${READ_FILE}")}"
 | 
			
		||||
MACHINE_NAME="${MACHINE_NAME:-$(awk -F'"' \
 | 
			
		||||
  '/#define MACHINE_NAME/{ print $2 }' < "${READ_FILE}")}"
 | 
			
		||||
PROTOCOL_VERSION="${PROTOCOL_VERSION:-$(awk -F'"' \
 | 
			
		||||
  '/#define PROTOCOL_VERSION/{ print $2 }' < "${READ_FILE}")}"
 | 
			
		||||
SOURCE_CODE_URL="${SOURCE_CODE_URL:-$(awk -F'"' \
 | 
			
		||||
  '/#define SOURCE_CODE_URL/{ print $2 }' < "${READ_FILE}")}"
 | 
			
		||||
WEBSITE_URL="${WEBSITE_URL:-$(awk -F'"' \
 | 
			
		||||
  '/#define WEBSITE_URL/{ print $2 }' < "${READ_FILE}")}"
 | 
			
		||||
 | 
			
		||||
cat > "${DIR}/Version.h" <<EOF
 | 
			
		||||
cat > "${WRITE_FILE}" <<EOF
 | 
			
		||||
/**
 | 
			
		||||
 * Marlin 3D Printer Firmware
 | 
			
		||||
 * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
 | 
			
		||||
@@ -97,7 +85,7 @@ cat > "${DIR}/Version.h" <<EOF
 | 
			
		||||
  * version was tagged.
 | 
			
		||||
  */
 | 
			
		||||
#ifndef STRING_DISTRIBUTION_DATE
 | 
			
		||||
  #define STRING_DISTRIBUTION_DATE "${DISTDATE}"
 | 
			
		||||
  #define STRING_DISTRIBUTION_DATE "${STRING_DISTRIBUTION_DATE}"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										338
									
								
								buildroot/bin/mftest
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										338
									
								
								buildroot/bin/mftest
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,338 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
#  mftest                             Select a test to apply and build
 | 
			
		||||
#  mftest -b [#]                      Build the auto-detected environment
 | 
			
		||||
#  mftest -u [#]                      Upload the auto-detected environment
 | 
			
		||||
#  mftest -tname -n# [-y]             Set config options and optionally build a test
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
[[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }
 | 
			
		||||
 | 
			
		||||
perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; }
 | 
			
		||||
errout() { echo -e "\033[0;31m$1\033[0m" ; }
 | 
			
		||||
bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }
 | 
			
		||||
 | 
			
		||||
usage() {
 | 
			
		||||
  echo "
 | 
			
		||||
Usage: mftest [-t|--env=<env|index>] [-n|--num=<num>] [-m|--make] [-y|--build=<Y|n>]
 | 
			
		||||
       mftest [-a|--autobuild]
 | 
			
		||||
       mftest [-r|--rebuild]
 | 
			
		||||
       mftest [-s|--silent]
 | 
			
		||||
       mftest [-u|--autoupload] [-n|--num=<num>]
 | 
			
		||||
 | 
			
		||||
OPTIONS
 | 
			
		||||
  -t --env         The environment to apply / run, or the menu index number.
 | 
			
		||||
  -n --num         The index of the test to run. (In file order.)
 | 
			
		||||
  -m --make        Use the make / Docker method for the build.
 | 
			
		||||
  -y --build       Skip 'Do you want to build this test?' and assume YES.
 | 
			
		||||
  -h --help        Print this help.
 | 
			
		||||
  -a --autobuild   PIO Build using the MOTHERBOARD environment.
 | 
			
		||||
  -u --autoupload  PIO Upload using the MOTHERBOARD environment.
 | 
			
		||||
  -v --verbose     Extra output for debugging.
 | 
			
		||||
  -s --silent      Silence build output from PlatformIO.
 | 
			
		||||
  -d --default     Restore to defaults before applying configs.
 | 
			
		||||
 | 
			
		||||
env shortcuts: tree due esp lin lp8|lpc8 lp9|lpc9 m128 m256|mega stm|f1 f4 f7 s6 teensy|t31|t32 t35|t36 t40|t41
 | 
			
		||||
"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TESTPATH=buildroot/tests
 | 
			
		||||
 | 
			
		||||
STATE_FILE="./.pio/.mftestrc"
 | 
			
		||||
SED=$(which gsed sed | head -n1)
 | 
			
		||||
 | 
			
		||||
shopt -s extglob nocasematch
 | 
			
		||||
 | 
			
		||||
# Matching patterns
 | 
			
		||||
ISNUM='^[0-9]+$'
 | 
			
		||||
ISRST='^(restore)_'
 | 
			
		||||
ISCMD='^(restore|opt|exec|use|pins|env)_'
 | 
			
		||||
ISEXEC='^exec_'
 | 
			
		||||
ISCONT='\\ *$'
 | 
			
		||||
 | 
			
		||||
# Get environment, test number, etc. from the command
 | 
			
		||||
TESTENV='-'
 | 
			
		||||
CHOICE=0
 | 
			
		||||
DEBUG=0
 | 
			
		||||
 | 
			
		||||
while getopts 'abdhmrsuvyn:t:-:' OFLAG; do
 | 
			
		||||
  case "${OFLAG}" in
 | 
			
		||||
    a) AUTO_BUILD=1 ; bugout "Auto-Build target..." ;;
 | 
			
		||||
    d) DL_DEFAULTS=1 ; bugout "Restore to defaults..." ;;
 | 
			
		||||
    h) EXIT_USAGE=1 ;;
 | 
			
		||||
    m) USE_MAKE=1 ; bugout "Using make with Docker..." ;;
 | 
			
		||||
    n) case "$OPTARG" in
 | 
			
		||||
         *[!0-9]*) perror "option requires a number" $OFLAG ; EXIT_USAGE=2 ;;
 | 
			
		||||
                *) CHOICE="$OPTARG" ; bugout "Got a number: $CHOICE" ;;
 | 
			
		||||
       esac
 | 
			
		||||
       ;;
 | 
			
		||||
    r) REBUILD=1         ; bugout "Rebuilding previous..." ;;
 | 
			
		||||
    s) SILENT_FLAG="-s" ;;
 | 
			
		||||
    t) TESTENV="$OPTARG" ; bugout "Got a target: $TESTENV" ;;
 | 
			
		||||
    u) AUTO_BUILD=2      ; bugout "Auto-Upload target..." ;;
 | 
			
		||||
    v) DEBUG=1           ; bugout "Debug ON" ;;
 | 
			
		||||
    y) BUILD_YES='Y'     ; bugout "Build will initiate..." ;;
 | 
			
		||||
    -) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
 | 
			
		||||
       case "$ONAM" in
 | 
			
		||||
         help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
 | 
			
		||||
    autobuild) AUTO_BUILD=1 ; bugout "Auto-Build target..."  ;;
 | 
			
		||||
   autoupload) AUTO_BUILD=2 ; bugout "Auto-Upload target..." ;;
 | 
			
		||||
          env) case "$OVAL" in
 | 
			
		||||
                 '') perror "option requires a value" $ONAM ; EXIT_USAGE=2 ;;
 | 
			
		||||
                  *) TESTENV="$OVAL" ; bugout "Got a target: $TESTENV" ;;
 | 
			
		||||
               esac
 | 
			
		||||
               ;;
 | 
			
		||||
          num) case "$OVAL" in
 | 
			
		||||
                 [0-9]+) CHOICE="$OVAL" ; bugout "Got a number: $CHOICE" ;;
 | 
			
		||||
                      *) perror "option requires a value" $ONAM ; EXIT_USAGE=2 ;;
 | 
			
		||||
               esac
 | 
			
		||||
               ;;
 | 
			
		||||
      rebuild) REBUILD=1  ; bugout "Rebuilding previous..." ;;
 | 
			
		||||
       silent) SILENT_FLAG="-s" ;;
 | 
			
		||||
         make) USE_MAKE=1 ; bugout "Using make with Docker..." ;;
 | 
			
		||||
debug|verbose) DEBUG=1    ; bugout "Debug ON" ;;
 | 
			
		||||
      default) DL_DEFAULTS=1 ; bugout "Restore to defaults..." ;;
 | 
			
		||||
        build) case "$OVAL" in
 | 
			
		||||
                 ''|y|yes) BUILD_YES='Y' ;;
 | 
			
		||||
                     n|no) BUILD_YES='N' ;;
 | 
			
		||||
                        *) perror "option value must be y, n, yes, or no" $ONAM ; EXIT_USAGE=2 ;;
 | 
			
		||||
               esac
 | 
			
		||||
               bugout "Build will initiate? ($BUILD_YES)"
 | 
			
		||||
               ;;
 | 
			
		||||
            *) perror "Unknown flag" "$OPTARG" ; EXIT_USAGE=2 ;;
 | 
			
		||||
       esac
 | 
			
		||||
       ;;
 | 
			
		||||
    *) EXIT_USAGE=2 ;;
 | 
			
		||||
  esac
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
 | 
			
		||||
 | 
			
		||||
if ((REBUILD)); then
 | 
			
		||||
  bugout "Rebuilding previous..."
 | 
			
		||||
  # Build with the last-built env
 | 
			
		||||
  [[ -f "$STATE_FILE" ]] || { errout "No previous (-r) build state found." ; exit 1 ; }
 | 
			
		||||
  read TESTENV <"$STATE_FILE"
 | 
			
		||||
  pio run $SILENT_FLAG -d . -e $TESTENV
 | 
			
		||||
  exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
case $TESTENV in
 | 
			
		||||
    tree) pio run -d . -e include_tree ; exit 1 ;;
 | 
			
		||||
     due) TESTENV='DUE' ;;
 | 
			
		||||
     esp) TESTENV='esp32' ;;
 | 
			
		||||
    lin*) TESTENV='linux_native' ;;
 | 
			
		||||
lp8|lpc8) TESTENV='LPC1768' ;;
 | 
			
		||||
lp9|lpc9) TESTENV='LPC1769' ;;
 | 
			
		||||
    m128) TESTENV='mega1280' ;;
 | 
			
		||||
    m256) TESTENV='mega2560' ;;
 | 
			
		||||
    mega) TESTENV='mega2560' ;;
 | 
			
		||||
     stm) TESTENV='STM32F103RE' ;;
 | 
			
		||||
      f1) TESTENV='STM32F103RE' ;;
 | 
			
		||||
      f4) TESTENV='STM32F4' ;;
 | 
			
		||||
      f7) TESTENV='STM32F7' ;;
 | 
			
		||||
      s6) TESTENV='FYSETC_S6' ;;
 | 
			
		||||
  teensy) TESTENV='teensy31' ;;
 | 
			
		||||
     t31) TESTENV='teensy31' ;;
 | 
			
		||||
     t32) TESTENV='teensy31' ;;
 | 
			
		||||
     t35) TESTENV='teensy35' ;;
 | 
			
		||||
     t36) TESTENV='teensy35' ;;
 | 
			
		||||
     t40) TESTENV='teensy41' ;;
 | 
			
		||||
     t41) TESTENV='teensy41' ;;
 | 
			
		||||
[1-9]|[1-9][0-9]) TESTNUM=$TESTENV ; TESTENV=- ;;
 | 
			
		||||
esac
 | 
			
		||||
 | 
			
		||||
if ((AUTO_BUILD)); then
 | 
			
		||||
  #
 | 
			
		||||
  # List environments that apply to the current MOTHERBOARD.
 | 
			
		||||
  #
 | 
			
		||||
  case $(uname | tr '[:upper:]' '[:lower:]') in
 | 
			
		||||
    darwin) SYS='mac' ;;
 | 
			
		||||
    *linux) SYS='lin' ;;
 | 
			
		||||
      win*) SYS='win' ;;
 | 
			
		||||
     msys*) SYS='win' ;;
 | 
			
		||||
   cygwin*) SYS='win' ;;
 | 
			
		||||
    mingw*) SYS='win' ;;
 | 
			
		||||
         *) SYS='uni' ;;
 | 
			
		||||
  esac
 | 
			
		||||
  echo ; echo -n "Auto " ; ((AUTO_BUILD == 2)) && echo "Upload..." || echo "Build..."
 | 
			
		||||
  MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Configuration.h | awk '{ print $3 }' | $SED 's/BOARD_//;s/\r//' )
 | 
			
		||||
  [[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
 | 
			
		||||
  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" )
 | 
			
		||||
  [[ -z $BNUM ]] && { echo "Error - Can't find BOARD_$MB in core/boards.h." ; exit 1 ; }
 | 
			
		||||
  ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | $SED -E "s/(env|$SYS)://" ) )
 | 
			
		||||
  [[ -z $ENVS ]] && { errout "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
 | 
			
		||||
  ECOUNT=${#ENVS[*]}
 | 
			
		||||
 | 
			
		||||
  if [[ $ECOUNT == 1 ]]; then
 | 
			
		||||
    TARGET=$ENVS
 | 
			
		||||
  else
 | 
			
		||||
    if [[ $CHOICE == 0 ]]; then
 | 
			
		||||
      # List env names and numbers. Get selection.
 | 
			
		||||
      echo "Available targets for \"$BDESC\" | $MB ($BNUM):"
 | 
			
		||||
 | 
			
		||||
      IND=0 ; for ENV in "${ENVS[@]}"; do let IND++ ; echo " $IND) $ENV" ; done
 | 
			
		||||
 | 
			
		||||
      if [[ $ECOUNT > 1 ]]; then
 | 
			
		||||
        for (( ; ; ))
 | 
			
		||||
        do
 | 
			
		||||
          read -p "Select a target for '$MB' (1-$ECOUNT) : " CHOICE
 | 
			
		||||
          [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
 | 
			
		||||
          [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= ECOUNT)) && break
 | 
			
		||||
          errout ">>> Invalid environment choice '$CHOICE'."
 | 
			
		||||
        done
 | 
			
		||||
        echo
 | 
			
		||||
      fi
 | 
			
		||||
    else
 | 
			
		||||
      echo "Detected \"$BDESC\" | $MB ($BNUM)."
 | 
			
		||||
      [[ $CHOICE > $ECOUNT ]] && { echo "Environment selection out of range." ; exit 1 ; }
 | 
			
		||||
    fi
 | 
			
		||||
    TARGET="${ENVS[$CHOICE-1]}"
 | 
			
		||||
    echo "Selected $TARGET"
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  echo "$TARGET" >"$STATE_FILE"
 | 
			
		||||
 | 
			
		||||
  if ((AUTO_BUILD == 2)); then
 | 
			
		||||
    echo "Uploading environment $TARGET for board $MB ($BNUM)..." ; echo
 | 
			
		||||
    pio run $SILENT_FLAG -t upload -e $TARGET
 | 
			
		||||
  else
 | 
			
		||||
    echo "Building environment $TARGET for board $MB ($BNUM)..." ; echo
 | 
			
		||||
    pio run $SILENT_FLAG -e $TARGET
 | 
			
		||||
  fi
 | 
			
		||||
  exit $?
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# List available tests and ask for selection
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
if [[ $TESTENV == '-' ]]; then
 | 
			
		||||
  IND=0
 | 
			
		||||
  NAMES=()
 | 
			
		||||
  MENU=()
 | 
			
		||||
  BIGLEN=0
 | 
			
		||||
  for FILE in $( ls -1 $TESTPATH/* | sort -f )
 | 
			
		||||
  do
 | 
			
		||||
    let IND++
 | 
			
		||||
    TNAME=${FILE/$TESTPATH\//}
 | 
			
		||||
    NAMES+=($TNAME)
 | 
			
		||||
    IFS=""
 | 
			
		||||
    ITEM=$( printf "%2i) %s" $IND $TNAME )
 | 
			
		||||
    MENU+=($ITEM)
 | 
			
		||||
    [[ ${#ITEM} -gt $BIGLEN ]] && BIGLEN=${#ITEM}
 | 
			
		||||
  done
 | 
			
		||||
 | 
			
		||||
  (( BIGLEN += 2 ))
 | 
			
		||||
  THIRD=$(( (${#MENU[@]} + 2) / 3 ))
 | 
			
		||||
  for ((i = 0; i < $THIRD; i++))
 | 
			
		||||
  do
 | 
			
		||||
    COL1=$i ; COL2=$(( $i + $THIRD )) ; COL3=$(( $i + 2 * $THIRD ))
 | 
			
		||||
    FMT="%-${BIGLEN}s"
 | 
			
		||||
    printf "${FMT}${FMT}${FMT}\n" ${MENU[$COL1]} ${MENU[$COL2]} ${MENU[$COL3]}
 | 
			
		||||
  done
 | 
			
		||||
 | 
			
		||||
  echo
 | 
			
		||||
  for (( ; ; ))
 | 
			
		||||
  do
 | 
			
		||||
    if [[ $TESTNUM -gt 0 ]]; then
 | 
			
		||||
      NAMEIND=$TESTNUM
 | 
			
		||||
    else
 | 
			
		||||
      read -p "Select a test to apply (1-$IND) : " NAMEIND
 | 
			
		||||
    fi
 | 
			
		||||
    [[ -z $NAMEIND ]] && { errout "(canceled)" ; exit 1 ; }
 | 
			
		||||
    TESTENV=${NAMES[$NAMEIND-1]}
 | 
			
		||||
    [[ $TESTNUM -gt 0 ]] && { echo "Preselected test $TESTNUM ... ($TESTENV)" ; TESTNUM='' ; }
 | 
			
		||||
    [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
 | 
			
		||||
    errout "Invalid selection."
 | 
			
		||||
  done
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Get the contents of the test file
 | 
			
		||||
OUT=$( cat $TESTPATH/$TESTENV 2>/dev/null ) || { errout "Can't find test '$TESTENV'." ; exit 1 ; }
 | 
			
		||||
 | 
			
		||||
# Count up the number of tests
 | 
			
		||||
TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
 | 
			
		||||
 | 
			
		||||
# User entered a number?
 | 
			
		||||
(( CHOICE && CHOICE > TESTCOUNT )) && { errout "Invalid test selection '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
 | 
			
		||||
 | 
			
		||||
if [[ $CHOICE == 0 ]]; then
 | 
			
		||||
  #
 | 
			
		||||
  # List test descriptions with numbers and get selection
 | 
			
		||||
  #
 | 
			
		||||
  echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
 | 
			
		||||
    IND=0
 | 
			
		||||
    while IFS= read -r LINE
 | 
			
		||||
    do
 | 
			
		||||
      if [[ $LINE =~ $ISEXEC ]]; then
 | 
			
		||||
        DESC=$( "$SED" -E 's/^exec_test \$1 \$2 "([^"]+)".*$/\1/g' <<<"$LINE" )
 | 
			
		||||
        (( ++IND < 10 )) && echo -n " "
 | 
			
		||||
        echo " $IND) $DESC"
 | 
			
		||||
      fi
 | 
			
		||||
    done
 | 
			
		||||
  }
 | 
			
		||||
  CHOICE=1
 | 
			
		||||
  if [[ $TESTCOUNT > 1 ]]; then
 | 
			
		||||
    for (( ; ; ))
 | 
			
		||||
    do
 | 
			
		||||
      read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
 | 
			
		||||
      [[ -z "$CHOICE" ]] && { errout "(canceled)" ; exit 1 ; }
 | 
			
		||||
      [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
 | 
			
		||||
      errout ">>> Invalid test selection '$CHOICE'."
 | 
			
		||||
    done
 | 
			
		||||
  fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Restore to defaults if requested
 | 
			
		||||
#
 | 
			
		||||
((DL_DEFAULTS)) && use_example_configs
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Run the specified test lines
 | 
			
		||||
#
 | 
			
		||||
echo -ne "\033[0;33m"
 | 
			
		||||
echo "$OUT" | {
 | 
			
		||||
  IND=0
 | 
			
		||||
  GOTX=0
 | 
			
		||||
  CMD=""
 | 
			
		||||
  while IFS= read -r LINE
 | 
			
		||||
  do
 | 
			
		||||
    if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
 | 
			
		||||
      ((!IND)) && let IND++
 | 
			
		||||
      if [[ $LINE =~ $ISEXEC ]]; then
 | 
			
		||||
        ((IND++ > CHOICE)) && break
 | 
			
		||||
      else
 | 
			
		||||
        ((!HEADER)) && {
 | 
			
		||||
          HEADER=1
 | 
			
		||||
          echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
 | 
			
		||||
        }
 | 
			
		||||
        ((IND == CHOICE)) && {
 | 
			
		||||
          GOTX=1
 | 
			
		||||
          [[ -n $DL_DEFAULTS && $LINE =~ $ISRST ]] && LINE="use_example_configs"
 | 
			
		||||
          [[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | $SED -e 's/\\//g' | $SED -E 's/ +/ /g' )
 | 
			
		||||
          [[ $LINE =~ $ISCONT ]] || { echo "$CMD" ; eval "$CMD" ; CMD="" ; }
 | 
			
		||||
        }
 | 
			
		||||
      fi
 | 
			
		||||
    fi
 | 
			
		||||
  done
 | 
			
		||||
}
 | 
			
		||||
echo -ne "\033[0m"
 | 
			
		||||
 | 
			
		||||
# Make clear it's a TEST
 | 
			
		||||
opt_set CUSTOM_MACHINE_NAME "\"Test $TESTENV ($CHOICE)\""
 | 
			
		||||
 | 
			
		||||
# Build the test too?
 | 
			
		||||
if [[ -z "$BUILD_YES" ]]; then
 | 
			
		||||
  echo
 | 
			
		||||
  read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
[[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
 | 
			
		||||
  ((USE_MAKE)) && make tests-single-local TEST_TARGET=$TESTENV ONLY_TEST=$CHOICE
 | 
			
		||||
  ((USE_MAKE)) || pio run $SILENT_FLAG -d . -e $TESTENV
 | 
			
		||||
  echo "$TESTENV" >"$STATE_FILE"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								buildroot/bin/mfutil
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								buildroot/bin/mfutil
									
									
									
									
									
										Executable file
									
								
							@@ -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" ; }
 | 
			
		||||
@@ -3,11 +3,13 @@
 | 
			
		||||
# exit on first failure
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
SED=$(which gsed || which sed)
 | 
			
		||||
SED=$(which gsed sed | head -n1)
 | 
			
		||||
 | 
			
		||||
for opt in "$@" ; do
 | 
			
		||||
  # Logic for returning nonzero based on answer here: https://stackoverflow.com/a/15966279/104648
 | 
			
		||||
  eval "${SED} -i '/\([[:blank:]]*\)\(\/\/\)*\([[:blank:]]*\)\(#define \b${opt}\b\)/{s//\1\3\/\/\4/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration.h" ||
 | 
			
		||||
  eval "${SED} -i '/\([[:blank:]]*\)\(\/\/\)*\([[:blank:]]*\)\(#define \b${opt}\b\)/{s//\1\3\/\/\4/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration_adv.h" ||
 | 
			
		||||
  (echo "ERROR: opt_disable Can't find ${opt}" >&2 && exit 9)
 | 
			
		||||
  DID=0 ; FOUND=0
 | 
			
		||||
  for FN in Configuration Configuration_adv; do
 | 
			
		||||
    "${SED}" -i "/^\(\s*\)\(#define\s\+${opt}\b\s\?\)\(\s\s\)\?/{s//\1\/\/\2/;h};\${x;/./{x;q0};x;q9}" Marlin/$FN.h && DID=1
 | 
			
		||||
    ((DID||FOUND)) || { grep -E "^\s*//\s*#define\s+${opt}\b" Marlin/$FN.h >/dev/null && FOUND=1 ; }
 | 
			
		||||
  done
 | 
			
		||||
  ((DID||FOUND)) || (echo "ERROR: $(basename $0) Can't find ${opt}" >&2 && exit 9)
 | 
			
		||||
done
 | 
			
		||||
 
 | 
			
		||||
@@ -3,11 +3,13 @@
 | 
			
		||||
# exit on first failure
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
SED=$(which gsed || which sed)
 | 
			
		||||
SED=$(which gsed sed | head -n1)
 | 
			
		||||
 | 
			
		||||
for opt in "$@" ; do
 | 
			
		||||
  # Logic for returning nonzero based on answer here: https://stackoverflow.com/a/15966279/104648
 | 
			
		||||
  eval "${SED} -i '/\(\/\/\)*[[:blank:]]*\(#define \b${opt}\b\)/{s//\2/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration.h" ||
 | 
			
		||||
  eval "${SED} -i '/\(\/\/\)*[[:blank:]]*\(#define \b${opt}\b\)/{s//\2/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration_adv.h" ||
 | 
			
		||||
  (echo "ERROR: opt_enable Can't find ${opt}" >&2 && exit 9)
 | 
			
		||||
  DID=0 ; FOUND=0
 | 
			
		||||
  for FN in Configuration Configuration_adv; do
 | 
			
		||||
    "${SED}" -i "/^\(\s*\)\/\/\(\s*\)\(#define\s\+${opt}\b\)\( \?\)/{s//\1\2\3\4\4\4/;h};\${x;/./{x;q0};x;q9}" Marlin/$FN.h && DID=1
 | 
			
		||||
    ((DID||FOUND)) || { grep -E "^\s*#define\s+${opt}\b" Marlin/$FN.h >/dev/null && FOUND=1 ; }
 | 
			
		||||
  done
 | 
			
		||||
  ((DID||FOUND)) || (echo "ERROR: $(basename $0) Can't find ${opt}" >&2 && exit 9)
 | 
			
		||||
done
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								buildroot/bin/opt_find
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										33
									
								
								buildroot/bin/opt_find
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
# opt_find
 | 
			
		||||
# Find one or more Marlin options - Configuration lines starting with #define
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
MYNAME=$(basename $0)
 | 
			
		||||
 | 
			
		||||
[[ $# == 0 ]] && ONE="-h" || ONE=$1
 | 
			
		||||
 | 
			
		||||
COMM="(//\\s*)?" ; TYPE=""
 | 
			
		||||
case "$ONE" in
 | 
			
		||||
  -d|--disabled )
 | 
			
		||||
      shift ; COMM="(//\\s*)" ; TYPE="disabled " ;;
 | 
			
		||||
  -e|--enabled )
 | 
			
		||||
      shift ; COMM="" ; TYPE="enabled " ;;
 | 
			
		||||
  -h|--help )
 | 
			
		||||
      echo "$MYNAME [-d|--disabled|-e|--enabled] STRING ... Find matching Marlin configuration options."
 | 
			
		||||
      echo ; shift ;;
 | 
			
		||||
  -* )
 | 
			
		||||
      echo "Unknown option $ONE" ; shift ;;
 | 
			
		||||
esac
 | 
			
		||||
 | 
			
		||||
while [[ $# > 0 ]]; do
 | 
			
		||||
  DID=0
 | 
			
		||||
  for FN in Configuration Configuration_adv; do
 | 
			
		||||
    FOUND=$( grep -HEn "^\s*${COMM}#define\s+[A-Z0-9_]*${1}" "Marlin/$FN.h" 2>/dev/null )
 | 
			
		||||
    [[ -n "$FOUND" ]] && { echo "$FOUND" ; DID=1 ; }
 | 
			
		||||
  done
 | 
			
		||||
  ((DID)) || { echo "ERROR: ${MYNAME} - No ${TYPE}match for ${1}" ; exit 9; }
 | 
			
		||||
  shift
 | 
			
		||||
  echo
 | 
			
		||||
done
 | 
			
		||||
@@ -3,10 +3,15 @@
 | 
			
		||||
# exit on first failure
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
SED=$(which gsed || which sed)
 | 
			
		||||
SED=$(which gsed sed | head -n1)
 | 
			
		||||
 | 
			
		||||
# Logic for returning nonzero based on answer here: https://stackoverflow.com/a/15966279/104648
 | 
			
		||||
eval "${SED} -i '/\(\/\/\)*\([[:blank:]]*\)\(#define\s\+\b${1}\b\).*$/{s//\2\3 ${2}/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration.h" ||
 | 
			
		||||
eval "${SED} -i '/\(\/\/\)*\([[:blank:]]*\)\(#define\s\+\b${1}\b\).*$/{s//\2\3 ${2}/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration_adv.h" ||
 | 
			
		||||
eval "echo '#define ${@}' >>Marlin/Configuration_adv.h" ||
 | 
			
		||||
(echo "ERROR: opt_set Can't set or add ${1}" >&2 && exit 9)
 | 
			
		||||
while [[ $# > 1 ]]; do
 | 
			
		||||
  DID=0
 | 
			
		||||
  for FN in Configuration Configuration_adv; do
 | 
			
		||||
    "${SED}" -i "/^\(\s*\)\/*\s*\(#define\s\+${1}\b\) *\(.*\)$/{s//\1\2 ${2} \/\/ \3/;h};\${x;/./{x;q0};x;q9}" Marlin/$FN.h && DID=1
 | 
			
		||||
  done
 | 
			
		||||
  ((DID)) ||
 | 
			
		||||
    eval "echo '#define ${1} ${2}' >>Marlin/Configuration.h" ||
 | 
			
		||||
      (echo "ERROR: opt_set Can't set or add ${1}" >&2 && exit 9)
 | 
			
		||||
  shift 2
 | 
			
		||||
done
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,13 @@
 | 
			
		||||
IFS='/' read -r -a PINPATH <<< "$1"
 | 
			
		||||
DIR=${PINPATH[0]}
 | 
			
		||||
NAM=${PINPATH[1]}
 | 
			
		||||
PIN=$2
 | 
			
		||||
VAL=$3
 | 
			
		||||
 | 
			
		||||
SED=$(which gsed || which sed)
 | 
			
		||||
eval "${SED} -i '/\(\/\/\)*\(#define \+${PIN}\b\).*$/{s//\2 ${VAL}/;h};\${x;/./{x;q0};x;q9}' Marlin/src/pins/$DIR/pins_${NAM}.h" ||
 | 
			
		||||
(echo "ERROR: pins_set Can't find ${PIN}" >&2 && exit 9)
 | 
			
		||||
SED=$(which gsed sed | head -n1)
 | 
			
		||||
 | 
			
		||||
shift
 | 
			
		||||
while [[ $# > 1 ]]; do
 | 
			
		||||
  PIN=$1 ; VAL=$2
 | 
			
		||||
  eval "${SED} -i '/^[[:blank:]]*\(\/\/\)*[[:blank:]]*\(#define \+${PIN}\b\).*$/{s//\2 ${VAL}/;h};\${x;/./{x;q0};x;q9}' Marlin/src/pins/$DIR/pins_${NAM}.h" ||
 | 
			
		||||
  (echo "ERROR: pins_set Can't find ${PIN}" >&2 && exit 9)
 | 
			
		||||
  shift 2
 | 
			
		||||
done
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,11 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
git checkout Marlin/Configuration*.h 2>/dev/null
 | 
			
		||||
git checkout Marlin/src/pins/ramps/pins_RAMPS.h 2>/dev/null
 | 
			
		||||
rm -f Marlin/_Bootscreen.h Marlin/_Statusscreen.h
 | 
			
		||||
rm -f Marlin/_Bootscreen.h Marlin/_Statusscreen.h marlin_config.json .pio/build/mc.zip
 | 
			
		||||
 | 
			
		||||
if [[ $1 == '-d' || $1 == '--default' ]]; then
 | 
			
		||||
  use_example_configs
 | 
			
		||||
else
 | 
			
		||||
  git checkout Marlin/Configuration.h 2>/dev/null
 | 
			
		||||
  git checkout Marlin/Configuration_adv.h 2>/dev/null
 | 
			
		||||
  git checkout Marlin/src/pins/ramps/pins_RAMPS.h 2>/dev/null
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										77
									
								
								buildroot/bin/run_tests
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										77
									
								
								buildroot/bin/run_tests
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
# run_tests
 | 
			
		||||
#
 | 
			
		||||
HERE="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
 | 
			
		||||
TESTS="$HERE/../tests"
 | 
			
		||||
export PATH="$HERE:$TESTS:$PATH"
 | 
			
		||||
 | 
			
		||||
# exit on first failure
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
exec_test () {
 | 
			
		||||
  printf "\n\033[0;32m[Test $2] \033[0m$3...\n"
 | 
			
		||||
  # Check to see if we should skip tests
 | 
			
		||||
  if [[ -n "$4" ]] ; then
 | 
			
		||||
    if [[ ! "$3" =~ $4 ]] ; then
 | 
			
		||||
      printf "\033[1;33mSkipped\033[0m\n"
 | 
			
		||||
      return 0
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
  if [[ -z "$VERBOSE_PLATFORMIO" ]] ; then
 | 
			
		||||
    silent="--silent"
 | 
			
		||||
  else
 | 
			
		||||
    silent="-v"
 | 
			
		||||
  fi
 | 
			
		||||
  if platformio run --project-dir $1 -e $2 $silent; then
 | 
			
		||||
    printf "\033[0;32mPassed\033[0m\n"
 | 
			
		||||
    return 0
 | 
			
		||||
  else
 | 
			
		||||
    if [[ -n $GIT_RESET_HARD ]]; then
 | 
			
		||||
      git reset --hard HEAD
 | 
			
		||||
    else
 | 
			
		||||
      restore_configs
 | 
			
		||||
    fi
 | 
			
		||||
    printf "\033[0;31mFailed!\033[0m\n"
 | 
			
		||||
    return 1
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
export -f exec_test
 | 
			
		||||
 | 
			
		||||
printf "Running \033[0;32m$2\033[0m Tests\n"
 | 
			
		||||
 | 
			
		||||
if [[ $2 = "ALL" ]]; then
 | 
			
		||||
  tests=("$TESTS"/*)
 | 
			
		||||
  for f in "${tests[@]}"; do
 | 
			
		||||
    testenv=$(basename $f)
 | 
			
		||||
    printf "Running \033[0;32m$f\033[0m Tests\n"
 | 
			
		||||
    exec_test $1 "$testenv --target clean" "Setup Build Environment"
 | 
			
		||||
    if [[ $GIT_RESET_HARD == "true" ]]; then
 | 
			
		||||
      git reset --hard HEAD
 | 
			
		||||
    else
 | 
			
		||||
      restore_configs
 | 
			
		||||
    fi
 | 
			
		||||
  done
 | 
			
		||||
else
 | 
			
		||||
  exec_test $1 "$2 --target clean" "Setup Build Environment"
 | 
			
		||||
  test_name="$3"
 | 
			
		||||
  # If the test name is 1 or 2 digits, treat it as an index
 | 
			
		||||
  if [[ "$test_name" =~ ^[0-9][0-9]?$ ]] ; then
 | 
			
		||||
    # Find the test name that corresponds to that index
 | 
			
		||||
    test_name="$(cat $TESTS/$2 | grep -e '^exec_test' | sed -n "$3p" | sed "s/.*\$1 \$2 \"\([^\"]*\).*/\1/g")"
 | 
			
		||||
    if [[ -z "$test_name" ]] ; then
 | 
			
		||||
      # Fail if none matches
 | 
			
		||||
      printf "\033[0;31mCould not find test \033[0m#$3\033[0;31m in \033[0mbuildroot/tests/$2\n"
 | 
			
		||||
      exit 1
 | 
			
		||||
    else
 | 
			
		||||
      printf "\033[0;32mMatching test \033[0m#$3\033[0;32m: '\033[0m$test_name\033[0;32m'\n"
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
  $TESTS/$2 $1 $2 "$test_name"
 | 
			
		||||
  if [[ $GIT_RESET_HARD == "true" ]]; then
 | 
			
		||||
    git reset --hard HEAD
 | 
			
		||||
  else
 | 
			
		||||
    restore_configs
 | 
			
		||||
  fi
 | 
			
		||||
fi
 | 
			
		||||
printf "\033[0;32mAll tests completed successfully\033[0m\n"
 | 
			
		||||
@@ -6,11 +6,12 @@
 | 
			
		||||
TMPDIR=`mktemp -d`
 | 
			
		||||
 | 
			
		||||
# Reformat a single file to tmp/
 | 
			
		||||
uncrustify -l CPP -c ./buildroot/share/extras/uncrustify.cfg -f "$1" >$TMPDIR/uncrustify.out
 | 
			
		||||
 | 
			
		||||
# Replace the original file
 | 
			
		||||
cp "$TMPDIR/uncrustify.out" "$1"
 | 
			
		||||
if uncrustify -l CPP -c ./buildroot/share/extras/uncrustify.cfg -f "$1" >$TMPDIR/uncrustify.out ; then
 | 
			
		||||
  cp "$TMPDIR/uncrustify.out" "$1"  ; # Replace the original file
 | 
			
		||||
else
 | 
			
		||||
  echo "Something went wrong with uncrustify."
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Clean up, deliberately
 | 
			
		||||
rm "$TMPDIR/uncrustify.out"
 | 
			
		||||
[[ -f "$TMPDIR/uncrustify.out" ]] && rm "$TMPDIR/uncrustify.out"
 | 
			
		||||
rmdir "$TMPDIR"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,21 +1,44 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
IFS=: read -r PART1 PART2 <<< "$@"
 | 
			
		||||
[ -n "${PART2}" ] && { REPO="$PART1" ; RDIR="${PART2// /%20}" ; } \
 | 
			
		||||
                  || { REPO=bugfix-2.0.x   ; RDIR="${PART1// /%20}" ; }
 | 
			
		||||
EXAMPLES="https://raw.githubusercontent.com/MarlinFirmware/Configurations/$REPO/config/examples"
 | 
			
		||||
#
 | 
			
		||||
# use_example_configs [repo:]configpath
 | 
			
		||||
#
 | 
			
		||||
# Examples:
 | 
			
		||||
#   use_example_configs
 | 
			
		||||
#   use_example_configs Creality/CR-10/CrealityV1
 | 
			
		||||
#   use_example_configs release-2.0.9.4:Creality/CR-10/CrealityV1
 | 
			
		||||
#
 | 
			
		||||
# If a configpath has spaces (or quotes) escape them or enquote the path
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
which curl >/dev/null && TOOL='curl -L -s -S -f -o wgot'
 | 
			
		||||
which wget >/dev/null && TOOL='wget -q -O wgot'
 | 
			
		||||
 | 
			
		||||
CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g')
 | 
			
		||||
[[ $CURR == "bugfix-2.0.x" ]] && BRANCH=bugfix-2.0.x || BRANCH=bugfix-2.1.x
 | 
			
		||||
 | 
			
		||||
REPO=$BRANCH
 | 
			
		||||
 | 
			
		||||
if [[ $# > 0 ]]; then
 | 
			
		||||
  IFS=: read -r PART1 PART2 <<< "$@"
 | 
			
		||||
  [[ -n $PART2 ]] && { UDIR="$PART2" ; REPO="$PART1" ; } \
 | 
			
		||||
                  || { UDIR="$PART1" ; }
 | 
			
		||||
  RDIR="${UDIR// /%20}"
 | 
			
		||||
  echo "Fetching $UDIR configurations from $REPO..."
 | 
			
		||||
  EXAMPLES="examples/$RDIR"
 | 
			
		||||
else
 | 
			
		||||
  EXAMPLES="default"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
CONFIGS="https://raw.githubusercontent.com/MarlinFirmware/Configurations/$REPO/config/${EXAMPLES}"
 | 
			
		||||
 | 
			
		||||
restore_configs
 | 
			
		||||
 | 
			
		||||
cd Marlin
 | 
			
		||||
 | 
			
		||||
$TOOL "$EXAMPLES/$RDIR/Configuration.h"     >/dev/null 2>&1 && mv wgot Configuration.h
 | 
			
		||||
$TOOL "$EXAMPLES/$RDIR/Configuration_adv.h" >/dev/null 2>&1 && mv wgot Configuration_adv.h
 | 
			
		||||
$TOOL "$EXAMPLES/$RDIR/_Bootscreen.h"       >/dev/null 2>&1 && mv wgot _Bootscreen.h
 | 
			
		||||
$TOOL "$EXAMPLES/$RDIR/_Statusscreen.h"     >/dev/null 2>&1 && mv wgot _Statusscreen.h
 | 
			
		||||
$TOOL "$CONFIGS/Configuration.h"     >/dev/null 2>&1 && mv wgot Configuration.h
 | 
			
		||||
$TOOL "$CONFIGS/Configuration_adv.h" >/dev/null 2>&1 && mv wgot Configuration_adv.h
 | 
			
		||||
$TOOL "$CONFIGS/_Bootscreen.h"       >/dev/null 2>&1 && mv wgot _Bootscreen.h
 | 
			
		||||
$TOOL "$CONFIGS/_Statusscreen.h"     >/dev/null 2>&1 && mv wgot _Statusscreen.h
 | 
			
		||||
 | 
			
		||||
rm -f wgot
 | 
			
		||||
cd - >/dev/null
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user