main, compileopts: move GetTargetSpecs() to compileopts package
Этот коммит содержится в:
родитель
24ae6fdf29
коммит
a531ed614a
3 изменённых файлов: 40 добавлений и 40 удалений
|
@ -246,6 +246,43 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
|
||||||
return spec, nil
|
return spec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTargetSpecs retrieves target specifications from the TINYGOROOT targets
|
||||||
|
// directory. Only valid target JSON files are considered, and the function
|
||||||
|
// returns a map of target names to their respective TargetSpec.
|
||||||
|
func GetTargetSpecs() (map[string]*TargetSpec, error) {
|
||||||
|
dir := filepath.Join(goenv.Get("TINYGOROOT"), "targets")
|
||||||
|
entries, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not list targets: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
maps := map[string]*TargetSpec{}
|
||||||
|
for _, entry := range entries {
|
||||||
|
entryInfo, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not get entry info: %w", err)
|
||||||
|
}
|
||||||
|
if !entryInfo.Mode().IsRegular() || !strings.HasSuffix(entry.Name(), ".json") {
|
||||||
|
// Only inspect JSON files.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
path := filepath.Join(dir, entry.Name())
|
||||||
|
spec, err := LoadTarget(&Options{Target: path})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not list target: %w", err)
|
||||||
|
}
|
||||||
|
if spec.FlashMethod == "" && spec.FlashCommand == "" && spec.Emulator == "" {
|
||||||
|
// This doesn't look like a regular target file, but rather like
|
||||||
|
// a parent target (such as targets/cortex-m.json).
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name := entry.Name()
|
||||||
|
name = name[:len(name)-5]
|
||||||
|
maps[name] = spec
|
||||||
|
}
|
||||||
|
return maps, nil
|
||||||
|
}
|
||||||
|
|
||||||
func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
||||||
// No target spec available. Use the default one, useful on most systems
|
// No target spec available. Use the default one, useful on most systems
|
||||||
// with a regular OS.
|
// with a regular OS.
|
||||||
|
|
2
main.go
2
main.go
|
@ -1743,7 +1743,7 @@ func main() {
|
||||||
handleCompilerError(err)
|
handleCompilerError(err)
|
||||||
}
|
}
|
||||||
case "targets":
|
case "targets":
|
||||||
specs, err := GetTargetSpecs()
|
specs, err := compileopts.GetTargetSpecs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "could not list targets:", err)
|
fmt.Fprintln(os.Stderr, "could not list targets:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
41
monitor.go
41
monitor.go
|
@ -11,7 +11,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -20,7 +19,6 @@ import (
|
||||||
"github.com/mattn/go-tty"
|
"github.com/mattn/go-tty"
|
||||||
"github.com/tinygo-org/tinygo/builder"
|
"github.com/tinygo-org/tinygo/builder"
|
||||||
"github.com/tinygo-org/tinygo/compileopts"
|
"github.com/tinygo-org/tinygo/compileopts"
|
||||||
"github.com/tinygo-org/tinygo/goenv"
|
|
||||||
|
|
||||||
"go.bug.st/serial"
|
"go.bug.st/serial"
|
||||||
"go.bug.st/serial/enumerator"
|
"go.bug.st/serial/enumerator"
|
||||||
|
@ -145,9 +143,9 @@ type SerialPortInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListSerialPort returns serial port information and any detected TinyGo
|
// ListSerialPort returns serial port information and any detected TinyGo
|
||||||
// target
|
// target.
|
||||||
func ListSerialPorts() ([]SerialPortInfo, error) {
|
func ListSerialPorts() ([]SerialPortInfo, error) {
|
||||||
maps, err := GetTargetSpecs()
|
maps, err := compileopts.GetTargetSpecs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -186,41 +184,6 @@ func ListSerialPorts() ([]SerialPortInfo, error) {
|
||||||
return serialPortInfo, nil
|
return serialPortInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTargetSpecs() (map[string]*compileopts.TargetSpec, error) {
|
|
||||||
dir := filepath.Join(goenv.Get("TINYGOROOT"), "targets")
|
|
||||||
entries, err := os.ReadDir(dir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not list targets: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
maps := map[string]*compileopts.TargetSpec{}
|
|
||||||
for _, entry := range entries {
|
|
||||||
entryInfo, err := entry.Info()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not get entry info: %w", err)
|
|
||||||
}
|
|
||||||
if !entryInfo.Mode().IsRegular() || !strings.HasSuffix(entry.Name(), ".json") {
|
|
||||||
// Only inspect JSON files.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
path := filepath.Join(dir, entry.Name())
|
|
||||||
spec, err := compileopts.LoadTarget(&compileopts.Options{Target: path})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cnuld not list target: %w", err)
|
|
||||||
}
|
|
||||||
if spec.FlashMethod == "" && spec.FlashCommand == "" && spec.Emulator == "" {
|
|
||||||
// This doesn't look like a regular target file, but rather like
|
|
||||||
// a parent target (such as targets/cortex-m.json).
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name := entry.Name()
|
|
||||||
name = name[:len(name)-5]
|
|
||||||
//fmt.Println(name)
|
|
||||||
maps[name] = spec
|
|
||||||
}
|
|
||||||
return maps, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var addressMatch = regexp.MustCompile(`^panic: runtime error at 0x([0-9a-f]+): `)
|
var addressMatch = regexp.MustCompile(`^panic: runtime error at 0x([0-9a-f]+): `)
|
||||||
|
|
||||||
// Extract the address from the "panic: runtime error at" message.
|
// Extract the address from the "panic: runtime error at" message.
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче