Browse Source

Add mftest -b (auto-build) and -u (upload)

- Implement the equivalent of auto-build for the shell environment by using the MOTHERBOARD setting to look up the env: entries.
Scott Lahteine 4 years ago
parent
commit
10b4fa91eb
1 changed files with 81 additions and 22 deletions
  1. 81
    22
      buildroot/share/git/mftest

+ 81
- 22
buildroot/share/git/mftest View File

@@ -1,10 +1,9 @@
1 1
 #!/usr/bin/env bash
2 2
 #
3
-# mftest [name] [index]
4
-#
5
-# Set configuration options based on a test
6
-# By default it will do megaatmega2560
7
-# Use 'mftest -' to pick from the list.
3
+#  mftest                             Select a test to apply and build
4
+#  mftest -b                          Build 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
8 7
 #
9 8
 
10 9
 MFINFO=$(mfinfo) || exit 1
@@ -12,16 +11,24 @@ MFINFO=$(mfinfo) || exit 1
12 11
 
13 12
 TESTPATH=buildroot/share/tests
14 13
 STATE_FILE=$( echo ./.pio/.mftestrc )
14
+SED=$(which gsed || which sed)
15 15
 
16 16
 shopt -s extglob nocasematch
17 17
 
18
+# Matching patterns
19
+ISNUM='^[0-9]+$'
20
+ISCMD='^(restore|opt|exec|use|pins|env)_'
21
+ISEXEC='^exec_'
22
+ISCONT='\\ *$'
23
+
18 24
 # Get the environment and test number from the command
19 25
 TESTENV=${1:-'-'}
20 26
 CHOICE=${2:-0}
27
+AUTOENV=0
21 28
 
22 29
 # Allow shorthand for test name
23 30
 case $TESTENV in
24
-    tree) platformio run --project-dir . -e include_tree ; exit 1 ;;
31
+    tree) pio run -d . -e include_tree ; exit 1 ;;
25 32
      due) TESTENV='DUE' ;;
26 33
      esp) TESTENV='esp32' ;;
27 34
     lin*) TESTENV='linux_native' ;;
@@ -43,22 +50,72 @@ case $TESTENV in
43 50
           # Build with the last-built env
44 51
       -r) [[ -f "$STATE_FILE" ]] || { echo "No previous (-r) build state found." ; exit 1 ; }
45 52
           read TESTENV <"$STATE_FILE"
46
-          platformio run --project-dir . -e $TESTENV
53
+          pio run -d . -e $TESTENV
54
+          exit
55
+          ;;
56
+
57
+   -[bu]) MB=$( grep "define MOTHERBOARD" Marlin/Configuration.h | awk '{ print $3 }' | $SED 's/BOARD_//' )
58
+          [[ -z $MB ]] && { echo "Error - Unable to read MOTHERBOARD setting." ; exit 1 ; }
59
+          BLINE=$( grep "define BOARD_$MB" Marlin/src/core/boards.h )
60
+          BNUM=$( $SED -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
61
+          BDESC=$( $SED -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
62
+          [[ -z $BNUM ]] && { echo "Error - Unable to $MB in boards list." ; exit 1 ; }
63
+          readarray -t ENVS <<< $( grep -A1 "MB($MB)" Marlin/src/pins/pins.h | $SED -n '2 p' | grep -oE 'env:[^ ]+' | $SED -E 's/env://' )
64
+          [[ -z $ENVS ]] && { echo "Error - Unable to find target(s) for $MB ($BNUM)." ; exit 1 ; }
65
+          ECOUNT=${#ENVS[*]}
66
+
67
+          if [[ $ECOUNT == 1 ]]; then
68
+            TARGET=$ENVS
69
+          else
70
+            #
71
+            # List env names and numbers. Get selection.
72
+            #
73
+            if [[ $CHOICE == 0 ]]; then
74
+              echo "Available targets for \"$BDESC\" | $MB ($BNUM):"
75
+
76
+              IND=0 ; for ENV in "${ENVS[@]}"; do echo " $IND) $ENV" ; done
77
+
78
+              if [[ $ECOUNT > 1 ]]; then
79
+                for (( ; ; ))
80
+                do
81
+                  read -p "Select a target for '$MB' (1-$ECOUNT) : " CHOICE
82
+                  [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
83
+                  [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= ECOUNT)) && break
84
+                  echo ">>> Invalid environment choice '$CHOICE'."
85
+                done
86
+                echo
87
+              fi
88
+            else
89
+              echo "Detected \"$BDESC\" | $MB ($BNUM)."
90
+              [[ $CHOICE > $ECOUNT ]] && { echo "Environment selection is out of range." ; exit 1 ; }
91
+            fi
92
+            TARGET="${ENVS[$CHOICE-1]}"
93
+            echo "Selected $TARGET"
94
+          fi
95
+
96
+          echo "$TARGET" >"$STATE_FILE"
97
+
98
+          if [[ $TESTENV == "-u" ]]; then
99
+            echo "Build/Uploading environment $TARGET for board $MB ($BNUM)..." ; echo
100
+            pio run -t upload -e $TARGET
101
+          else
102
+            echo "Building environment $TARGET for board $MB ($BNUM)..." ; echo
103
+            pio run -e $TARGET
104
+          fi
47 105
           exit
48 106
           ;;
49
-          # A -y may come first
107
+
108
+          # The -y flag may come first
50 109
       -y) TESTENV=${2:-'-'} ; CHOICE=${3:-0} ;;
110
+
51 111
   -[a-z]) echo "Unknown flag $TESTENV" ; exit 1 ;;
52 112
        -) ;;
53 113
 esac
54 114
 
55
-# Matching patterns
56
-ISNUM='^[0-9]+$'
57
-ISCMD='^(restore|opt|exec|use|pins|env)_'
58
-ISEXEC='^exec_'
59
-ISCONT='\\ *$'
60
-
115
+#
61 116
 # List available tests and ask for selection
117
+#
118
+
62 119
 if [[ $TESTENV == '-' ]]; then
63 120
   IND=0
64 121
   NAMES=()
@@ -86,17 +143,17 @@ fi
86 143
 OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
87 144
 
88 145
 # Count up the number of tests
89
-# TODO: List test descriptions with numbers
90 146
 TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
91 147
 
92 148
 # User entered a number?
93
-(( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
149
+(( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test selection '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
94 150
 
95 151
 if [[ $CHOICE == 0 ]]; then
96
-  # List test descriptions with numbers
152
+  #
153
+  # List test descriptions with numbers and get selection
154
+  #
97 155
   echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
98 156
     IND=0
99
-    SED=$(which gsed || which sed)
100 157
     while IFS= read -r LINE
101 158
     do
102 159
       if [[ $LINE =~ $ISEXEC ]]; then
@@ -113,12 +170,14 @@ if [[ $CHOICE == 0 ]]; then
113 170
       read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
114 171
       [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
115 172
       [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
116
-      echo ">>> Invalid test index '$CHOICE'."
173
+      echo ">>> Invalid test selection '$CHOICE'."
117 174
     done
118 175
   fi
119 176
 fi
120 177
 
121
-# Finally, run the specified test lines
178
+#
179
+# Run the specified test lines
180
+#
122 181
 echo "$OUT" | {
123 182
   IND=0
124 183
   GOTX=0
@@ -136,7 +195,7 @@ echo "$OUT" | {
136 195
         }
137 196
         ((IND == CHOICE)) && {
138 197
           GOTX=1
139
-          [[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' )
198
+          [[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | $SED -e 's/\\//g' )
140 199
           [[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
141 200
         }
142 201
       fi
@@ -154,6 +213,6 @@ if [[ $BUILD_YES != 'Y' ]]; then
154 213
 fi
155 214
 
156 215
 [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
157
-  platformio run --project-dir . -e $TESTENV
216
+  pio run -d . -e $TESTENV
158 217
   echo "$TESTENV" >"$STATE_FILE"
159 218
 }

Loading…
Cancel
Save