})
}
+ // On the builders only, test that a moved GOROOT still works.
+ if os.Getenv("GO_BUILDER_NAME") != "" {
+ t.tests = append(t.tests, distTest{
+ name: "moved_goroot",
+ heading: "moved GOROOT",
+ fn: func(dt *distTest) error {
+ t.runPending(dt)
+ moved := t.goroot + "-moved"
+ if err := os.Rename(t.goroot, moved); err != nil {
+ return err
+ }
+
+ // Run `go test fmt` in the moved GOROOT.
+ cmd := exec.Command(filepath.Join(moved, "bin", "go"), "test", "fmt")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ // Don't set GOROOT in the environment.
+ for _, e := range os.Environ() {
+ if !strings.HasPrefix(e, "GOROOT=") {
+ cmd.Env = append(cmd.Env, e)
+ }
+ }
+ err := cmd.Run()
+
+ if rerr := os.Rename(moved, t.goroot); rerr != nil {
+ log.Fatalf("failed to restore GOROOT: %v", rerr)
+ }
+ return err
+ },
+ })
+ }
+
// Test that internal linking of standard packages does not
// require libgcc. This ensures that we can install a Go
// release on a system that does not have a C compiler
// Global build parameters (used during package load)
var (
- Goarch string
- Goos string
+ Goarch = BuildContext.GOARCH
+ Goos = BuildContext.GOOS
ExeSuffix string
- Gopath []string
+ Gopath = filepath.SplitList(BuildContext.GOPATH)
)
+func init() {
+ if Goos == "windows" {
+ ExeSuffix = ".exe"
+ }
+}
+
var (
GOROOT = findGOROOT()
GOBIN = os.Getenv("GOBIN")
GO386 = objabi.GO386
)
+// Update build context to use our computed GOROOT.
+func init() {
+ BuildContext.GOROOT = GOROOT
+ // Note that we must use runtime.GOOS and runtime.GOARCH here,
+ // as the tool directory does not move based on environment variables.
+ // This matches the initialization of ToolDir in go/build,
+ // except for using GOROOT rather than runtime.GOROOT().
+ build.ToolDir = filepath.Join(GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+}
+
func findGOROOT() string {
if env := os.Getenv("GOROOT"); env != "" {
return filepath.Clean(env)
}
}
-func init() {
- cfg.Goarch = cfg.BuildContext.GOARCH
- cfg.Goos = cfg.BuildContext.GOOS
-
- if cfg.Goos == "windows" {
- cfg.ExeSuffix = ".exe"
- }
- cfg.Gopath = filepath.SplitList(cfg.BuildContext.GOPATH)
-}
-
// A Builder holds global state about a build.
// It does not hold per-package state, because we
// build packages in parallel, and the builder is shared.