Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» More compatible opt helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 24, 2024
1 parent f2d585a commit 74ffa0c
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 44 deletions.
1 change: 0 additions & 1 deletion buildroot/bin/mftest
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ env shortcuts: tree due esp lin lp8|lpc8 lp9|lpc9 m128 m256|mega stm|f1 f4 f7 s6
TESTPATH=buildroot/tests

STATE_FILE="./.pio/.mftestrc"
SED=$(which gsed sed | head -n1)

shopt -s extglob nocasematch

Expand Down
8 changes: 3 additions & 5 deletions buildroot/bin/mfutil
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
#

# 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=$(which gsed sed | head -n1)
[[ -z "$SED" ]] && { echo "No sed found, please install sed" ; exit 1 ; }
which curl &>/dev/null || { echo "curl not found! Please install it."; exit 1 ; }
which git &>/dev/null || { echo "git not found! Please install it."; exit 1 ; }
which sed &>/dev/null || { echo "sed not found! Please install it."; exit 1 ; }

OPEN=$( which gnome-open xdg-open open | head -n1 )

Expand Down
29 changes: 25 additions & 4 deletions buildroot/bin/opt_disable
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@
# exit on first failure
set -e

SED=$(which gsed sed | head -n1)
# Get SED_CMD, SED_I, and the BSDSED flag
. $(dirname $0)/opt_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 ; }
for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do
if [[ $BSDSED ]]; then
# BSD sed version (macOS)
"${SED_CMD}" "${SED_I[@]}" \
"/^[[:space:]]*#define[[:space:]]+${opt}\b/{
s/^[[:space:]]*\(#define[[:space:]]+${opt}\b.*\)/\/\/\1/
h
\$b end
}
\$!b
:end
x
/./{ x; q0; }
x
q1" \
$FN && DID=1
else
# GNU sed version
"${SED_CMD}" "${SED_I[@]}" \
"/^\(\s*\)\(#define\s\+${opt}\b\s\?\)\(\s\s\)\?/{s//\1\/\/\2/;h};\${x;/./{x;q0};x;q1}" \
$FN && DID=1
fi
((DID||FOUND)) || { grep -E "^\s*\/\/#define\s+${opt}\b" $FN >/dev/null && FOUND=1 ; }
done
((DID||FOUND)) || (echo "ERROR: $(basename $0) Can't find ${opt}" >&2 && exit 9)
done
29 changes: 25 additions & 4 deletions buildroot/bin/opt_enable
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@
# exit on first failure
set -e

SED=$(which gsed sed | head -n1)
# Get SED_CMD, SED_I, and the BSDSED flag
. $(dirname $0)/opt_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 ; }
for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do
if [[ $BSDSED ]]; then
# BSD sed version (macOS)
"${SED_CMD}" "${SED_I[@]}" \
"/^[[:space:]]*\/\/[[:space:]]*#define[[:space:]]+${opt}\b/{
s/^[[:space:]]*\/\/[[:space:]]*\(#define[[:space:]]+${opt}\b\)[[:space:]]*/\1 /
h
\$b end
}
\$!b
:end
x
/./{ x; q0; }
x
q1" \
$FN && DID=1
else
# GNU sed version
"${SED_CMD}" "${SED_I[@]}" \
"/^\(\s*\)\/\/\(\s*\)\(#define\s\+${opt}\b\)\( \?\)/{s//\1\2\3\4\4\4/;h};\${x;/./{x;q0};x;q1}" \
$FN && DID=1
fi
((DID||FOUND)) || { grep -E "^\s*#define\s+${opt}\b" $FN >/dev/null && FOUND=1 ; }
done
((DID||FOUND)) || (echo "ERROR: $(basename $0) Can't find ${opt}" >&2 && exit 9)
done
4 changes: 2 additions & 2 deletions buildroot/bin/opt_find
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ 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 )
for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do
FOUND=$( grep -HEn "^\s*${COMM}#define\s+[A-Z0-9_]*${1}" $FN 2>/dev/null )
[[ -n "$FOUND" ]] && { echo "$FOUND" ; DID=1 ; }
done
((DID)) || { echo "ERROR: ${MYNAME} - No ${TYPE}match for ${1}" ; exit 9; }
Expand Down
9 changes: 9 additions & 0 deletions buildroot/bin/opt_sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Detect sed version
SED_CMD="sed"
SED_I=(-i)
if command -v gsed >/dev/null 2>&1; then
SED_CMD="gsed"
elif [[ "$(uname)" == "Darwin" ]]; then
SED_I=(-i '')
BSDSED=1
fi
27 changes: 24 additions & 3 deletions buildroot/bin/opt_set
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@
# exit on first failure
set -e

SED=$(which gsed sed | head -n1)
# Get SED_CMD, SED_I, and the BSDSED flag
. $(dirname $0)/opt_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
for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do
if [[ $BSDSED ]]; then
# BSD sed version (macOS)
$SED_CMD "${SED_I[@]}" \
"/^[[:space:]]*\/\{0,2\}[[:space:]]*#define[[:space:]]+${1}\b/{
s/^[[:space:]]*\/\{0,2\}[[:space:]]*\(#define[[:space:]]+${1}\b\)[[:space:]]*.*/\1 ${2} \/\/ &/
h
\$b end
}
\$!b
:end
x
/./{ x; q0; }
x
q1" \
$FN && DID=1
else
# GNU sed version
$SED_CMD "${SED_I[@]}" \
"/^\(\s*\)\/\{0,2\}\s*\(#define\s\+${1}\b\)\s*\(.*\)$/{s//\1\2 ${2} \/\/ \3/;h};\${x;/./{x;q0};x;q1}" \
$FN && DID=1
fi
done
((DID)) ||
eval "echo '#define ${1} ${2}' >>Marlin/Configuration.h" ||
Expand Down
16 changes: 0 additions & 16 deletions buildroot/bin/pins_set

This file was deleted.

1 change: 0 additions & 1 deletion buildroot/share/git/mfhelp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Modify Configuration.h / Configuration_adv.h:
Modify pins files:
pins_set ............. Set the value of a pin in a pins file
pinsformat.py ........ Python script to format pins files
THIS
1 change: 0 additions & 1 deletion buildroot/share/git/mfprep
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# so at every release be sure to create a dev- tag and publish it to origin.
#

SED=$(which gsed sed | head -n1)
SELF=`basename "$0"`
DRYRUN=0

Expand Down
5 changes: 2 additions & 3 deletions buildroot/tests/DUE
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), ExtUI, S-Curve, many options
# RADDS with BLTouch, ABL(B), 3 x Z auto-align
#
restore_configs
opt_set MOTHERBOARD BOARD_RADDS Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z3_DRIVER_TYPE A4988
opt_set MOTHERBOARD BOARD_RADDS Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z3_DRIVER_TYPE A4988 \
X_MAX_PIN -1 Y_MAX_PIN -1
opt_enable ENDSTOPPULLUPS BLTOUCH AUTO_BED_LEVELING_BILINEAR \
Z_STEPPER_AUTO_ALIGN Z_STEPPER_ALIGN_STEPPER_XY Z_SAFE_HOMING
pins_set ramps/RAMPS X_MAX_PIN -1
pins_set ramps/RAMPS Y_MAX_PIN -1
exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN, E_DUAL_STEPPER_DRIVERS" "$3"

#
Expand Down
3 changes: 1 addition & 2 deletions buildroot/tests/teensy35
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ exec_test $1 $2 "Teensy 3.5/3.6 COREXZ | BACKLASH" "$3"
# Enable Dual Z with Dual Z endstops
#
restore_configs
opt_set MOTHERBOARD BOARD_TEENSY35_36 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2
opt_set MOTHERBOARD BOARD_TEENSY35_36 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2 X_MAX_PIN -1
opt_enable Z_MULTI_ENDSTOPS
pins_set ramps/RAMPS X_MAX_PIN -1
exec_test $1 $2 "Dual Z with Dual Z endstops" "$3"

# Clean up
Expand Down
3 changes: 1 addition & 2 deletions buildroot/tests/teensy41
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ exec_test $1 $2 "Teensy 4.0/4.1 COREXZ" "$3"
# Enable Dual Z with Dual Z endstops
#
restore_configs
opt_set MOTHERBOARD BOARD_TEENSY41 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2
opt_set MOTHERBOARD BOARD_TEENSY41 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2 X_MAX_PIN -1
opt_enable Z_MULTI_ENDSTOPS
pins_set ramps/RAMPS X_MAX_PIN -1
exec_test $1 $2 "Dual Z with Dual Z endstops" "$3"

# Clean up
Expand Down

0 comments on commit 74ffa0c

Please sign in to comment.