@@ -11,7 +11,6 @@ import (
1111 "io"
1212 "os"
1313 "os/signal"
14- "path/filepath"
1514 "regexp"
1615 "strconv"
1716 "strings"
@@ -20,7 +19,6 @@ import (
2019 "github.com/mattn/go-tty"
2120 "github.com/tinygo-org/tinygo/builder"
2221 "github.com/tinygo-org/tinygo/compileopts"
23- "github.com/tinygo-org/tinygo/goenv"
2422
2523 "go.bug.st/serial"
2624 "go.bug.st/serial/enumerator"
@@ -145,9 +143,9 @@ type SerialPortInfo struct {
145143}
146144
147145// ListSerialPort returns serial port information and any detected TinyGo
148- // target
146+ // target.
149147func ListSerialPorts () ([]SerialPortInfo , error ) {
150- maps , err := GetTargetSpecs ()
148+ maps , err := compileopts . GetTargetSpecs ()
151149 if err != nil {
152150 return nil , err
153151 }
@@ -186,41 +184,6 @@ func ListSerialPorts() ([]SerialPortInfo, error) {
186184 return serialPortInfo , nil
187185}
188186
189- func GetTargetSpecs () (map [string ]* compileopts.TargetSpec , error ) {
190- dir := filepath .Join (goenv .Get ("TINYGOROOT" ), "targets" )
191- entries , err := os .ReadDir (dir )
192- if err != nil {
193- return nil , fmt .Errorf ("could not list targets: %w" , err )
194- }
195-
196- maps := map [string ]* compileopts.TargetSpec {}
197- for _ , entry := range entries {
198- entryInfo , err := entry .Info ()
199- if err != nil {
200- return nil , fmt .Errorf ("could not get entry info: %w" , err )
201- }
202- if ! entryInfo .Mode ().IsRegular () || ! strings .HasSuffix (entry .Name (), ".json" ) {
203- // Only inspect JSON files.
204- continue
205- }
206- path := filepath .Join (dir , entry .Name ())
207- spec , err := compileopts .LoadTarget (& compileopts.Options {Target : path })
208- if err != nil {
209- return nil , fmt .Errorf ("cnuld not list target: %w" , err )
210- }
211- if spec .FlashMethod == "" && spec .FlashCommand == "" && spec .Emulator == "" {
212- // This doesn't look like a regular target file, but rather like
213- // a parent target (such as targets/cortex-m.json).
214- continue
215- }
216- name := entry .Name ()
217- name = name [:len (name )- 5 ]
218- //fmt.Println(name)
219- maps [name ] = spec
220- }
221- return maps , nil
222- }
223-
224187var addressMatch = regexp .MustCompile (`^panic: runtime error at 0x([0-9a-f]+): ` )
225188
226189// Extract the address from the "panic: runtime error at" message.
0 commit comments