ci: changed to generate only files that exist in targets

This commit is contained in:
sago35
2021-04-08 14:50:49 +09:00
parent 1e9a41dc94
commit fa79f561ac
2 changed files with 72 additions and 9 deletions
+7 -7
View File
@@ -120,22 +120,22 @@ gen-device-avr:
@GO111MODULE=off $(GO) fmt ./src/device/avr
build/gen-device-svd: ./tools/gen-device-svd/*.go
$(GO) build -o $@ ./tools/gen-device-svd/
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o $@ ./tools/gen-device-svd/
gen-device-esp: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Espressif-Community -interrupts=software lib/cmsis-svd/data/Espressif-Community/ src/device/esp/
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Espressif-Community -only-used -interrupts=software lib/cmsis-svd/data/Espressif-Community/ src/device/esp/
GO111MODULE=off $(GO) fmt ./src/device/esp
gen-device-nrf: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk lib/nrfx/mdk/ src/device/nrf/
./build/gen-device-svd -source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk -only-used lib/nrfx/mdk/ src/device/nrf/
GO111MODULE=off $(GO) fmt ./src/device/nrf
gen-device-nxp: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/NXP lib/cmsis-svd/data/NXP/ src/device/nxp/
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/NXP -only-used lib/cmsis-svd/data/NXP/ src/device/nxp/
GO111MODULE=off $(GO) fmt ./src/device/nxp
gen-device-sam: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel lib/cmsis-svd/data/Atmel/ src/device/sam/
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel -only-used lib/cmsis-svd/data/Atmel/ src/device/sam/
GO111MODULE=off $(GO) fmt ./src/device/sam
gen-device-sifive: build/gen-device-svd
@@ -143,11 +143,11 @@ gen-device-sifive: build/gen-device-svd
GO111MODULE=off $(GO) fmt ./src/device/sifive
gen-device-kendryte: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Kendryte-Community -interrupts=software lib/cmsis-svd/data/Kendryte-Community/ src/device/kendryte/
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Kendryte-Community -only-used -interrupts=software lib/cmsis-svd/data/Kendryte-Community/ src/device/kendryte/
GO111MODULE=off $(GO) fmt ./src/device/kendryte
gen-device-stm32: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/tinygo-org/stm32-svd lib/stm32-svd/svd src/device/stm32/
./build/gen-device-svd -source=https://github.com/tinygo-org/stm32-svd -only-used lib/stm32-svd/svd src/device/stm32/
GO111MODULE=off $(GO) fmt ./src/device/stm32
+65 -2
View File
@@ -5,6 +5,8 @@ import (
"encoding/xml"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
@@ -13,6 +15,10 @@ import (
"strings"
"text/template"
"unicode"
"github.com/tinygo-org/tinygo/builder"
"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/goenv"
)
var validName = regexp.MustCompile("^[a-zA-Z0-9_]+$")
@@ -1164,7 +1170,7 @@ Default_Handler:
return w.Flush()
}
func generate(indir, outdir, sourceURL, interruptSystem string) error {
func generate(indir, outdir, sourceURL, interruptSystem string, onlyUsed bool) error {
if _, err := os.Stat(indir); os.IsNotExist(err) {
fmt.Fprintln(os.Stderr, "cannot find input directory:", indir)
os.Exit(1)
@@ -1177,7 +1183,14 @@ func generate(indir, outdir, sourceURL, interruptSystem string) error {
os.Exit(1)
}
sort.Strings(infiles)
targets := tinygoTargets()
for _, infile := range infiles {
if onlyUsed {
if !targets[strings.ToLower(strings.TrimSuffix(filepath.Base(infile), filepath.Ext(infile)))] {
continue
}
}
fmt.Println(infile)
device, err := readSVD(infile, sourceURL)
if err != nil {
@@ -1202,9 +1215,59 @@ func generate(indir, outdir, sourceURL, interruptSystem string) error {
return nil
}
func tinygoTargets() map[string]bool {
names := []string{}
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 nil
}
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 nil
}
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]
names = append(names, name)
}
tags := map[string]bool{}
for _, tgt := range names {
options := &compileopts.Options{
Target: tgt,
}
config, err := builder.NewConfig(options)
if err != nil {
log.Fatal(err)
}
for _, tag := range config.BuildTags() {
tags[tag] = true
}
}
return tags
}
func main() {
sourceURL := flag.String("source", "<unknown>", "source SVD file")
interruptSystem := flag.String("interrupts", "hardware", "interrupt system in use (software, hardware)")
onlyUsed := flag.Bool("only-used", false, "generate only what is defined in target")
flag.Parse()
if flag.NArg() != 2 {
fmt.Fprintln(os.Stderr, "provide exactly two arguments: input directory (with .svd files) and output directory for generated files")
@@ -1213,7 +1276,7 @@ func main() {
}
indir := flag.Arg(0)
outdir := flag.Arg(1)
err := generate(indir, outdir, *sourceURL, *interruptSystem)
err := generate(indir, outdir, *sourceURL, *interruptSystem, *onlyUsed)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)