1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-26 13:25:54 +00:00

🔧 Use string manglers in scripts

This commit is contained in:
Scott Lahteine 2024-09-05 12:00:20 -05:00
parent 9e6981ea60
commit d36d9cb506
5 changed files with 29 additions and 25 deletions

View File

@ -68,7 +68,7 @@ while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
d|v) DEBUG=1 ; bugout "Debug ON" ;;
n) DRYRUN=1 ; bugout "Dry Run" ;;
p) PURGE=1 ; bugout "Purge stat file" ;;
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
case "$ONAM" in
archive) ARCHIVE=1 ; bugout "Archiving" ;;
base) OPATH=${OVAL%/} ; bugout "Base: $OPATH" ;;
@ -90,6 +90,7 @@ while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
*) EXIT_USAGE=2 ; break ;;
esac
done
shift $((OPTIND - 1))
# Check for mixed continue, skip, resume arguments. Only one should be used.
((CONTINUE + CONTSKIP + ISRES + PURGE > 1)) && { echo "Don't mix -c, -p, -s, and -r options" ; echo ; EXIT_USAGE=2 ; }
@ -154,7 +155,7 @@ CONF_TREE=$( ls -d "$OPATH"/config/examples/**/ | grep -vE ".+\.(\w+)$" )
for CONF in $CONF_TREE ; do
# Get a config's directory name
DIR=$( echo "$CONF" | "$SED" "s|$OPATH/config/examples/||" )
DIR=${CONF#$OPATH/config/examples/}
# If looking for a config, skip others
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue

View File

@ -58,7 +58,7 @@ while getopts 'ab:c:e:fhio:r-:' OFLAG; do
h) EXIT_USAGE=1 ; break ;;
f) NOFAIL=1 ;;
r) REVEAL=1 ;;
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
case "$ONAM" in
archive) ARCHIVE=1 ;;
allow) ALLOW=1 ;;
@ -75,6 +75,7 @@ while getopts 'ab:c:e:fhio:r-:' OFLAG; do
*) EXIT_USAGE=2 ; break ;;
esac
done
shift $((OPTIND - 1))
# Must be called from another script (or with --allow)
[[ $ALLOW || $SHLVL -gt 2 ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; }
@ -121,11 +122,9 @@ rm -f Marlin/Config.h Marlin/Config-export.h
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
# Strip #error lines from Configuration.h using
awk 'NR < 20 || NR > 30 || !/#error/' Marlin/Configuration.h > Marlin/Configuration.h~
mv Marlin/Configuration.h~ Marlin/Configuration.h
# Hide several warnings when not exporting
[[ -z $EXPNUM ]] && CLEANER=1

View File

@ -3,12 +3,10 @@
# 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
awk '/default_src_filter/ { sub("default_src_filter", "org_src_filter"); print "default_src_filter = +<src/*>"; } 1' $FN > $FN~ && mv $FN~ $FN
else
git checkout $FN 2>/dev/null
fi

View File

@ -74,7 +74,7 @@ while getopts 'abdhmrsuvyn:t:-:' OFLAG; do
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"
-) ONAM="${OPTARG%%=*}" ; 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..." ;;
@ -107,6 +107,7 @@ debug|verbose) DEBUG=1 ; bugout "Debug ON" ;;
*) EXIT_USAGE=2 ;;
esac
done
shift $((OPTIND - 1))
((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
@ -158,16 +159,21 @@ if ((AUTO_BUILD)); then
*) SYS='uni' ;;
esac
echo ; echo -n "Auto " ; ((AUTO_BUILD == 2)) && echo "Upload..." || echo "Build..."
MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Configuration.h 2>/dev/null | awk '{ print $3 }' | $SED 's/BOARD_//;s/\r//' )
[[ -z $MB ]] && {
MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Config.h 2>/dev/null | awk '{ print $3 }' | $SED 's/BOARD_//;s/\r//' )
[[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
}
#
# Get the MOTHERBOARD define value from the .h file and strip off the "BOARD_" prefix
#
ACODE='/[[:space:]]*#define[[:space:]]MOTHERBOARD[[:space:]]/ { sub(/^BOARD_/, "", $3); print $3 }'
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" )
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)://" ) )
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[*]}
@ -276,7 +282,7 @@ if [[ $CHOICE == 0 ]]; then
while IFS= read -r LINE
do
if [[ $LINE =~ $ISEXEC ]]; then
DESC=$( "$SED" -E 's/^exec_test \$1 \$2 "([^"]+)".*$/\1/g' <<<"$LINE" )
DESC=$( sed -E 's/^exec_test \$1 \$2 "([^"]+)".*$/\1/g' <<<"$LINE" )
(( ++IND < 10 )) && echo -n " "
echo " $IND) $DESC"
fi
@ -321,7 +327,7 @@ echo "$OUT" | {
((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' )
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' | sed -E 's/ +/ /g' )
[[ $LINE =~ $ISCONT ]] || { echo "$CMD" ; eval "$CMD" ; CMD="" ; }
}
fi

View File

@ -36,10 +36,10 @@ TMPF="$TMPDIR/tmp.txt"
SCRF="$TMPDIR/update-$DEST.sh"
git checkout bugfix-2.1.x
git log --pretty="[%h] %s" dev-$TAG1..$TAG2 | grep -v '\[cron\]' | $SED '1!G;h;$!d' >"$LOGB"
git log --pretty="[%h] %s" dev-$TAG1..$TAG2 | grep -v '\[cron\]' | sed '1!G;h;$!d' >"$LOGB"
git checkout $DEST
git log --pretty="[%h] %s" $TAG1..$TAG2 | $SED '1!G;h;$!d' >"$LOG2" || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
git log --pretty="[%h] %s" $TAG1..$TAG2 | sed '1!G;h;$!d' >"$LOG2" || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
# Go through commit text from DEST removing all matches from the bugfix log
@ -57,7 +57,7 @@ cat "$LOG2" | while read line; do
#echo "... $PATT"
[[ -n "$PATT" ]] && { grep -vE "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
else
PATT=$( $SED -E 's/^\[[0-9a-f]{10}\]( . )?(.+)$/\2/' <<<"$line" )
PATT=$( sed -E 's/^\[[0-9a-f]{10}\]( . )?(.+)$/\2/' <<<"$line" )
[[ -n "$PATT" ]] && { grep -v "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
fi
done