1
0
mirror of https://github.com/golang/go synced 2024-11-23 00:40:08 -07:00

[dev.cmdgo] cmd/link: fix TestBuildForTvOS

This test was broken in CL 334732 on darwin.

The test invokes 'go build' with a CC containing the arguments
-framework CoreFoundation. Previously, the go command split CC on
whitespace, and inserted the arguments after the command line when
running CC directly. Those arguments weren't passed to cgo though,
so cgo ran CC without -framework CoreFoundation (or any of the other
flags).

In CL 334732, we pass CC through to cgo, and cgo splits arguments
using str.SplitQuotedFields. So -framework CoreFoundation actually
gets passed to the C compiler. It appears that -framework flags are
only meant to be used in linking operations, so when cgo invokes clang
with -E (run preprocessor only), clang emits an error that -framework
is unused.

This change fixes the test by moving -framework CoreFoundation out of
CC and into CGO_LDFLAGS.

Change-Id: Ie884c3c0d8bea21fad57f325d19989ad39de7204
Reviewed-on: https://go-review.googlesource.com/c/go/+/341929
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Jay Conrod 2021-08-12 14:33:58 -07:00
parent d397fc1169
commit e2e1987b31

View File

@ -282,8 +282,8 @@ func TestBuildForTvOS(t *testing.T) {
"-isysroot", strings.TrimSpace(string(sdkPath)), "-isysroot", strings.TrimSpace(string(sdkPath)),
"-mtvos-version-min=12.0", "-mtvos-version-min=12.0",
"-fembed-bitcode", "-fembed-bitcode",
"-framework", "CoreFoundation",
} }
CGO_LDFLAGS := []string{"-framework", "CoreFoundation"}
lib := filepath.Join("testdata", "testBuildFortvOS", "lib.go") lib := filepath.Join("testdata", "testBuildFortvOS", "lib.go")
tmpDir := t.TempDir() tmpDir := t.TempDir()
@ -295,12 +295,14 @@ func TestBuildForTvOS(t *testing.T) {
"GOARCH=arm64", "GOARCH=arm64",
"CC="+strings.Join(CC, " "), "CC="+strings.Join(CC, " "),
"CGO_CFLAGS=", // ensure CGO_CFLAGS does not contain any flags. Issue #35459 "CGO_CFLAGS=", // ensure CGO_CFLAGS does not contain any flags. Issue #35459
"CGO_LDFLAGS="+strings.Join(CGO_LDFLAGS, " "),
) )
if out, err := cmd.CombinedOutput(); err != nil { if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out) t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
} }
link := exec.Command(CC[0], CC[1:]...) link := exec.Command(CC[0], CC[1:]...)
link.Args = append(link.Args, CGO_LDFLAGS...)
link.Args = append(link.Args, "-o", filepath.Join(tmpDir, "a.out")) // Avoid writing to package directory. link.Args = append(link.Args, "-o", filepath.Join(tmpDir, "a.out")) // Avoid writing to package directory.
link.Args = append(link.Args, ar, filepath.Join("testdata", "testBuildFortvOS", "main.m")) link.Args = append(link.Args, ar, filepath.Join("testdata", "testBuildFortvOS", "main.m"))
if out, err := link.CombinedOutput(); err != nil { if out, err := link.CombinedOutput(); err != nil {