Sfoglia il codice sorgente

🧑‍💻 Fix and improve build_all_examples

Scott Lahteine 2 anni fa
parent
commit
3b4c759872

+ 103
- 18
buildroot/bin/build_all_examples Vedi File

1
 #!/usr/bin/env bash
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
 GITREPO=https://github.com/MarlinFirmware/Configurations.git
19
 GITREPO=https://github.com/MarlinFirmware/Configurations.git
7
 STAT_FILE=./.pio/.buildall
20
 STAT_FILE=./.pio/.buildall
8
 
21
 
19
 # Check if called in the right location
32
 # Check if called in the right location
20
 [[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; }
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
 echo "On failure the last-built configs will be left in your working copy."
91
 echo "On failure the last-built configs will be left in your working copy."
31
 echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
92
 echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
32
 
93
 
33
-unset BRANCH
34
-unset FIRST_CONF
35
 if [[ -f "$STAT_FILE" ]]; then
94
 if [[ -f "$STAT_FILE" ]]; then
36
   IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
95
   IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
37
 fi
96
 fi
38
 
97
 
39
 # If -c is given start from the last attempted build
98
 # If -c is given start from the last attempted build
40
-if [[ $1 == '-c' ]]; then
99
+if ((CONTINUE)); then
41
   if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
100
   if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
42
     echo "Nothing to continue"
101
     echo "Nothing to continue"
43
     exit
102
     exit
44
   fi
103
   fi
45
-elif [[ $1 == '-s' ]]; then
104
+elif ((CONTSKIP)); then
46
   if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
105
   if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
47
     SKIP_CONF=1
106
     SKIP_CONF=1
48
   else
107
   else
49
     echo "Nothing to skip"
108
     echo "Nothing to skip"
50
     exit
109
     exit
51
   fi
110
   fi
52
-else
53
-  BRANCH=${1:-"import-2.0.x"}
54
-  FIRST_CONF=$2
55
 fi
111
 fi
56
 
112
 
57
 # Check if the current repository has unmerged changes
113
 # Check if the current repository has unmerged changes
82
 CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" )
138
 CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" )
83
 DOSKIP=0
139
 DOSKIP=0
84
 for CONF in $CONF_TREE ; do
140
 for CONF in $CONF_TREE ; do
141
+
85
   # Get a config's directory name
142
   # Get a config's directory name
86
   DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" )
143
   DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" )
144
+
87
   # If looking for a config, skip others
145
   # If looking for a config, skip others
88
   [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
146
   [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
89
   # Once found, stop looking
147
   # Once found, stop looking
90
   unset FIRST_CONF
148
   unset FIRST_CONF
149
+
91
   # If skipping, don't build the found one
150
   # If skipping, don't build the found one
92
   [[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
151
   [[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
152
+
93
   # ...if skipping, don't build this one
153
   # ...if skipping, don't build this one
94
   compgen -G "${CONF}Con*.h" > /dev/null || continue
154
   compgen -G "${CONF}Con*.h" > /dev/null || continue
155
+
156
+  # Remember where we are in case of failure
95
   echo "${BRANCH}*${DIR}" >"$STAT_FILE"
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
 done
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
 rm "$STAT_FILE"
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 Vedi File

22
 cp "$SUB"/_Bootscreen.h       Marlin/ 2>/dev/null
22
 cp "$SUB"/_Bootscreen.h       Marlin/ 2>/dev/null
23
 cp "$SUB"/_Statusscreen.h     Marlin/ 2>/dev/null
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
 echo "Building the firmware now..."
34
 echo "Building the firmware now..."
26
 HERE=`dirname "$0"`
35
 HERE=`dirname "$0"`
27
 $HERE/mftest -s -a -n1 || { echo "Failed"; exit 1; }
36
 $HERE/mftest -s -a -n1 || { echo "Failed"; exit 1; }

+ 1
- 1
buildroot/bin/mftest Vedi File

3
 #  mftest                             Select a test to apply and build
3
 #  mftest                             Select a test to apply and build
4
 #  mftest -b [#]                      Build the auto-detected environment
4
 #  mftest -b [#]                      Build the auto-detected environment
5
 #  mftest -u [#]                      Upload the auto-detected environment
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
 [[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }
9
 [[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }

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

16
 
16
 
17
 git push --set-upstream origin HEAD:$BRANCH
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
 URL="https://github.com/$FORK/$REPO/commits/$BRANCH"
20
 URL="https://github.com/$FORK/$REPO/commits/$BRANCH"
21
 
21
 
22
 if [ -z "$OPEN" ]; then
22
 if [ -z "$OPEN" ]; then

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

17
 
17
 
18
 opensite() {
18
 opensite() {
19
   URL="http://127.0.0.1:4000/"
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
   if [ -z "$OPEN" ]; then
21
   if [ -z "$OPEN" ]; then
22
     echo "Can't find a tool to open the URL:"
22
     echo "Can't find a tool to open the URL:"
23
     echo $URL
23
     echo $URL

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

23
 # See if it's been pushed yet
23
 # See if it's been pushed yet
24
 if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
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
 URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
27
 URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
28
 
28
 
29
 if [ -z "$OPEN" ]; then
29
 if [ -z "$OPEN" ]; then

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

45
 
45
 
46
 opensite() {
46
 opensite() {
47
   URL="$1"
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
   if [ -z "$OPEN" ]; then
49
   if [ -z "$OPEN" ]; then
50
     echo "Can't find a tool to open the URL:"
50
     echo "Can't find a tool to open the URL:"
51
     echo $URL
51
     echo $URL

Loading…
Annulla
Salva