Browse Source

🧑‍💻 Fix and improve build_all_examples

Scott Lahteine 2 years ago
parent
commit
3b4c759872

+ 103
- 18
buildroot/bin/build_all_examples View File

@@ -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

+ 9
- 0
buildroot/bin/build_example View File

@@ -22,6 +22,15 @@ cp "$SUB"/Configuration_adv.h Marlin/ 2>/dev/null
22 22
 cp "$SUB"/_Bootscreen.h       Marlin/ 2>/dev/null
23 23
 cp "$SUB"/_Statusscreen.h     Marlin/ 2>/dev/null
24 24
 
25
+set -e
26
+
27
+# Strip #error lines from Configuration.h
28
+SED=$(which gsed sed | head -n1)
29
+IFS=$'\n'; set -f
30
+$SED -i~ -e "20,30{/#error/d}" Marlin/Configuration.h
31
+rm Marlin/Configuration.h~
32
+unset IFS; set +f
33
+
25 34
 echo "Building the firmware now..."
26 35
 HERE=`dirname "$0"`
27 36
 $HERE/mftest -s -a -n1 || { echo "Failed"; exit 1; }

+ 1
- 1
buildroot/bin/mftest View File

@@ -3,7 +3,7 @@
3 3
 #  mftest                             Select a test to apply and build
4 4
 #  mftest -b [#]                      Build the auto-detected environment
5 5
 #  mftest -u [#]                      Upload the auto-detected environment
6
-#  mftest [name] [index] [-y]         Set config options and optionally build a test
6
+#  mftest -tname -n# [-y]             Set config options and optionally build a test
7 7
 #
8 8
 
9 9
 [[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }

+ 1
- 1
buildroot/share/git/firstpush View File

@@ -16,7 +16,7 @@ BRANCH=${INFO[5]}
16 16
 
17 17
 git push --set-upstream origin HEAD:$BRANCH
18 18
 
19
-OPEN=$(echo $(which gnome-open xdg-open open) | awk '{ print $1 }')
19
+OPEN=$( which gnome-open xdg-open open | head -n1 )
20 20
 URL="https://github.com/$FORK/$REPO/commits/$BRANCH"
21 21
 
22 22
 if [ -z "$OPEN" ]; then

+ 1
- 1
buildroot/share/git/mfdoc View File

@@ -17,7 +17,7 @@ BRANCH=${INFO[5]}
17 17
 
18 18
 opensite() {
19 19
   URL="http://127.0.0.1:4000/"
20
-  OPEN=$(echo $(which gnome-open xdg-open open) | awk '{ print $1 }')
20
+  OPEN=$( which gnome-open xdg-open open | head -n1 )
21 21
   if [ -z "$OPEN" ]; then
22 22
     echo "Can't find a tool to open the URL:"
23 23
     echo $URL

+ 1
- 1
buildroot/share/git/mfpr View File

@@ -23,7 +23,7 @@ OLDBRANCH=${INFO[5]}
23 23
 # See if it's been pushed yet
24 24
 if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
25 25
 
26
-OPEN=$(echo $(which gnome-open xdg-open open) | awk '{ print $1 }')
26
+OPEN=$( which gnome-open xdg-open open | head -n1 )
27 27
 URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
28 28
 
29 29
 if [ -z "$OPEN" ]; then

+ 1
- 1
buildroot/share/git/mfpub View File

@@ -45,7 +45,7 @@ git clean -d -f
45 45
 
46 46
 opensite() {
47 47
   URL="$1"
48
-  OPEN=$(echo $(which gnome-open xdg-open open) | awk '{ print $1 }')
48
+  OPEN=$( which gnome-open xdg-open open | head -n1 )
49 49
   if [ -z "$OPEN" ]; then
50 50
     echo "Can't find a tool to open the URL:"
51 51
     echo $URL

Loading…
Cancel
Save