first commit

This commit is contained in:
ZennDev1337 2024-01-08 09:23:06 +01:00
commit 8c39952965
1956 changed files with 1460685 additions and 0 deletions

1
buildroot/bin/.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
* text=auto eol=lf

View file

@ -0,0 +1,101 @@
#!/usr/bin/env bash
#
# build_all_examples base_branch [resume_point]
#
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 ; }
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Usage: $SELF base_branch [resume_point]
base_branch - Configuration branch to download and build
resume_point - Configuration path to start from"
exit
fi
echo "This script downloads all Configurations and builds Marlin with each one."
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'."
unset BRANCH
unset FIRST_CONF
if [[ -f "$STAT_FILE" ]]; then
IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
fi
# If -c is given start from the last attempted build
if [[ $1 == '-c' ]]; then
if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
echo "Nothing to continue"
exit
fi
elif [[ $1 == '-s' ]]; then
if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
SKIP_CONF=1
else
echo "Nothing to skip"
exit
fi
else
BRANCH=${1:-"import-2.0.x"}
FIRST_CONF=$2
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 "Downloading Configurations from GitHub into $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"
fi
echo -e "Start building now...\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
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
echo "${BRANCH}*${DIR}" >"$STAT_FILE"
"$HERE/build_example" "internal" "$TMP" "$DIR" || { echo "Failed to build $DIR"; exit ; }
done
# Delete the temp folder and build state
[[ -e "$TMP/config/examples" ]] && rm -rf "$TMP"
rm "$STAT_FILE"

View file

@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# build_example
#
# Usage: build_example internal config-home config-folder
#
# 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
echo "Building the firmware now..."
HERE=`dirname "$0"`
$HERE/mftest -a -n1 || { echo "Failed"; exit 1; }
echo "Success"

30
buildroot/bin/format_code Normal file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
#
# format_code [dir/file...]
#
HERE=`dirname $0`
while [[ $# -gt 0 ]]; do
val="$1"
if [ -d "$val" ]; then
find $val -name *.cpp -exec "$HERE/uncrust" '{}' \;
elif [ -d "./Marlin/src/$val" ]; then
find "./Marlin/src/$val" -name *.cpp -exec "$HERE/uncrust" '{}' \;
elif [ -f "./Marlin/src/$val" ]; then
uncrust "./Marlin/src/$val"
elif [ -f "$val" ]; then
uncrust "$val"
fi
done

View file

@ -0,0 +1,132 @@
#!/usr/bin/env bash
#
# generate_version
#
# Make a Version.h file to accompany CUSTOM_VERSION_FILE
#
# Authors: jbrazio, thinkyhead, InsanityAutomation, rfinnie
#
set -e
DIR="${1:-Marlin}"
READ_FILE="${READ_FILE:-${DIR}/Version.h}"
WRITE_FILE="${WRITE_FILE:-${READ_FILE}}"
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)"
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="${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 > "${WRITE_FILE}" <<EOF
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once
/**
* THIS FILE IS AUTOMATICALLY GENERATED DO NOT MANUALLY EDIT IT.
* IT DOES NOT GET COMMITTED TO THE REPOSITORY.
*
* Branch: ${BRANCH}
* Version: ${VERSION}
*/
/**
* Marlin release version identifier
*/
#ifndef SHORT_BUILD_VERSION
#define SHORT_BUILD_VERSION "${SHORT_BUILD_VERSION}"
#endif
/**
* Verbose version identifier which should contain a reference to the location
* from where the binary was downloaded or the source code was compiled.
*/
#ifndef DETAILED_BUILD_VERSION
#define DETAILED_BUILD_VERSION "${DETAILED_BUILD_VERSION}"
#endif
/**
* The STRING_DISTRIBUTION_DATE represents when the binary file was built,
* here we define this default string as the date where the latest release
* version was tagged.
*/
#ifndef STRING_DISTRIBUTION_DATE
#define STRING_DISTRIBUTION_DATE "${STRING_DISTRIBUTION_DATE}"
#endif
/**
* The protocol for communication to the host. Protocol indicates communication
* standards such as the use of ASCII, "echo:" and "error:" line prefixes, etc.
* (Other behaviors are given by the firmware version and capabilities report.)
*/
#ifndef PROTOCOL_VERSION
#define PROTOCOL_VERSION "${PROTOCOL_VERSION}"
#endif
/**
* Defines a generic printer name to be output to the LCD after booting Marlin.
*/
#ifndef MACHINE_NAME
#define MACHINE_NAME "${MACHINE_NAME}"
#endif
/**
* The SOURCE_CODE_URL is the location where users will find the Marlin Source
* Code which is installed on the device. In most cases —unless the manufacturer
* has a distinct Github fork— the Source Code URL should just be the main
* Marlin repository.
*/
#ifndef SOURCE_CODE_URL
#define SOURCE_CODE_URL "${SOURCE_CODE_URL}"
#endif
/**
* Default generic printer UUID.
*/
#ifndef DEFAULT_MACHINE_UUID
#define DEFAULT_MACHINE_UUID "${DEFAULT_MACHINE_UUID}"
#endif
/**
* The WEBSITE_URL is the location where users can get more information such as
* documentation about a specific Marlin release.
*/
#ifndef WEBSITE_URL
#define WEBSITE_URL "${WEBSITE_URL}"
#endif
EOF

313
buildroot/bin/mftest Normal file
View file

@ -0,0 +1,313 @@
#!/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 [name] [index] [-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 [-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.
env shortcuts: tree due esp lin lpc|lpc8 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 || which sed)
shopt -s extglob nocasematch
# Matching patterns
ISNUM='^[0-9]+$'
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 'abhmruvyn:t:-:' OFLAG; do
case "${OFLAG}" in
a) AUTO_BUILD=1 ; bugout "Auto-Build target..." ;;
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..." ;;
make) USE_MAKE=1 ; bugout "Using make with Docker..." ;;
debug|verbose) DEBUG=1 ; bugout "Debug ON" ;;
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]|[1-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_//' )
[[ -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 $MB in boards list." ; 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 0
fi
#
# List available tests and ask for selection
#
if [[ $TESTENV == '-' ]]; then
IND=0
NAMES=()
for FILE in $( ls -1 $TESTPATH/* )
do
let IND++
TNAME=${FILE/$TESTPATH\//}
NAMES+=($TNAME)
(( IND < 10 )) && echo -n " "
echo " $IND) $TNAME"
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
#
# 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
[[ $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"
}

3
buildroot/bin/opt_add Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
eval "echo '#define ${@}' | cat - Marlin/Configuration.h > temp && mv temp Marlin/Configuration.h"

15
buildroot/bin/opt_disable Normal file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# exit on first failure
set -e
SED=$(which gsed || which sed)
for opt in "$@" ; do
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

15
buildroot/bin/opt_enable Normal file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# exit on first failure
set -e
SED=$(which gsed || which sed)
for opt in "$@" ; do
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

17
buildroot/bin/opt_set Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# exit on first failure
set -e
SED=$(which gsed || which sed)
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

11
buildroot/bin/pins_set Normal file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
IFS='/' read -r -a PINPATH <<< "$1"
DIR=${PINPATH[0]}
NAM=${PINPATH[1]}
PIN=$2
VAL=$3
SED=$(which gsed || which sed)
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)

View file

@ -0,0 +1,5 @@
#!/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

77
buildroot/bin/run_tests Normal file
View 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"

17
buildroot/bin/uncrust Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Run uncrustify for a file in-place
#
TMPDIR=`mktemp -d`
# Reformat a single file to tmp/
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
[[ -f "$TMPDIR/uncrustify.out" ]] && rm "$TMPDIR/uncrustify.out"
rmdir "$TMPDIR"

View file

@ -0,0 +1,21 @@
#!/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"
which curl >/dev/null && TOOL='curl -L -s -S -f -o wgot'
which wget >/dev/null && TOOL='wget -q -O wgot'
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
rm -f wgot
cd - >/dev/null