Bladeren bron

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 jaren geleden
bovenliggende
commit
10b4fa91eb
1 gewijzigde bestanden met toevoegingen van 81 en 22 verwijderingen
  1. 81
    22
      buildroot/share/git/mftest

+ 81
- 22
buildroot/share/git/mftest Bestand weergeven

1
 #!/usr/bin/env bash
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
 MFINFO=$(mfinfo) || exit 1
9
 MFINFO=$(mfinfo) || exit 1
12
 
11
 
13
 TESTPATH=buildroot/share/tests
12
 TESTPATH=buildroot/share/tests
14
 STATE_FILE=$( echo ./.pio/.mftestrc )
13
 STATE_FILE=$( echo ./.pio/.mftestrc )
14
+SED=$(which gsed || which sed)
15
 
15
 
16
 shopt -s extglob nocasematch
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
 # Get the environment and test number from the command
24
 # Get the environment and test number from the command
19
 TESTENV=${1:-'-'}
25
 TESTENV=${1:-'-'}
20
 CHOICE=${2:-0}
26
 CHOICE=${2:-0}
27
+AUTOENV=0
21
 
28
 
22
 # Allow shorthand for test name
29
 # Allow shorthand for test name
23
 case $TESTENV in
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
      due) TESTENV='DUE' ;;
32
      due) TESTENV='DUE' ;;
26
      esp) TESTENV='esp32' ;;
33
      esp) TESTENV='esp32' ;;
27
     lin*) TESTENV='linux_native' ;;
34
     lin*) TESTENV='linux_native' ;;
43
           # Build with the last-built env
50
           # Build with the last-built env
44
       -r) [[ -f "$STATE_FILE" ]] || { echo "No previous (-r) build state found." ; exit 1 ; }
51
       -r) [[ -f "$STATE_FILE" ]] || { echo "No previous (-r) build state found." ; exit 1 ; }
45
           read TESTENV <"$STATE_FILE"
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
           exit
105
           exit
48
           ;;
106
           ;;
49
-          # A -y may come first
107
+
108
+          # The -y flag may come first
50
       -y) TESTENV=${2:-'-'} ; CHOICE=${3:-0} ;;
109
       -y) TESTENV=${2:-'-'} ; CHOICE=${3:-0} ;;
110
+
51
   -[a-z]) echo "Unknown flag $TESTENV" ; exit 1 ;;
111
   -[a-z]) echo "Unknown flag $TESTENV" ; exit 1 ;;
52
        -) ;;
112
        -) ;;
53
 esac
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
 # List available tests and ask for selection
116
 # List available tests and ask for selection
117
+#
118
+
62
 if [[ $TESTENV == '-' ]]; then
119
 if [[ $TESTENV == '-' ]]; then
63
   IND=0
120
   IND=0
64
   NAMES=()
121
   NAMES=()
86
 OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
143
 OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
87
 
144
 
88
 # Count up the number of tests
145
 # Count up the number of tests
89
-# TODO: List test descriptions with numbers
90
 TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
146
 TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
91
 
147
 
92
 # User entered a number?
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
 if [[ $CHOICE == 0 ]]; then
151
 if [[ $CHOICE == 0 ]]; then
96
-  # List test descriptions with numbers
152
+  #
153
+  # List test descriptions with numbers and get selection
154
+  #
97
   echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
155
   echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
98
     IND=0
156
     IND=0
99
-    SED=$(which gsed || which sed)
100
     while IFS= read -r LINE
157
     while IFS= read -r LINE
101
     do
158
     do
102
       if [[ $LINE =~ $ISEXEC ]]; then
159
       if [[ $LINE =~ $ISEXEC ]]; then
113
       read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
170
       read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
114
       [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
171
       [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
115
       [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
172
       [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
116
-      echo ">>> Invalid test index '$CHOICE'."
173
+      echo ">>> Invalid test selection '$CHOICE'."
117
     done
174
     done
118
   fi
175
   fi
119
 fi
176
 fi
120
 
177
 
121
-# Finally, run the specified test lines
178
+#
179
+# Run the specified test lines
180
+#
122
 echo "$OUT" | {
181
 echo "$OUT" | {
123
   IND=0
182
   IND=0
124
   GOTX=0
183
   GOTX=0
136
         }
195
         }
137
         ((IND == CHOICE)) && {
196
         ((IND == CHOICE)) && {
138
           GOTX=1
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
           [[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
199
           [[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
141
         }
200
         }
142
       fi
201
       fi
154
 fi
213
 fi
155
 
214
 
156
 [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
215
 [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
157
-  platformio run --project-dir . -e $TESTENV
216
+  pio run -d . -e $TESTENV
158
   echo "$TESTENV" >"$STATE_FILE"
217
   echo "$TESTENV" >"$STATE_FILE"
159
 }
218
 }

Laden…
Annuleren
Opslaan