Skip to content

Commit

Permalink
build: unify vendor skipping logic
Browse files Browse the repository at this point in the history
This fixes a recent bug where 'make geth' built everything instead of
just geth.
  • Loading branch information
fjl committed Mar 23, 2017
1 parent 11e7a71 commit e7911ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
29 changes: 3 additions & 26 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,7 @@ func doInstall(cmdline []string) {
if flag.NArg() > 0 {
packages = flag.Args()
}

// Resolve ./... manually and remove vendor/bazil/fuse (fuse is not in windows)
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))
}
}

packages = build.ExpandPackagesNoVendor(packages)

if *arch == "" || *arch == runtime.GOARCH {
goinstall := goTool("install", buildFlags(env)...)
Expand Down Expand Up @@ -284,19 +272,8 @@ func doTest(cmdline []string) {
if len(flag.CommandLine.Args()) > 0 {
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))
}
}
}
packages = build.ExpandPackagesNoVendor(packages)

// Run analysis tools before the tests.
if *vet {
build.MustRun(goTool("vet", packages...))
Expand Down
28 changes: 28 additions & 0 deletions internal/build/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"text/template"
)
Expand Down Expand Up @@ -136,3 +137,30 @@ func CopyFile(dst, src string, mode os.FileMode) {
log.Fatal(err)
}
}

// ExpandPackagesNoVendor expands a cmd/go import path pattern, skipping
// vendored packages.
func ExpandPackagesNoVendor(patterns []string) []string {
expand := false
for _, pkg := range patterns {
if strings.Contains(pkg, "...") {
expand = true
}
}
if expand {
args := append([]string{"list"}, patterns...)
cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("package listing failed: %v\n%s", err, string(out))
}
var packages []string
for _, line := range strings.Split(string(out), "\n") {
if !strings.Contains(line, "/vendor/") {
packages = append(packages, strings.TrimSpace(line))
}
}
return packages
}
return patterns
}

0 comments on commit e7911ad

Please sign in to comment.