build, internal/build: sort out vendor quircks

This commit is contained in:
Péter Szilágyi 2016-10-24 18:59:18 +03:00
parent d4336f00a6
commit 0ed91a7557
No known key found for this signature in database
GPG key ID: 119A76381CCB7DD2
2 changed files with 16 additions and 11 deletions

View file

@ -178,6 +178,7 @@ func goTool(subcmd string, args ...string) *exec.Cmd {
cmd := exec.Command(gocmd, subcmd) cmd := exec.Command(gocmd, subcmd)
cmd.Args = append(cmd.Args, args...) cmd.Args = append(cmd.Args, args...)
cmd.Env = []string{ cmd.Env = []string{
"GO15VENDOREXPERIMENT=1",
"GOPATH=" + build.GOPATH(), "GOPATH=" + build.GOPATH(),
"GOBIN=" + GOBIN, "GOBIN=" + GOBIN,
} }
@ -200,11 +201,24 @@ func doTest(cmdline []string) {
coverage = flag.Bool("coverage", false, "Whether to record code coverage") coverage = flag.Bool("coverage", false, "Whether to record code coverage")
) )
flag.CommandLine.Parse(cmdline) flag.CommandLine.Parse(cmdline)
packages := []string{"./..."} packages := []string{"./..."}
if len(flag.CommandLine.Args()) > 0 { if len(flag.CommandLine.Args()) > 0 {
packages = flag.CommandLine.Args() packages = flag.CommandLine.Args()
} }
if len(packages) == 1 && packages[0] == "./..." {
// Resolve ./... manually since go vet will fail on vendored stuff
out, err := goTool("list", "./...").CombinedOutput()
if err != nil {
log.Fatalf("package listing failed: %v\n%s", err, string(out))
}
packages = []string{}
for _, line := range strings.Split(string(out), "\n") {
if !strings.Contains(line, "vendor") {
packages = append(packages, strings.TrimSpace(line))
}
}
}
// Run analysis tools before the tests. // Run analysis tools before the tests.
if *vet { if *vet {
build.MustRun(goTool("vet", packages...)) build.MustRun(goTool("vet", packages...))

View file

@ -55,16 +55,7 @@ func GOPATH() string {
if len(path) == 0 { if len(path) == 0 {
log.Fatal("GOPATH is not set") log.Fatal("GOPATH is not set")
} }
// Ensure Godeps workspace is present in the path.
godeps, _ := filepath.Abs(filepath.Join("Godeps", "_workspace"))
for _, dir := range path {
if dir == godeps {
return strings.Join(path, string(filepath.ListSeparator)) return strings.Join(path, string(filepath.ListSeparator))
}
}
newpath := append(path[:1], godeps)
newpath = append(newpath, path[1:]...)
return strings.Join(newpath, string(filepath.ListSeparator))
} }
// VERSION returns the content of the VERSION file. // VERSION returns the content of the VERSION file.