main: test other architectures by specifying a different GOARCH

... instead of setting a special -target= value. This is more robust and
makes sure that the test actually tests different arcitectures as they
would be compiled by TinyGo. As an example, the bug of the bugfix in the
previous commit ("arm: use armv7 instead of thumbv7") would have been
caught if this change was applied earlier.

I've decided to put GOOS/GOARCH in compileopts.Options, as it makes
sense to me to treat them the same way as command line parameters.
This commit is contained in:
Ayke van Laethem
2021-09-22 02:37:10 +02:00
committed by Ron Evans
parent 36f1517e8d
commit 0a80da46b1
8 changed files with 72 additions and 47 deletions
+4 -1
View File
@@ -16,8 +16,11 @@ var (
)
// Options contains extra options to give to the compiler. These options are
// usually passed from the command line.
// usually passed from the command line, but can also be passed in environment
// variables for example.
type Options struct {
GOOS string // environment variable
GOARCH string // environment variable
Target string
Opt string
GC string
+10 -12
View File
@@ -161,36 +161,34 @@ func (spec *TargetSpec) resolveInherits() error {
}
// Load a target specification.
func LoadTarget(target string) (*TargetSpec, error) {
if target == "" {
func LoadTarget(options *Options) (*TargetSpec, error) {
if options.Target == "" {
// Configure based on GOOS/GOARCH environment variables (falling back to
// runtime.GOOS/runtime.GOARCH), and generate a LLVM target based on it.
goos := goenv.Get("GOOS")
goarch := goenv.Get("GOARCH")
llvmos := goos
llvmos := options.GOOS
llvmarch := map[string]string{
"386": "i386",
"amd64": "x86_64",
"arm64": "aarch64",
"arm": "armv7",
}[goarch]
}[options.GOARCH]
if llvmarch == "" {
llvmarch = goarch
llvmarch = options.GOARCH
}
// Target triples (which actually have four components, but are called
// triples for historical reasons) have the form:
// arch-vendor-os-environment
target = llvmarch + "-unknown-" + llvmos
if goarch == "arm" {
target := llvmarch + "-unknown-" + llvmos
if options.GOARCH == "arm" {
target += "-gnueabihf"
}
return defaultTarget(goos, goarch, target)
return defaultTarget(options.GOOS, options.GOARCH, target)
}
// See whether there is a target specification for this target (e.g.
// Arduino).
spec := &TargetSpec{}
err := spec.loadFromGivenStr(target)
err := spec.loadFromGivenStr(options.Target)
if err == nil {
// Successfully loaded this target from a built-in .json file. Make sure
// it includes all parents as specified in the "inherits" key.
@@ -206,7 +204,7 @@ func LoadTarget(target string) (*TargetSpec, error) {
} else {
// Load target from given triple, ignore GOOS/GOARCH environment
// variables.
tripleSplit := strings.Split(target, "-")
tripleSplit := strings.Split(options.Target, "-")
if len(tripleSplit) < 3 {
return nil, errors.New("expected a full LLVM target or a custom target in -target flag")
}
+2 -2
View File
@@ -6,12 +6,12 @@ import (
)
func TestLoadTarget(t *testing.T) {
_, err := LoadTarget("arduino")
_, err := LoadTarget(&Options{Target: "arduino"})
if err != nil {
t.Error("LoadTarget test failed:", err)
}
_, err = LoadTarget("notexist")
_, err = LoadTarget(&Options{Target: "notexist"})
if err == nil {
t.Error("LoadTarget should have failed with non existing target")
}