2
2
#
3
3
# Usage:
4
4
#
5
- # build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo
5
+ # build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo (import-2.1.x)
6
+ # [-B|--base] - Base path of configurations, overriding -b
6
7
# [-c|--continue] - Continue the paused build
7
- # [-d|--debug] - Print extra debug output
8
- # [-i|--ini] - Archive ini/json/yml files in the temp config folder
9
- # [-l|--limit=#] - Limit the number of builds in this run
10
- # [-n|--nobuild] - Don't actually build anything.
8
+ # [-p|--purge] - Purge the status file and start over
9
+ # [-s|--skip] - Continue the paused build, skipping one
11
10
# [-r|--resume=<path>] - Start at some config in the filesystem order
12
- # [-s|--skip] - Do the thing
13
- #
14
- # build_all_examples [...] branch [resume-from]
11
+ # [-l|--limit=#] - Limit the number of builds in this run
12
+ # [-d|--debug] - Print extra debug output (after)
13
+ # [-n|--nobuild] - Don't actually build anything
14
+ # [-f|--nofail] - Don't stop on a failed build
15
+ # [-e|--export=N] - Set CONFIG_EXPORT and export into each config folder
16
+ # [-a|--archive] - Copy the binary to the export location
17
+ # [-o|--output] - Redirect export / archiving to another location
18
+ # (By default export to origin config folders)
19
+ # [-h|--help] - Print usage and exit
15
20
#
16
21
17
22
HERE=` dirname $0 `
23
+ PATH=" $HERE :$PATH "
18
24
19
- . " $HERE / mfutil"
25
+ . mfutil
20
26
21
27
GITREPO=https://github.com/MarlinFirmware/Configurations.git
22
28
STAT_FILE=./.pio/.buildall
23
29
24
- usage () { echo "
25
- Usage: $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-r|--resume=<path>]
26
- $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-c|--continue]
27
- $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-s|--skip]
28
- $SELF [-b|--branch=<branch>] [-d|--debug] [-n|--nobuild]
29
- $SELF [...] branch [resume-point]
30
+ usage () { echo " Usage:
31
+
32
+ build_all_examples [-b|--branch=<branch>] - Branch to fetch from Configurations repo (import-2.1.x)
33
+ [-B|--base] - Base path of configurations, overriding -b
34
+ [-c|--continue] - Continue the paused build
35
+ [-p|--purge] - Purge the status file and start over
36
+ [-s|--skip] - Continue the paused build, skipping one
37
+ [-r|--resume=<path>] - Start at some config in the filesystem order
38
+ [-e|--export=N] - Set CONFIG_EXPORT and export to the export location
39
+ [-a|--archive] - Copy the binary to the export location
40
+ [-o|--output] - Redirect export / archiving to another location
41
+ (By default export to origin config folders)
42
+ [-d|--debug] - Print extra debug output (after)
43
+ [-l|--limit=#] - Limit the number of builds in this run
44
+ [-n|--nobuild] - Don't actually build anything
45
+ [-f|--nofail] - Don't stop on a failed build
46
+ [-h|--help] - Print usage and exit
30
47
"
31
48
}
32
49
@@ -36,50 +53,60 @@ unset FIRST_CONF
36
53
EXIT_USAGE=
37
54
LIMIT=1000
38
55
39
- while getopts ' b:cdhil:nqr :sv-:' OFLAG; do
56
+ while getopts ' aB:b:ce:fdhl:no:pr :sv-:' OFLAG; do
40
57
case " ${OFLAG} " in
41
- b) BRANCH=$OPTARG ; bugout " Branch: $BRANCH " ;;
42
- r) FIRST_CONF=" $OPTARG " ; bugout " Resume: $FIRST_CONF " ;;
43
- c) CONTINUE=1 ; bugout " Continue" ;;
44
- s) CONTSKIP=1 ; bugout " Continue, skipping" ;;
45
- i) COPY_INI=1 ; bugout " Archive INI/JSON/YML files" ;;
58
+ a) ARCHIVE=1 ; bugout " Archiving" ;;
59
+ B) CBASE=${OPTARG%/ } ; bugout " Base: $CBASE " ;;
60
+ b) BRANCH=$OPTARG ; bugout " Branch: $BRANCH " ;;
61
+ f) NOFAIL=1 ; bugout " Continue on Fail" ;;
62
+ r) ISRES=1 ; FIRST_CONF=$OPTARG ; bugout " Resume: $FIRST_CONF " ;;
63
+ c) CONTINUE=1 ; bugout " Continue" ;;
64
+ s) CONTSKIP=1 ; bugout " Continue, skipping" ;;
65
+ e) CEXPORT=$OPTARG ; bugout " Export $CEXPORT " ;;
66
+ o) OUTBASE=" ${OPTARG%/ } " ; bugout " Archive to $OUTBASE " ;;
46
67
h) EXIT_USAGE=1 ; break ;;
47
- l) LIMIT=$OPTARG ; bugout " Limit to $LIMIT build(s)" ;;
48
- d|v) DEBUG=1 ; bugout " Debug ON" ;;
49
- n) DRYRUN=1 ; bugout " Dry Run" ;;
50
- -) IFS=" =" read -r ONAM OVAL <<< " $OPTARG"
68
+ l) LIMIT=$OPTARG ; bugout " Limit to $LIMIT build(s)" ;;
69
+ d|v) DEBUG=1 ; bugout " Debug ON" ;;
70
+ n) DRYRUN=1 ; bugout " Dry Run" ;;
71
+ p) PURGE=1 ; bugout " Purge stat file" ;;
72
+ -) ONAM=" ${OPTARG%% =* } " ; OVAL=" ${OPTARG#* =} "
51
73
case " $ONAM " in
52
- branch) BRANCH=$OVAL ; bugout " Branch: $BRANCH " ;;
53
- resume) FIRST_CONF=" $OVAL " ; bugout " Resume: $FIRST_CONF " ;;
54
- continue) CONTINUE=1 ; bugout " Continue" ;;
55
- skip) CONTSKIP=2 ; bugout " Continue, skipping" ;;
56
- limit) LIMIT=$OVAL ; bugout " Limit to $LIMIT build(s)" ;;
57
- ini) COPY_INI=1 ; bugout " Archive INI/JSON/YML files" ;;
74
+ archive) ARCHIVE=1 ; bugout " Archiving" ;;
75
+ base) CBASE=${OVAL%/ } ; bugout " Base: $CBASE " ;;
76
+ branch) BRANCH=$OVAL ; bugout " Branch: $BRANCH " ;;
77
+ nofail) NOFAIL=1 ; bugout " Continue on Fail" ;;
78
+ resume) ISRES=1 ; FIRST_CONF=$OVAL ; bugout " Resume: $FIRST_CONF " ;;
79
+ continue) CONTINUE=1 ; bugout " Continue" ;;
80
+ skip) CONTSKIP=1 ; bugout " Continue, skipping" ;;
81
+ export) CEXPORT=$OVAL ; bugout " Export $EXPORT " ;;
82
+ output) OUTBASE=" ${OVAL%/ } " ; bugout " Archive to $OUTBASE " ;;
83
+ limit) LIMIT=$OVAL ; bugout " Limit to $LIMIT build(s)" ;;
58
84
help) [[ -z " $OVAL " ]] || perror " option can't take value $OVAL " $ONAM ; EXIT_USAGE=1 ;;
59
- debug) DEBUG=1 ; bugout " Debug ON" ;;
60
- nobuild) DRYRUN=1 ; bugout " Dry Run" ;;
85
+ debug) DEBUG=1 ; bugout " Debug ON" ;;
86
+ nobuild) DRYRUN=1 ; bugout " Dry Run" ;;
87
+ purge) PURGE=1 ; bugout " Purge stat file" ;;
61
88
* ) EXIT_USAGE=2 ; echo " $SELF : unrecognized option \` --$ONAM '" ; break ;;
62
89
esac
63
90
;;
64
91
* ) EXIT_USAGE=2 ; break ;;
65
92
esac
66
93
done
67
-
68
- # Extra arguments count as BRANCH, FIRST_CONF
69
94
shift $(( OPTIND - 1 ))
70
- [[ $# > 0 ]] && { BRANCH=$1 ; shift 1 ; bugout " BRANCH=$BRANCH " ; }
71
- [[ $# > 0 ]] && { FIRST_CONF=$1 ; shift 1 ; bugout " FIRST_CONF=$FIRST_CONF " ; }
72
- [[ $# > 0 ]] && { EXIT_USAGE=2 ; echo " too many arguments" ; }
73
95
96
+ # Check for mixed continue, skip, resume arguments. Only one should be used.
97
+ (( CONTINUE + CONTSKIP + ISRES + PURGE > 1 )) && { echo " Don't mix -c, -p, -s, and -r options" ; echo ; EXIT_USAGE=2 ; }
98
+
99
+ # Exit with helpful usage information
74
100
(( EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
75
101
76
- echo " This script downloads each Configuration and attempts to build it."
77
- echo " On failure the last-built configs will be left in your working copy."
102
+ echo
103
+ echo " This script downloads all example configs and attempts to build them."
104
+ echo " On failure the last-built configs are left in your working copy."
78
105
echo " Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
106
+ echo
79
107
80
- if [[ -f " $STAT_FILE " ]]; then
81
- IFS=' *' read BRANCH FIRST_CONF < " $STAT_FILE "
82
- fi
108
+ [[ -n $PURGE ]] && rm -f " $STAT_FILE "
109
+ [[ -z $FIRST_CONF && -f " $STAT_FILE " ]] && IFS=' *' read BRANCH FIRST_CONF < " $STAT_FILE "
83
110
84
111
# If -c is given start from the last attempted build
85
112
if (( CONTINUE)) ; then
@@ -97,77 +124,90 @@ elif ((CONTSKIP)); then
97
124
fi
98
125
99
126
# Check if the current repository has unmerged changes
100
- if [[ $ SKIP_CONF ]] ; then
127
+ if (( SKIP_CONF)) ; then
101
128
echo " Skipping $FIRST_CONF "
102
- elif [[ $FIRST_CONF ]]; then
129
+ elif [[ -n $FIRST_CONF ]]; then
103
130
echo " Resuming from $FIRST_CONF "
104
131
else
105
132
git diff --quiet || { echo " The working copy is modified. Commit or stash changes before proceeding." ; exit ; }
106
133
fi
107
134
108
- # Create a temporary folder inside .pio
109
- TMP=./.pio/build-$BRANCH
110
- [[ -d " $TMP " ]] || mkdir -p $TMP
111
-
112
- # Download Configurations into the temporary folder
113
- if [[ ! -e " $TMP /README.md" ]]; then
114
- echo " Fetching Configurations from GitHub to $TMP "
115
- git clone --depth=1 --single-branch --branch " $BRANCH " $GITREPO " $TMP " || { echo " Failed to clone the configuration repository" ; 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 ; }
116
139
else
117
- echo " Using cached Configurations at $TMP "
140
+ # Make a Configurations temporary folder if needed
141
+ CBASE=./.pio/build-$BRANCH
142
+ [[ -d " $CBASE " ]] || mkdir -p " $CBASE "
143
+ # Download the specified Configurations branch if needed
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 ; }
147
+ fi
118
148
fi
119
149
120
- echo -e " Start build...\n====================="
150
+ # Build
151
+ echo -e " =====================\nProceed with builds...\n====================="
121
152
shopt -s nullglob
122
- IFS='
123
- '
124
- CONF_TREE=$( ls -d " $TMP " /config/examples/* / " $TMP " /config/examples/* /* / " $TMP " /config/examples/* /* /* / " $TMP " /config/examples/* /* /* /* / | grep -vE " .+\.(\w+)$" )
125
- for CONF in $CONF_TREE ; do
153
+
154
+ export PAUSE=1
155
+
156
+ # Get a list of all folders that contain a file matching "Configuration*.h"
157
+ find -ds " $CBASE " /config/examples -type d -name ' Configuration.h' -o -name ' Configuration_adv.h' -print0 | while IFS= read -r -d $' \0' CONF; do
158
+
159
+ # Remove the file name and slash from the end of the path
160
+ CONF=${CONF%/* }
126
161
127
162
# Get a config's directory name
128
- DIR=$( echo $ CONF | " $SED " " s| $TMP /config/examples/|| " )
163
+ DIR=${ CONF# $CBASE / config/ examples/ }
129
164
130
165
# If looking for a config, skip others
131
- [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && " $FIRST_CONF /" != $DIR ]] && continue
166
+ [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && " $FIRST_CONF /" != $DIR ]] && { (( DEBUG )) && echo " [SKIP] $DIR " ; continue ; }
132
167
# Once found, stop looking
133
168
unset FIRST_CONF
134
169
135
170
# If skipping, don't build the found one
136
171
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
137
172
138
- # ...if skipping, don't build this one
139
- compgen -G " ${CONF} Con*.h" > /dev/null || continue
173
+ # Either Configuration.h or Configuration_adv.h must exist
174
+ [[ -f " $CONF " /Configuration.h || -f " $CONF " /Configuration_adv.h ]] || { echo " [NONE] $DIR " ; continue ; }
175
+
176
+ # Command arguments for 'build_example'
177
+ CARGS=(" -b" " $CBASE " " -c" " $DIR " )
178
+
179
+ # Exporting? Add -e argument
180
+ (( CEXPORT)) && CARGS+=(" -e" " $CEXPORT " )
181
+
182
+ # Continue on fail? Add -f argument
183
+ (( NOFAIL)) && CARGS+=(" -f" )
184
+
185
+ # Archive the build? Add -a argument
186
+ (( ARCHIVE)) && CARGS+=(" -a" )
187
+
188
+ # Redirecting the export/archive output? Add -o argument
189
+ [[ -n $OUTBASE ]] && CARGS+=(" -o" " $OUTBASE " )
140
190
141
191
# Build or print build command for --nobuild
142
- if [[ $ DRYRUN ]] ; then
143
- echo -e " \033[0;32m[DRYRUN] build_example internal \" $TMP \" \" $DIR \" \033[0m"
192
+ if (( DRYRUN)) ; then
193
+ echo -e " \033[0;32m[DRYRUN] build_example ${CARGS[@]} \033[0m"
144
194
else
145
195
# Remember where we are in case of failure
146
196
echo " ${BRANCH} *${DIR} " > " $STAT_FILE "
147
- # Build folder is unknown so delete all report files
148
- if [[ $COPY_INI ]]; then
149
- IFIND=' find ./.pio/build/ -name "config.ini" -o -name "schema.json" -o -name "schema.yml"'
150
- $IFIND -exec rm " {}" \;
151
- fi
152
- (( DEBUG)) && echo " \" $HERE /build_example\" internal \" $TMP \" \" $DIR \" "
153
- " $HERE /build_example" internal " $TMP " " $DIR " || { echo " Failed to build $DIR " ; exit ; }
154
- # Build folder is unknown so copy all report files
155
- [[ $COPY_INI ]] && $IFIND -exec cp " {}" " $CONF " \;
197
+ (( DEBUG)) && echo " build_example ${CARGS[@]} "
198
+ # Invoke build_example
199
+ build_example " ${CARGS[@]} " || { echo " Failed to build $DIR " ; exit ; }
156
200
fi
157
201
158
- (( -- LIMIT)) || { echo " Limit reached" ; PAUSE=1 ; break ; }
202
+ echo
203
+ (( -- LIMIT)) || { echo " Specified limit reached" ; break ; }
204
+ echo
205
+
206
+ export PAUSE=0
159
207
160
208
done
161
209
210
+ echo " Exiting"
211
+
162
212
# Delete the build state if not paused early
163
- [[ $PAUSE ]] || rm " $STAT_FILE "
164
-
165
- # Delete the temp folder if not preserving generated INI files
166
- if [[ -e " $TMP /config/examples" ]]; then
167
- if [[ $COPY_INI ]]; then
168
- OPEN=$( which gnome-open xdg-open open | head -n1 )
169
- $OPEN " $TMP "
170
- elif [[ ! $PAUSE ]]; then
171
- rm -rf " $TMP "
172
- fi
173
- fi
213
+ (( PAUSE)) || rm -f " $STAT_FILE "
0 commit comments