Skip to content

Commit eb00167

Browse files
committed
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 <[email protected]> Reviewed-by: Tobias Klauser <[email protected]>
1 parent 277609f commit eb00167

File tree

2 files changed

+52
-51
lines changed

2 files changed

+52
-51
lines changed

src/cmd/link/dwarf_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -171,54 +171,3 @@ func TestDWARFiOS(t *testing.T) {
171171
testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm", "GOARM=7")
172172
testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm64")
173173
}
174-
175-
func TestBuildFortvOS(t *testing.T) {
176-
testenv.MustHaveCGO(t)
177-
testenv.MustHaveGoBuild(t)
178-
179-
// Only run this on darwin/amd64, where we can cross build for tvOS.
180-
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
181-
t.Skip("skipping on non-darwin/amd64 platform")
182-
}
183-
if err := exec.Command("xcrun", "--help").Run(); err != nil {
184-
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
185-
}
186-
187-
sdkPath, err := exec.Command("xcrun", "--sdk", "appletvos", "--show-sdk-path").Output()
188-
if err != nil {
189-
t.Fatalf("xcrun --sdk appletvos --show-sdk-path failed: %v", err)
190-
}
191-
CC := []string{
192-
"clang",
193-
"-arch",
194-
"arm64",
195-
"-isysroot", strings.TrimSpace(string(sdkPath)),
196-
"-mtvos-version-min=12.0",
197-
"-fembed-bitcode",
198-
"-framework", "CoreFoundation",
199-
}
200-
lib := filepath.Join("testdata", "lib.go")
201-
tmpDir, err := ioutil.TempDir("", "go-link-TestBuildFortvOS")
202-
if err != nil {
203-
t.Fatal(err)
204-
}
205-
defer os.RemoveAll(tmpDir)
206-
207-
ar := filepath.Join(tmpDir, "lib.a")
208-
cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
209-
cmd.Env = append(os.Environ(),
210-
"CGO_ENABLED=1",
211-
"GOOS=darwin",
212-
"GOARCH=arm64",
213-
"CC="+strings.Join(CC, " "),
214-
)
215-
if out, err := cmd.CombinedOutput(); err != nil {
216-
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
217-
}
218-
219-
link := exec.Command(CC[0], CC[1:]...)
220-
link.Args = append(link.Args, ar, filepath.Join("testdata", "main.m"))
221-
if out, err := link.CombinedOutput(); err != nil {
222-
t.Fatalf("%v: %v:\n%s", link.Args, err, out)
223-
}
224-
}

src/cmd/link/link_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/exec"
88
"path/filepath"
99
"regexp"
10+
"runtime"
1011
"strings"
1112
"testing"
1213
)
@@ -177,3 +178,54 @@ main.x: relocation target main.zero not defined
177178
t.Fatalf("want:\n%sgot:\n%s", want, got)
178179
}
179180
}
181+
182+
func TestBuildFortvOS(t *testing.T) {
183+
testenv.MustHaveCGO(t)
184+
testenv.MustHaveGoBuild(t)
185+
186+
// Only run this on darwin/amd64, where we can cross build for tvOS.
187+
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
188+
t.Skip("skipping on non-darwin/amd64 platform")
189+
}
190+
if err := exec.Command("xcrun", "--help").Run(); err != nil {
191+
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
192+
}
193+
194+
sdkPath, err := exec.Command("xcrun", "--sdk", "appletvos", "--show-sdk-path").Output()
195+
if err != nil {
196+
t.Skip("failed to locate appletvos SDK, skipping")
197+
}
198+
CC := []string{
199+
"clang",
200+
"-arch",
201+
"arm64",
202+
"-isysroot", strings.TrimSpace(string(sdkPath)),
203+
"-mtvos-version-min=12.0",
204+
"-fembed-bitcode",
205+
"-framework", "CoreFoundation",
206+
}
207+
lib := filepath.Join("testdata", "lib.go")
208+
tmpDir, err := ioutil.TempDir("", "go-link-TestBuildFortvOS")
209+
if err != nil {
210+
t.Fatal(err)
211+
}
212+
defer os.RemoveAll(tmpDir)
213+
214+
ar := filepath.Join(tmpDir, "lib.a")
215+
cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
216+
cmd.Env = append(os.Environ(),
217+
"CGO_ENABLED=1",
218+
"GOOS=darwin",
219+
"GOARCH=arm64",
220+
"CC="+strings.Join(CC, " "),
221+
)
222+
if out, err := cmd.CombinedOutput(); err != nil {
223+
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
224+
}
225+
226+
link := exec.Command(CC[0], CC[1:]...)
227+
link.Args = append(link.Args, ar, filepath.Join("testdata", "main.m"))
228+
if out, err := link.CombinedOutput(); err != nil {
229+
t.Fatalf("%v: %v:\n%s", link.Args, err, out)
230+
}
231+
}

0 commit comments

Comments
 (0)