From af4d0fe191f22a4169bff2fff721ef20a1884bd2 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 6 Nov 2021 15:17:02 +0100 Subject: [PATCH] compileopts: fix reversed append in the target file With this fix, `cflags` in the target JSON files is correctly ordered. Previously, the cflags of a parent JSON file would come after the ones in the child JSON file, which makes it hard to override properties in the child JSON file. Specifically, this fixes the case where targets/riscv32.json sets `-march=rv32imac` and targets/esp32c3.json wants to override this using `-march=rv32imc` but can't do this because its `-march` comes before the riscv32.json one. --- compileopts/target.go | 2 +- compileopts/target_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go index df269a26..c15316e2 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -94,7 +94,7 @@ func (spec *TargetSpec) overrideProperties(child *TargetSpec) { dst.Set(src) case "append", "": // or append the field of child to spec - dst.Set(reflect.AppendSlice(src, dst)) + dst.Set(reflect.AppendSlice(dst, src)) default: panic("override mode must be 'copy' or 'append' (default). I don't know how to '" + tag + "'.") } diff --git a/compileopts/target_test.go b/compileopts/target_test.go index 11071663..6aea7e81 100644 --- a/compileopts/target_test.go +++ b/compileopts/target_test.go @@ -27,7 +27,7 @@ func TestOverrideProperties(t *testing.T) { base := &TargetSpec{ GOOS: "baseGoos", CPU: "baseCpu", - Features: []string{"bf1", "bf2"}, + CFlags: []string{"-base-foo", "-base-bar"}, BuildTags: []string{"bt1", "bt2"}, Emulator: []string{"be1", "be2"}, DefaultStackSize: 42, @@ -37,7 +37,7 @@ func TestOverrideProperties(t *testing.T) { child := &TargetSpec{ GOOS: "", CPU: "chlidCpu", - Features: []string{"cf1", "cf2"}, + CFlags: []string{"-child-foo", "-child-bar"}, Emulator: []string{"ce1", "ce2"}, AutoStackSize: &childAutoStackSize, DefaultStackSize: 64, @@ -51,8 +51,8 @@ func TestOverrideProperties(t *testing.T) { if base.CPU != "chlidCpu" { t.Errorf("Overriding failed : got %v", base.CPU) } - if !reflect.DeepEqual(base.Features, []string{"cf1", "cf2", "bf1", "bf2"}) { - t.Errorf("Overriding failed : got %v", base.Features) + if !reflect.DeepEqual(base.CFlags, []string{"-base-foo", "-base-bar", "-child-foo", "-child-bar"}) { + t.Errorf("Overriding failed : got %v", base.CFlags) } if !reflect.DeepEqual(base.BuildTags, []string{"bt1", "bt2"}) { t.Errorf("Overriding failed : got %v", base.BuildTags)