Skip to content

Commit 73b6ba8

Browse files
committed
πŸ§‘β€πŸ’» More compatible Build Scripts
Followup to d36d9cb
1 parent 72b09fe commit 73b6ba8

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

β€Žbuildroot/bin/build_all_examples

+30-27
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
#
2121

2222
HERE=`dirname $0`
23+
PATH="$HERE:$PATH"
2324

24-
. "$HERE/mfutil"
25+
. mfutil
2526

2627
GITREPO=https://github.com/MarlinFirmware/Configurations.git
2728
STAT_FILE=./.pio/.buildall
@@ -55,7 +56,7 @@ LIMIT=1000
5556
while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
5657
case "${OFLAG}" in
5758
a) ARCHIVE=1 ; bugout "Archiving" ;;
58-
B) OPATH=${OPTARG%/} ; bugout "Base: $OPATH" ;;
59+
B) CBASE=${OPTARG%/} ; bugout "Base: $CBASE" ;;
5960
b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
6061
f) NOFAIL=1 ; bugout "Continue on Fail" ;;
6162
r) ISRES=1 ; FIRST_CONF=$OPTARG ; bugout "Resume: $FIRST_CONF" ;;
@@ -71,7 +72,7 @@ while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
7172
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
7273
case "$ONAM" in
7374
archive) ARCHIVE=1 ; bugout "Archiving" ;;
74-
base) OPATH=${OVAL%/} ; bugout "Base: $OPATH" ;;
75+
base) CBASE=${OVAL%/} ; bugout "Base: $CBASE" ;;
7576
branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
7677
nofail) NOFAIL=1 ; bugout "Continue on Fail" ;;
7778
resume) ISRES=1 ; FIRST_CONF=$OVAL ; bugout "Resume: $FIRST_CONF" ;;
@@ -131,45 +132,47 @@ else
131132
git diff --quiet || { echo "The working copy is modified. Commit or stash changes before proceeding."; exit ; }
132133
fi
133134

134-
# Create a temporary folder inside .pio
135-
if [[ -n $OPATH ]]; then
136-
[[ -d "$OPATH" ]] || { echo "Given base -B $OPATH not found." ; exit ; }
135+
# Check for the given base path
136+
if [[ -n $CBASE ]]; then
137+
CBASE="${CBASE/#\~/$HOME}"
138+
[[ -d "$CBASE" ]] || { echo "Given base -B $CBASE not found." ; exit ; }
137139
else
138140
# Make a Configurations temporary folder if needed
139-
OPATH=./.pio/build-$BRANCH
140-
[[ -d "$OPATH" ]] || mkdir -p "$OPATH"
141+
CBASE=./.pio/build-$BRANCH
142+
[[ -d "$CBASE" ]] || mkdir -p "$CBASE"
141143
# Download the specified Configurations branch if needed
142-
if [[ ! -e "$OPATH/README.md" ]]; then
143-
echo "Fetching Configurations from GitHub to $OPATH"
144-
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$OPATH" || { echo "Failed to clone the configuration repository"; exit ; }
144+
if [[ ! -e "$CBASE/README.md" ]]; then
145+
echo "Fetching Configurations from GitHub to $CBASE"
146+
git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$CBASE" || { echo "Failed to clone the configuration repository"; exit ; }
145147
fi
146148
fi
147149

148150
# Build
149151
echo -e "=====================\nProceed with builds...\n====================="
150152
shopt -s nullglob
151-
shopt -s globstar
152-
IFS='
153-
'
154-
CONF_TREE=$( ls -d "$OPATH"/config/examples/**/ | grep -vE ".+\.(\w+)$" )
155-
for CONF in $CONF_TREE ; do
153+
154+
# Get a list of all folders that contain a file matching "Configuration*.h"
155+
find -ds "$CBASE"/config/examples -type d -name 'Configuration.h' -o -name 'Configuration_adv.h' -print0 | while IFS= read -r -d '' CONF; do
156+
157+
# Remove the file name and slash from the end of the path
158+
CONF=${CONF%/*}
156159

157160
# Get a config's directory name
158-
DIR=${CONF#$OPATH/config/examples/}
161+
DIR=${CONF#$CBASE/config/examples/}
159162

160163
# If looking for a config, skip others
161-
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
164+
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && { ((DEBUG)) && echo "[SKIP] $DIR" ; continue ; }
162165
# Once found, stop looking
163166
unset FIRST_CONF
164167

165168
# If skipping, don't build the found one
166169
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
167170

168-
# At least one config file is required here
169-
compgen -G "${CONF}Configuration*.h" > /dev/null || continue
171+
# Either Configuration.h or Configuration_adv.h must exist
172+
[[ -f "$CONF"/Configuration.h || -f "$CONF"/Configuration_adv.h ]] || { echo "[NONE] $DIR" ; continue ; }
170173

171174
# Command arguments for 'build_example'
172-
CARGS=("-b" "$OPATH" "-c" "$DIR")
175+
CARGS=("-b" "$CBASE" "-c" "$DIR")
173176

174177
# Exporting? Add -e argument
175178
((CEXPORT)) && CARGS+=("-e" "$CEXPORT")
@@ -189,16 +192,16 @@ for CONF in $CONF_TREE ; do
189192
else
190193
# Remember where we are in case of failure
191194
echo "${BRANCH}*${DIR}" >"$STAT_FILE"
192-
((DEBUG)) && echo "\"$HERE/build_example\" ${CARGS[@]}"
195+
((DEBUG)) && echo "build_example ${CARGS[@]}"
193196
# Invoke build_example
194-
"$HERE"/build_example "${CARGS[@]}" || { echo "Failed to build $DIR" ; exit ; }
197+
build_example "${CARGS[@]}" || { echo "Failed to build $DIR" ; exit ; }
195198
fi
196199

197-
((--LIMIT)) || { echo "Limit reached" ; PAUSE=1 ; break ; }
198-
199-
echo ; echo
200+
echo
201+
((--LIMIT)) || { echo "Specified limit reached" ; PAUSE=1 ; break ; }
202+
echo
200203

201204
done
202205

203206
# Delete the build state if not paused early
204-
[[ $PAUSE ]] || rm "$STAT_FILE"
207+
[[ $PAUSE ]] || rm -f "$STAT_FILE"

β€Žbuildroot/bin/build_example

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ build_example -b|--base=<path> - Configurations root folder (e.g., ./.pio/bu
3232
}
3333

3434
HERE=`dirname $0`
35+
PATH="$HERE:$PATH"
3536

36-
source "$HERE/mfutil"
37+
. mfutil
3738

3839
annc() { echo -e "\033[0;32m$1\033[0m" ; }
3940

@@ -100,7 +101,7 @@ SUB="$SUB1/$CONFIG"
100101
[[ -d "$SUB" ]] || { echo "-c|--config $CONFIG doesn't exist" ; exit 1 ; }
101102

102103
# ...and contains Configuration.h or Configuration_adv.h
103-
[[ -n $(compgen -G "$SUB/Configuration*.h") ]] || { echo "No configuration files found in $SUB" ; exit 1 ; }
104+
[[ -f "$SUB"/Configuration.h || -f "$SUB"/Configuration_adv.h ]] || { echo "No configuration files found in $SUB" ; exit 1 ; }
104105

105106
# Get the location for exports and archives
106107
if [[ -n $OUTBASE ]]; then
@@ -173,7 +174,7 @@ fi
173174
set +e
174175

175176
echo "Building example $CONFIG ..."
176-
"$HERE/mftest" -s -a -n1 ; ERR=$?
177+
mftest -s -a -n1 ; ERR=$?
177178

178179
((ERR)) && echo "Failed" || echo "Success"
179180

@@ -191,6 +192,7 @@ fi
191192
# Currently only BOARD_CREALITY_F401RE env:STM32F401RE_creality
192193
if ((ARCHIVE)); then
193194
annc "Archiving"
195+
rm -f "$ARCSUB"/*.bin.tar.gz "$ARCSUB"/*.hex.tar.gz
194196
find "$BUILD" \( "${BNAME[@]}" \) -exec sh -c '
195197
ARCSUB="$1"
196198
shift 1

β€Žbuildroot/bin/mftest

-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ if ((AUTO_BUILD)); then
167167
MB=$(awk "$ACODE" Marlin/Configuration.h 2>/dev/null)
168168
[[ -z $MB ]] && MB=$(awk "$ACODE" Marlin/Config.h 2>/dev/null)
169169
[[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
170-
echo "Got $MB"
171-
exit
172170
BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
173171
BNUM=$( sed -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
174172
BDESC=$( sed -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )

0 commit comments

Comments
Β (0)