Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions compileopts/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,24 @@ func GetTargetSpecs() (map[string]*TargetSpec, error) {
continue
}
path := filepath.Join(dir, entry.Name())

// Read raw JSON to check if this is an inheritable-only (non-board)
// target before resolving inheritance, since the field would
// propagate to child board targets through inheritance.
rawData, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("could not read target file: %w", err)
}
var rawCheck struct {
InheritableOnly bool `json:"inheritable-only"`
}
if err := json.Unmarshal(rawData, &rawCheck); err != nil {
return nil, fmt.Errorf("could not parse target file %s: %w", entry.Name(), err)
}
if rawCheck.InheritableOnly {
continue
}

spec, err := LoadTarget(&Options{Target: path})
if err != nil {
return nil, fmt.Errorf("could not list target: %w", err)
Expand Down
31 changes: 31 additions & 0 deletions compileopts/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ func TestLoadTarget(t *testing.T) {
}
}

func TestGetTargetSpecs_InheritableOnlyTargetsExcluded(t *testing.T) {
specs, err := GetTargetSpecs()
if err != nil {
t.Fatal("GetTargetSpecs failed:", err)
}

// Inheritable-only processor-level targets should not appear in the listing.
inheritableOnlyTargets := []string{"esp32", "esp32c3", "esp32c6", "esp32s3", "esp8266", "rp2040", "rp2350", "rp2350b"}
for _, name := range inheritableOnlyTargets {
if _, ok := specs[name]; ok {
t.Errorf("inheritable-only target %q should not appear in GetTargetSpecs", name)
}
}

// Board targets that inherit from inheritable-only targets should still appear.
boardTargets := []string{"esp32-coreboard-v2", "pico"}
for _, name := range boardTargets {
if _, ok := specs[name]; !ok {
t.Errorf("board target %q should appear in GetTargetSpecs", name)
}
}
}

func TestLoadTarget_InheritableOnlyTargetStillLoadable(t *testing.T) {
// Inheritable-only targets should still be loadable directly (for building).
_, err := LoadTarget(&Options{Target: "esp32"})
if err != nil {
t.Errorf("LoadTarget should still load inheritable-only target esp32: %v", err)
}
}

func TestOverrideProperties(t *testing.T) {
baseAutoStackSize := true
base := &TargetSpec{
Expand Down
1 change: 1 addition & 0 deletions targets/esp32.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inherits": ["xtensa"],
"inheritable-only": true,
"cpu": "esp32",
"features": "+atomctl,+bool,+clamps,+coprocessor,+debug,+density,+dfpaccel,+div32,+exception,+fp,+highpriinterrupts,+interrupt,+loop,+mac16,+memctl,+minmax,+miscsr,+mul32,+mul32high,+nsa,+prid,+regprotect,+rvector,+s32c1i,+sext,+threadptr,+timerint,+windowed",
"build-tags": ["esp32", "esp"],
Expand Down
1 change: 1 addition & 0 deletions targets/esp32c3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inherits": ["riscv32"],
"inheritable-only": true,
"features": "+32bit,+c,+m,+zmmul,-a,-b,-d,-e,-experimental-sdext,-experimental-sdtrig,-experimental-smctr,-experimental-ssctr,-experimental-svukte,-experimental-xqcia,-experimental-xqciac,-experimental-xqcicli,-experimental-xqcicm,-experimental-xqcics,-experimental-xqcicsr,-experimental-xqciint,-experimental-xqcilo,-experimental-xqcilsm,-experimental-xqcisls,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-f,-h,-relax,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xesppie,-xmipscmove,-xmipslsp,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zacas,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
"build-tags": ["esp32c3", "esp"],
"serial": "usb",
Expand Down
1 change: 1 addition & 0 deletions targets/esp32s3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inherits": ["xtensa"],
"inheritable-only": true,
"cpu": "esp32s3",
"features": "+atomctl,+bool,+clamps,+coprocessor,+debug,+density,+div32,+esp32s3,+exception,+fp,+highpriinterrupts,+interrupt,+loop,+mac16,+memctl,+minmax,+miscsr,+mul32,+mul32high,+nsa,+prid,+regprotect,+rvector,+s32c1i,+sext,+threadptr,+timerint,+windowed",
"build-tags": ["esp32s3", "esp"],
Expand Down
1 change: 1 addition & 0 deletions targets/esp8266.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inherits": ["xtensa"],
"inheritable-only": true,
"cpu": "esp8266",
"features": "+debug,+density,+exception,+extendedl32r,+highpriinterrupts,+interrupt,+mul32,+nsa,+prid,+regprotect,+rvector,+timerint",
"build-tags": ["esp8266", "esp"],
Expand Down
1 change: 1 addition & 0 deletions targets/rp2040.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inherits": ["cortex-m0plus"],
"inheritable-only": true,
"build-tags": ["rp2040", "rp"],
"scheduler": "tasks",
"flash-1200-bps-reset": "true",
Expand Down
1 change: 1 addition & 0 deletions targets/rp2350.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inherits": ["cortex-m33"],
"inheritable-only": true,
"build-tags": ["rp2350", "rp"],
"scheduler": "tasks",
"flash-1200-bps-reset": "true",
Expand Down
1 change: 1 addition & 0 deletions targets/rp2350b.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inherits": ["rp2350"],
"inheritable-only": true,
"build-tags": ["rp2350b"],
"serial-port": ["2e8a:000f"]
}
Loading