Commit eb00167e authored by Elias Naur's avatar Elias Naur

cmd/link: skip TestBuildFortvOS if the SDK is missing

While we're here, move the test from dwarf_test.go to link_test.go;
it doesn't have anything to do with DWARF.

Should fix the macOS builders with only the Xcode command line tools
installed.

Change-Id: Iaaba1b589f4d778705f7b627f78c2b12388e2b3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/168462
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarTobias Klauser <tobias.klauser@gmail.com>
parent 277609f8
...@@ -171,54 +171,3 @@ func TestDWARFiOS(t *testing.T) { ...@@ -171,54 +171,3 @@ func TestDWARFiOS(t *testing.T) {
testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm", "GOARM=7") testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm", "GOARM=7")
testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm64") testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm64")
} }
func TestBuildFortvOS(t *testing.T) {
testenv.MustHaveCGO(t)
testenv.MustHaveGoBuild(t)
// Only run this on darwin/amd64, where we can cross build for tvOS.
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
t.Skip("skipping on non-darwin/amd64 platform")
}
if err := exec.Command("xcrun", "--help").Run(); err != nil {
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
}
sdkPath, err := exec.Command("xcrun", "--sdk", "appletvos", "--show-sdk-path").Output()
if err != nil {
t.Fatalf("xcrun --sdk appletvos --show-sdk-path failed: %v", err)
}
CC := []string{
"clang",
"-arch",
"arm64",
"-isysroot", strings.TrimSpace(string(sdkPath)),
"-mtvos-version-min=12.0",
"-fembed-bitcode",
"-framework", "CoreFoundation",
}
lib := filepath.Join("testdata", "lib.go")
tmpDir, err := ioutil.TempDir("", "go-link-TestBuildFortvOS")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)
ar := filepath.Join(tmpDir, "lib.a")
cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
cmd.Env = append(os.Environ(),
"CGO_ENABLED=1",
"GOOS=darwin",
"GOARCH=arm64",
"CC="+strings.Join(CC, " "),
)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
}
link := exec.Command(CC[0], CC[1:]...)
link.Args = append(link.Args, ar, filepath.Join("testdata", "main.m"))
if out, err := link.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", link.Args, err, out)
}
}
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime"
"strings" "strings"
"testing" "testing"
) )
...@@ -177,3 +178,54 @@ main.x: relocation target main.zero not defined ...@@ -177,3 +178,54 @@ main.x: relocation target main.zero not defined
t.Fatalf("want:\n%sgot:\n%s", want, got) t.Fatalf("want:\n%sgot:\n%s", want, got)
} }
} }
func TestBuildFortvOS(t *testing.T) {
testenv.MustHaveCGO(t)
testenv.MustHaveGoBuild(t)
// Only run this on darwin/amd64, where we can cross build for tvOS.
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
t.Skip("skipping on non-darwin/amd64 platform")
}
if err := exec.Command("xcrun", "--help").Run(); err != nil {
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
}
sdkPath, err := exec.Command("xcrun", "--sdk", "appletvos", "--show-sdk-path").Output()
if err != nil {
t.Skip("failed to locate appletvos SDK, skipping")
}
CC := []string{
"clang",
"-arch",
"arm64",
"-isysroot", strings.TrimSpace(string(sdkPath)),
"-mtvos-version-min=12.0",
"-fembed-bitcode",
"-framework", "CoreFoundation",
}
lib := filepath.Join("testdata", "lib.go")
tmpDir, err := ioutil.TempDir("", "go-link-TestBuildFortvOS")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)
ar := filepath.Join(tmpDir, "lib.a")
cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
cmd.Env = append(os.Environ(),
"CGO_ENABLED=1",
"GOOS=darwin",
"GOARCH=arm64",
"CC="+strings.Join(CC, " "),
)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
}
link := exec.Command(CC[0], CC[1:]...)
link.Args = append(link.Args, ar, filepath.Join("testdata", "main.m"))
if out, err := link.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", link.Args, err, out)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment