1
0
mirror of https://github.com/golang/go synced 2024-09-29 20:24:34 -06:00
The Go programming language
Go to file
Bryan C. Mills e64c87157d cmd/go: run tests when cmd/go is cross-compiled
When the GOOS or GOARCH of the cmd/go test binary does not match the
GOOS or GOARCH of the installed 'go' binary itself, the test currently
attempts to trick 'go test' into thinking that there were no test
functions to run.

That makes it very difficult to discover how to actually run the
tests, which in turn makes it difficult to diagnose and fix
regressions in, say, the linux-386-longtest builders. (We have had a
few of those lately, and they shouldn't be as much of an ordeal to fix
as they currently are.)

There are three underlying problems:

1. cmd/go uses its own GOOS and GOARCH to figure out which variant of
   other tools to use, and the cache keys for all installed tools and
   libraries include the IDs of the tools used to build them. So when
   cmd/go's GOARCH changes, all installed tools and binaries appear
   stale *even if* they were just installed by invoking the native
   cmd/go with the appropriate GOARCH value set.

2. The "go/build" library used by cmd/go toggles its default
   CGO_ENABLED behavior depending on whether the GOOS and GOARCH being
   imported match runtime.GOOS and runtime.GOARCH.

3. A handful of cmd/go tests explicitly use gccgo, but the user's
   installed gccgo binary cannot necessarily cross-compile to the same
   platforms as cmd/go.

To address the cache-invalidation problem, we modify the test variant
of cmd/go to use the host's native toolchain (as indicated by the new
TESTGO_GOHOSTOS and TESTGO_GOHOSTARCH environment variables) instead
of the toolchain matching the test binary itself. That allows a test
cmd/go binary compiled with GOARCH=386 to use libraries and tools
cross-compiled by the native toolchain, so that

	$ GOARCH=386 go install std cmd

suffices to make the packages in std and cmd non-stale in the
tests.

To address the CGO_ENABLED mismatch, we set CGO_ENABLED explicitly in
the test's environment whenever it may differ from the default. Since
script tests that use cgo are already expected to use a [cgo]
condition, setting the environment to match that condition fixes the
cgo-specific tests.

To address the gccgo-specific cross-compilation failures, we add a new
script condition, [cross], which evaluates to true whenever the
platform of the test binary differs from that of the native toolchain.
We can then use that condition to explicitly skip the handful of gccgo
tests that fail under cross-compilation.

Fixes #53936.

Change-Id: I8633944f674eb5941ccc95df928991660e7e8137
Reviewed-on: https://go-review.googlesource.com/c/go/+/356611
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2022-08-18 14:52:30 +00:00
.github .github: remove duplicate security link 2022-01-07 17:55:09 +00:00
api crypto/subtle: add XORBytes 2022-08-17 18:47:33 +00:00
doc doc: move Go 1.19 release notes to x/website 2022-08-01 18:07:12 +00:00
lib/time lib/time, time/tzdata: update to 2022b 2022-08-11 20:03:19 +00:00
misc misc/cgo/testsanitizers: fix code to detect gcc version correctly 2022-08-11 17:23:33 +00:00
src cmd/go: run tests when cmd/go is cross-compiled 2022-08-18 14:52:30 +00:00
test cmd/compile/internal/noder: shape-based stenciling for unified IR 2022-08-18 13:16:21 +00:00
.gitattributes
.gitignore
codereview.cfg
CONTRIBUTING.md
LICENSE
PATENTS
README.md README.md: update wiki link 2022-04-26 16:21:18 +00:00
SECURITY.md SECURITY.md: replace golang.org with go.dev 2022-04-26 19:59:47 +00:00

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://go.dev/dl/.

After downloading a binary release, visit https://go.dev/doc/install for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.