-// +build !nacl,!js,!plan9,!windows
-// run
+// errorcheckdir -n
+// run
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package main
-
-import (
- "fmt"
- "os"
- "os/exec"
- "path/filepath"
- "regexp"
-)
-
-func main() {
- // TODO: If we get rid of errchk, re-enable this test on Plan 9 and Windows.
- errchk, err := filepath.Abs("errchk")
- check(err)
-
- bugDir := filepath.Join(".", "fixedbugs", "bug345.dir")
- run("go", "tool", "compile", filepath.Join(bugDir, "io.go"))
- run(errchk, "go", "tool", "compile", "-e", filepath.Join(bugDir, "main.go"))
-
- os.Remove("io.o")
-}
-
-var bugRE = regexp.MustCompile(`(?m)^BUG`)
-
-func run(name string, args ...string) {
- cmd := exec.Command(name, args...)
- out, err := cmd.CombinedOutput()
- if bugRE.Match(out) || err != nil {
- fmt.Println(string(out))
- fmt.Println(err)
- os.Exit(1)
- }
-}
-
-func check(err error) {
- if err != nil {
- fmt.Println(err)
- os.Exit(1)
- }
-}
+package ignored
return runcmd(cmd...)
}
-func compileInDir(runcmd runCmd, dir string, flags []string, names ...string) (out []byte, err error) {
- cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", "."}
+func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, names ...string) (out []byte, err error) {
+ cmd := []string{goTool(), "tool", "compile", "-e"}
+ if localImports {
+ // Set relative path for local imports and import search path to current dir.
+ cmd = append(cmd, "-D", ".", "-I", ".")
+ }
cmd = append(cmd, flags...)
if *linkshared {
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
wantError := false
wantAuto := false
singlefilepkgs := false
+ localImports := true
f := strings.Fields(action)
if len(f) > 0 {
action = f[0]
wantError = false
case "-s":
singlefilepkgs = true
+ case "-n":
+ // Do not set relative path for local imports to current dir,
+ // e.g. do not pass -D . -I . to the compiler.
+ // Used in fixedbugs/bug345.go to allow compilation and import of local pkg.
+ // See golang.org/issue/25635
+ localImports = false
case "-t": // timeout in seconds
args = args[1:]
var err error
return
}
for _, gofiles := range pkgs {
- _, t.err = compileInDir(runcmd, longdir, flags, gofiles...)
+ _, t.err = compileInDir(runcmd, longdir, flags, localImports, gofiles...)
if t.err != nil {
return
}
errPkg--
}
for i, gofiles := range pkgs {
- out, err := compileInDir(runcmd, longdir, flags, gofiles...)
+ out, err := compileInDir(runcmd, longdir, flags, localImports, gofiles...)
if i == errPkg {
if wantError && err == nil {
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
return
}
for i, gofiles := range pkgs {
- _, err := compileInDir(runcmd, longdir, flags, gofiles...)
+ _, err := compileInDir(runcmd, longdir, flags, localImports, gofiles...)
// Allow this package compilation fail based on conditions below;
// its errors were checked in previous case.
if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) {