Update linux go to 1.15beta1
From https://ci.android.com/builds/submitted/6626886/linux/latest/go.zip
Test: m blueprint_tools
Change-Id: Ib0d1176e769611b25554177aef209bc7e6456694
diff --git a/test/run.go b/test/run.go
index 28ed865..95b94b7 100644
--- a/test/run.go
+++ b/test/run.go
@@ -34,7 +34,7 @@
keep = flag.Bool("k", false, "keep. keep temporary directory.")
numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run")
summary = flag.Bool("summary", false, "show summary of results")
- allCodegen = flag.Bool("all_codegen", false, "run all goos/goarch for codegen")
+ allCodegen = flag.Bool("all_codegen", defaultAllCodeGen(), "run all goos/goarch for codegen")
showSkips = flag.Bool("show_skips", false, "show skipped tests")
runSkips = flag.Bool("run_skips", false, "run skipped tests (ignore skip and build tags)")
linkshared = flag.Bool("linkshared", false, "")
@@ -45,6 +45,14 @@
shards = flag.Int("shards", 0, "number of shards. If 0, all tests are run. This is used by the continuous build.")
)
+// defaultAllCodeGen returns the default value of the -all_codegen
+// flag. By default, we prefer to be fast (returning false), except on
+// the linux-amd64 builder that's already very fast, so we get more
+// test coverage on trybots. See https://golang.org/issue/34297.
+func defaultAllCodeGen() bool {
+ return os.Getenv("GO_BUILDER_NAME") == "linux-amd64"
+}
+
var (
goos, goarch string
@@ -158,14 +166,6 @@
}
}
-func toolPath(name string) string {
- p := filepath.Join(os.Getenv("GOROOT"), "bin", "tool", name)
- if _, err := os.Stat(p); err != nil {
- log.Fatalf("didn't find binary at %s", p)
- }
- return p
-}
-
// goTool reports the path of the go tool to use to run the tests.
// If possible, use the same Go used to run run.go, otherwise
// fallback to the go version found in the PATH.
@@ -193,9 +193,14 @@
func goFiles(dir string) []string {
f, err := os.Open(dir)
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
dirnames, err := f.Readdirnames(-1)
- check(err)
+ f.Close()
+ if err != nil {
+ log.Fatal(err)
+ }
names := []string{}
for _, name := range dirnames {
if !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") && shardMatch(name) {
@@ -253,12 +258,6 @@
func (s skipError) Error() string { return string(s) }
-func check(err error) {
- if err != nil {
- log.Fatal(err)
- }
-}
-
// test holds the state of a test.
type test struct {
dir, gofile string
@@ -352,7 +351,9 @@
for _, file := range files {
name := file.Name()
pkgname, err := getPackageNameFromSource(filepath.Join(longdir, name))
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
i, ok := m[pkgname]
if singlefilepkgs || !ok {
i = len(pkgs)
@@ -458,7 +459,11 @@
// or else the commands will rebuild any needed packages (like runtime)
// over and over.
func goGcflags() string {
- return "-gcflags=" + os.Getenv("GO_GCFLAGS")
+ return "-gcflags=all=" + os.Getenv("GO_GCFLAGS")
+}
+
+func goGcflagsIsEmpty() bool {
+ return "" == os.Getenv("GO_GCFLAGS")
}
// run runs a test.
@@ -491,9 +496,7 @@
// skip first line
action = action[nl+1:]
}
- if strings.HasPrefix(action, "//") {
- action = action[2:]
- }
+ action = strings.TrimPrefix(action, "//")
// Check for build constraints only up to the actual code.
pkgPos := strings.Index(t.src, "\npackage")
@@ -592,7 +595,9 @@
}
err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644)
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
// A few tests (of things like the environment) require these to be set.
if os.Getenv("GOOS") == "" {
@@ -602,20 +607,23 @@
os.Setenv("GOARCH", runtime.GOARCH)
}
- useTmp := true
- runInDir := false
+ var (
+ runInDir = t.tempDir
+ tempDirIsGOPATH = false
+ )
runcmd := func(args ...string) ([]byte, error) {
cmd := exec.Command(args[0], args[1:]...)
var buf bytes.Buffer
cmd.Stdout = &buf
cmd.Stderr = &buf
- cmd.Env = os.Environ()
- if useTmp {
- cmd.Dir = t.tempDir
- cmd.Env = envForDir(cmd.Dir)
+ cmd.Env = append(os.Environ(), "GOENV=off", "GOFLAGS=")
+ if runInDir != "" {
+ cmd.Dir = runInDir
+ // Set PWD to match Dir to speed up os.Getwd in the child process.
+ cmd.Env = append(cmd.Env, "PWD="+cmd.Dir)
}
- if runInDir {
- cmd.Dir = t.goDirName()
+ if tempDirIsGOPATH {
+ cmd.Env = append(cmd.Env, "GOPATH="+t.tempDir)
}
var err error
@@ -666,7 +674,25 @@
}
// -S=2 forces outermost line numbers when disassembling inlined code.
cmdline := []string{"build", "-gcflags", "-S=2"}
- cmdline = append(cmdline, flags...)
+
+ // Append flags, but don't override -gcflags=-S=2; add to it instead.
+ for i := 0; i < len(flags); i++ {
+ flag := flags[i]
+ switch {
+ case strings.HasPrefix(flag, "-gcflags="):
+ cmdline[2] += " " + strings.TrimPrefix(flag, "-gcflags=")
+ case strings.HasPrefix(flag, "--gcflags="):
+ cmdline[2] += " " + strings.TrimPrefix(flag, "--gcflags=")
+ case flag == "-gcflags", flag == "--gcflags":
+ i++
+ if i < len(flags) {
+ cmdline[2] += " " + flags[i]
+ }
+ default:
+ cmdline = append(cmdline, flag)
+ }
+ }
+
cmdline = append(cmdline, long)
cmd := exec.Command(goTool(), cmdline...)
cmd.Env = append(os.Environ(), env.Environ()...)
@@ -805,8 +831,10 @@
pflags = append(pflags, flags...)
if setpkgpaths {
fp := filepath.Join(longdir, gofiles[0])
- pkgname, serr := getPackageNameFromSource(fp)
- check(serr)
+ pkgname, err := getPackageNameFromSource(fp)
+ if err != nil {
+ log.Fatal(err)
+ }
pflags = append(pflags, "-p", pkgname)
}
_, err := compileInDir(runcmd, longdir, pflags, localImports, gofiles...)
@@ -838,13 +866,31 @@
}
case "runindir":
- // run "go run ." in t.goDirName()
- // It's used when test requires go build and run the binary success.
- // Example when long import path require (see issue29612.dir) or test
- // contains assembly file (see issue15609.dir).
- // Verify the expected output.
- useTmp = false
- runInDir = true
+ // Make a shallow copy of t.goDirName() in its own module and GOPATH, and
+ // run "go run ." in it. The module path (and hence import path prefix) of
+ // the copy is equal to the basename of the source directory.
+ //
+ // It's used when test a requires a full 'go build' in order to compile
+ // the sources, such as when importing multiple packages (issue29612.dir)
+ // or compiling a package containing assembly files (see issue15609.dir),
+ // but still needs to be run to verify the expected output.
+ tempDirIsGOPATH = true
+ srcDir := t.goDirName()
+ modName := filepath.Base(srcDir)
+ gopathSrcDir := filepath.Join(t.tempDir, "src", modName)
+ runInDir = gopathSrcDir
+
+ if err := overlayDir(gopathSrcDir, srcDir); err != nil {
+ t.err = err
+ return
+ }
+
+ modFile := fmt.Sprintf("module %s\ngo 1.14\n", modName)
+ if err := ioutil.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil {
+ t.err = err
+ return
+ }
+
cmd := []string{goTool(), "run", goGcflags()}
if *linkshared {
cmd = append(cmd, "-linkshared")
@@ -958,13 +1004,13 @@
longdirgofile := filepath.Join(filepath.Join(cwd, t.dir), t.gofile)
cmd = append(cmd, flags...)
cmd = append(cmd, longdirgofile)
- out, err := runcmd(cmd...)
+ _, err := runcmd(cmd...)
if err != nil {
t.err = err
return
}
cmd = []string{"./a.exe"}
- out, err = runcmd(append(cmd, args...)...)
+ out, err := runcmd(append(cmd, args...)...)
if err != nil {
t.err = err
return
@@ -978,10 +1024,10 @@
// Run Go file if no special go command flags are provided;
// otherwise build an executable and run it.
// Verify the output.
- useTmp = false
+ runInDir = ""
var out []byte
var err error
- if len(flags)+len(args) == 0 && goGcflags() == "" && !*linkshared {
+ if len(flags)+len(args) == 0 && goGcflagsIsEmpty() && !*linkshared && goarch == runtime.GOARCH && goos == runtime.GOOS {
// If we're not using special go command flags,
// skip all the go command machinery.
// This avoids any time the go command would
@@ -1026,7 +1072,7 @@
defer func() {
<-rungatec
}()
- useTmp = false
+ runInDir = ""
cmd := []string{goTool(), "run", goGcflags()}
if *linkshared {
cmd = append(cmd, "-linkshared")
@@ -1059,7 +1105,7 @@
case "errorcheckoutput":
// Run Go file and write its output into temporary Go file.
// Compile and errorCheck generated Go file.
- useTmp = false
+ runInDir = ""
cmd := []string{goTool(), "run", goGcflags()}
if *linkshared {
cmd = append(cmd, "-linkshared")
@@ -1120,7 +1166,9 @@
func (t *test) makeTempDir() {
var err error
t.tempDir, err = ioutil.TempDir("", "")
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
if *keep {
log.Printf("Temporary directory is %s", t.tempDir)
}
@@ -1725,23 +1773,6 @@
assert(shouldTest("// +build !windows !plan9", "windows", "amd64"))
}
-// envForDir returns a copy of the environment
-// suitable for running in the given directory.
-// The environment is the current process's environment
-// but with an updated $PWD, so that an os.Getwd in the
-// child will be faster.
-func envForDir(dir string) []string {
- env := os.Environ()
- for i, kv := range env {
- if strings.HasPrefix(kv, "PWD=") {
- env[i] = "PWD=" + dir
- return env
- }
- }
- env = append(env, "PWD="+dir)
- return env
-}
-
func getenv(key, def string) string {
value := os.Getenv(key)
if value != "" {
@@ -1749,3 +1780,66 @@
}
return def
}
+
+// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
+func overlayDir(dstRoot, srcRoot string) error {
+ dstRoot = filepath.Clean(dstRoot)
+ if err := os.MkdirAll(dstRoot, 0777); err != nil {
+ return err
+ }
+
+ srcRoot, err := filepath.Abs(srcRoot)
+ if err != nil {
+ return err
+ }
+
+ return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
+ if err != nil || srcPath == srcRoot {
+ return err
+ }
+
+ suffix := strings.TrimPrefix(srcPath, srcRoot)
+ for len(suffix) > 0 && suffix[0] == filepath.Separator {
+ suffix = suffix[1:]
+ }
+ dstPath := filepath.Join(dstRoot, suffix)
+
+ perm := info.Mode() & os.ModePerm
+ if info.Mode()&os.ModeSymlink != 0 {
+ info, err = os.Stat(srcPath)
+ if err != nil {
+ return err
+ }
+ perm = info.Mode() & os.ModePerm
+ }
+
+ // Always copy directories (don't symlink them).
+ // If we add a file in the overlay, we don't want to add it in the original.
+ if info.IsDir() {
+ return os.MkdirAll(dstPath, perm|0200)
+ }
+
+ // If the OS supports symlinks, use them instead of copying bytes.
+ if err := os.Symlink(srcPath, dstPath); err == nil {
+ return nil
+ }
+
+ // Otherwise, copy the bytes.
+ src, err := os.Open(srcPath)
+ if err != nil {
+ return err
+ }
+ defer src.Close()
+
+ dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
+ if err != nil {
+ return err
+ }
+
+ _, err = io.Copy(dst, src)
+ if closeErr := dst.Close(); err == nil {
+ err = closeErr
+ }
+ return err
+ })
+}