main: implement tinygo targets to list usable targets
This patch adds the `tinygo targets` command, which lists usable targets (targets that can be used in the `-target` flag). The assumption here is that usable targets can either be flashed or emulated by TinyGo. There is one exception where it doesn't work yet: the nintendoswitch target. Right now it requires some manual steps to build a .nro file which can then be run by yuzu, hence why it doesn't show up in the list.
Этот коммит содержится в:
родитель
b99175a436
коммит
e7227df80d
1 изменённых файлов: 30 добавлений и 0 удалений
30
main.go
30
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"go/scanner"
|
"go/scanner"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -921,6 +922,35 @@ func main() {
|
||||||
}
|
}
|
||||||
err := Test(pkgName, options)
|
err := Test(pkgName, options)
|
||||||
handleCompilerError(err)
|
handleCompilerError(err)
|
||||||
|
case "targets":
|
||||||
|
dir := filepath.Join(goenv.Get("TINYGOROOT"), "targets")
|
||||||
|
entries, err := ioutil.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "could not list targets:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
if !entry.Mode().IsRegular() || !strings.HasSuffix(entry.Name(), ".json") {
|
||||||
|
// Only inspect JSON files.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
path := filepath.Join(dir, entry.Name())
|
||||||
|
spec, err := compileopts.LoadTarget(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "could not list target:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if spec.FlashMethod == "" && spec.FlashCommand == "" && spec.Emulator == nil {
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
case "info":
|
case "info":
|
||||||
if flag.NArg() == 1 {
|
if flag.NArg() == 1 {
|
||||||
options.Target = flag.Arg(0)
|
options.Target = flag.Arg(0)
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче