|
@@ -1,8 +1,21 @@
|
1
|
1
|
#!/usr/bin/env bash
|
2
|
2
|
#
|
3
|
|
-# build_all_examples base_branch [resume_point]
|
|
3
|
+# Usage:
|
|
4
|
+#
|
|
5
|
+# build_all_examples [-b|--branch=<branch>]
|
|
6
|
+# [-c|--continue]
|
|
7
|
+# [-d|--debug]
|
|
8
|
+# [-i|--ini]
|
|
9
|
+# [-l|--limit=#]
|
|
10
|
+# [-n|--nobuild]
|
|
11
|
+# [-r|--resume=<path>]
|
|
12
|
+# [-s|--skip]
|
|
13
|
+#
|
|
14
|
+# build_all_examples [...] branch [resume-from]
|
4
|
15
|
#
|
5
|
16
|
|
|
17
|
+set -e
|
|
18
|
+
|
6
|
19
|
GITREPO=https://github.com/MarlinFirmware/Configurations.git
|
7
|
20
|
STAT_FILE=./.pio/.buildall
|
8
|
21
|
|
|
@@ -19,39 +32,82 @@ HERE=`dirname "$0"`
|
19
|
32
|
# Check if called in the right location
|
20
|
33
|
[[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; }
|
21
|
34
|
|
22
|
|
-if [[ $# -lt 1 || $# -gt 2 ]]; then
|
23
|
|
- echo "Usage: $SELF base_branch [resume_point]
|
24
|
|
- base_branch - Configuration branch to download and build
|
25
|
|
- resume_point - Configuration path to start from"
|
26
|
|
- exit
|
27
|
|
-fi
|
|
35
|
+perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; }
|
|
36
|
+bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }
|
|
37
|
+
|
|
38
|
+usage() { echo "
|
|
39
|
+Usage: $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-r|--resume=<path>]
|
|
40
|
+ $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-c|--continue]
|
|
41
|
+ $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-s|--skip]
|
|
42
|
+ $SELF [-b|--branch=<branch>] [-d|--debug] [-n|--nobuild]
|
|
43
|
+ $SELF [...] branch [resume-point]
|
|
44
|
+"
|
|
45
|
+}
|
|
46
|
+
|
|
47
|
+# Assume the most recent configs
|
|
48
|
+BRANCH=import-2.1.x
|
|
49
|
+unset FIRST_CONF
|
|
50
|
+EXIT_USAGE=
|
|
51
|
+LIMIT=1000
|
28
|
52
|
|
29
|
|
-echo "This script downloads all Configurations and builds Marlin with each one."
|
|
53
|
+while getopts 'b:cdhil:nqr:sv-:' OFLAG; do
|
|
54
|
+ case "${OFLAG}" in
|
|
55
|
+ b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
|
|
56
|
+ r) FIRST_CONF="$OPTARG" ; bugout "Resume: $FIRST_CONF" ;;
|
|
57
|
+ c) CONTINUE=1 ; bugout "Continue" ;;
|
|
58
|
+ s) CONTSKIP=1 ; bugout "Continue, skipping" ;;
|
|
59
|
+ i) CREATE_INI=1 ; bugout "Generate an INI file" ;;
|
|
60
|
+ h) EXIT_USAGE=1 ; break ;;
|
|
61
|
+ l) LIMIT=$OPTARG ; bugout "Limit to $LIMIT configs" ;;
|
|
62
|
+ d|v) DEBUG=1 ; bugout "Debug ON" ;;
|
|
63
|
+ n) DRYRUN=1 ; bugout "Dry Run" ;;
|
|
64
|
+ -) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
|
|
65
|
+ case "$ONAM" in
|
|
66
|
+ branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
|
|
67
|
+ resume) FIRST_CONF="$OVAL" ; bugout "Resume: $FIRST_CONF" ;;
|
|
68
|
+ continue) CONTINUE=1 ; bugout "Continue" ;;
|
|
69
|
+ skip) CONTSKIP=2 ; bugout "Continue, skipping" ;;
|
|
70
|
+ limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT configs" ;;
|
|
71
|
+ ini) CREATE_INI=1 ; bugout "Generate an INI file" ;;
|
|
72
|
+ help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
|
|
73
|
+ debug) DEBUG=1 ; bugout "Debug ON" ;;
|
|
74
|
+ nobuild) DRYRUN=1 ; bugout "Dry Run" ;;
|
|
75
|
+ *) EXIT_USAGE=2 ; echo "$SELF: unrecognized option \`--$ONAM'" ; break ;;
|
|
76
|
+ esac
|
|
77
|
+ ;;
|
|
78
|
+ *) EXIT_USAGE=2 ; break ;;
|
|
79
|
+ esac
|
|
80
|
+done
|
|
81
|
+
|
|
82
|
+# Extra arguments count as BRANCH, FIRST_CONF
|
|
83
|
+shift $((OPTIND - 1))
|
|
84
|
+[[ $# > 0 ]] && { BRANCH=$1 ; shift 1 ; bugout "BRANCH=$BRANCH" ; }
|
|
85
|
+[[ $# > 0 ]] && { FIRST_CONF=$1 ; shift 1 ; bugout "FIRST_CONF=$FIRST_CONF" ; }
|
|
86
|
+[[ $# > 0 ]] && { EXIT_USAGE=2 ; echo "too many arguments" ; }
|
|
87
|
+
|
|
88
|
+((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
|
|
89
|
+
|
|
90
|
+echo "This script downloads each Configuration and attempts to build it."
|
30
|
91
|
echo "On failure the last-built configs will be left in your working copy."
|
31
|
92
|
echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
|
32
|
93
|
|
33
|
|
-unset BRANCH
|
34
|
|
-unset FIRST_CONF
|
35
|
94
|
if [[ -f "$STAT_FILE" ]]; then
|
36
|
95
|
IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
|
37
|
96
|
fi
|
38
|
97
|
|
39
|
98
|
# If -c is given start from the last attempted build
|
40
|
|
-if [[ $1 == '-c' ]]; then
|
|
99
|
+if ((CONTINUE)); then
|
41
|
100
|
if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
|
42
|
101
|
echo "Nothing to continue"
|
43
|
102
|
exit
|
44
|
103
|
fi
|
45
|
|
-elif [[ $1 == '-s' ]]; then
|
|
104
|
+elif ((CONTSKIP)); then
|
46
|
105
|
if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
|
47
|
106
|
SKIP_CONF=1
|
48
|
107
|
else
|
49
|
108
|
echo "Nothing to skip"
|
50
|
109
|
exit
|
51
|
110
|
fi
|
52
|
|
-else
|
53
|
|
- BRANCH=${1:-"import-2.0.x"}
|
54
|
|
- FIRST_CONF=$2
|
55
|
111
|
fi
|
56
|
112
|
|
57
|
113
|
# Check if the current repository has unmerged changes
|
|
@@ -82,20 +138,49 @@ IFS='
|
82
|
138
|
CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" )
|
83
|
139
|
DOSKIP=0
|
84
|
140
|
for CONF in $CONF_TREE ; do
|
|
141
|
+
|
85
|
142
|
# Get a config's directory name
|
86
|
143
|
DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" )
|
|
144
|
+
|
87
|
145
|
# If looking for a config, skip others
|
88
|
146
|
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
|
89
|
147
|
# Once found, stop looking
|
90
|
148
|
unset FIRST_CONF
|
|
149
|
+
|
91
|
150
|
# If skipping, don't build the found one
|
92
|
151
|
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
|
|
152
|
+
|
93
|
153
|
# ...if skipping, don't build this one
|
94
|
154
|
compgen -G "${CONF}Con*.h" > /dev/null || continue
|
|
155
|
+
|
|
156
|
+ # Remember where we are in case of failure
|
95
|
157
|
echo "${BRANCH}*${DIR}" >"$STAT_FILE"
|
96
|
|
- "$HERE/build_example" "internal" "$TMP" "$DIR" || { echo "Failed to build $DIR"; exit ; }
|
|
158
|
+
|
|
159
|
+ # Build or pretend to build
|
|
160
|
+ if [[ $DRYRUN ]]; then
|
|
161
|
+ echo "[DRYRUN] build_example internal \"$TMP\" \"$DIR\""
|
|
162
|
+ else
|
|
163
|
+ # Build folder is unknown so delete all "config.ini" files
|
|
164
|
+ [[ $CREATE_INI ]] && find ./.pio/build/ -name "config.ini" -exec rm "{}" \;
|
|
165
|
+ ((DEBUG)) && echo "\"$HERE/build_example\" \"internal\" \"$TMP\" \"$DIR\""
|
|
166
|
+ "$HERE/build_example" "internal" "$TMP" "$DIR" || { echo "Failed to build $DIR"; exit ; }
|
|
167
|
+ # Build folder is unknown so copy any "config.ini"
|
|
168
|
+ [[ $CREATE_INI ]] && find ./.pio/build/ -name "config.ini" -exec cp "{}" "$CONF" \;
|
|
169
|
+ fi
|
|
170
|
+
|
|
171
|
+ ((LIMIT--)) || { echo "Limit reached" ; break ; }
|
|
172
|
+
|
97
|
173
|
done
|
98
|
174
|
|
99
|
|
-# Delete the temp folder and build state
|
100
|
|
-[[ -e "$TMP/config/examples" ]] && rm -rf "$TMP"
|
|
175
|
+# Delete the build state
|
101
|
176
|
rm "$STAT_FILE"
|
|
177
|
+
|
|
178
|
+# Delete the temp folder if not preserving generated INI files
|
|
179
|
+if [[ -e "$TMP/config/examples" ]]; then
|
|
180
|
+ if [[ $CREATE_INI ]]; then
|
|
181
|
+ OPEN=$( which gnome-open xdg-open open | head -n1 )
|
|
182
|
+ $OPEN "$TMP"
|
|
183
|
+ else
|
|
184
|
+ rm -rf "$TMP"
|
|
185
|
+ fi
|
|
186
|
+fi
|