Skip to content

Commit e7911ad

Browse files
committed
build: unify vendor skipping logic
This fixes a recent bug where 'make geth' built everything instead of just geth.
1 parent 11e7a71 commit e7911ad

2 files changed

Lines changed: 31 additions & 26 deletions

File tree

‎build/ci.go‎

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,7 @@ func doInstall(cmdline []string) {
173173
if flag.NArg() > 0 {
174174
packages = flag.Args()
175175
}
176-
177-
// Resolve ./... manually and remove vendor/bazil/fuse (fuse is not in windows)
178-
out, err := goTool("list", "./...").CombinedOutput()
179-
if err != nil {
180-
log.Fatalf("package listing failed: %v\n%s", err, string(out))
181-
}
182-
packages = []string{}
183-
for _, line := range strings.Split(string(out), "\n") {
184-
if !strings.Contains(line, "vendor") {
185-
packages = append(packages, strings.TrimSpace(line))
186-
}
187-
}
188-
176+
packages = build.ExpandPackagesNoVendor(packages)
189177

190178
if *arch == "" || *arch == runtime.GOARCH {
191179
goinstall := goTool("install", buildFlags(env)...)
@@ -284,19 +272,8 @@ func doTest(cmdline []string) {
284272
if len(flag.CommandLine.Args()) > 0 {
285273
packages = flag.CommandLine.Args()
286274
}
287-
if len(packages) == 1 && packages[0] == "./..." {
288-
// Resolve ./... manually since go vet will fail on vendored stuff
289-
out, err := goTool("list", "./...").CombinedOutput()
290-
if err != nil {
291-
log.Fatalf("package listing failed: %v\n%s", err, string(out))
292-
}
293-
packages = []string{}
294-
for _, line := range strings.Split(string(out), "\n") {
295-
if !strings.Contains(line, "vendor") {
296-
packages = append(packages, strings.TrimSpace(line))
297-
}
298-
}
299-
}
275+
packages = build.ExpandPackagesNoVendor(packages)
276+
300277
// Run analysis tools before the tests.
301278
if *vet {
302279
build.MustRun(goTool("vet", packages...))

‎internal/build/util.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os"
2727
"os/exec"
2828
"path/filepath"
29+
"runtime"
2930
"strings"
3031
"text/template"
3132
)
@@ -136,3 +137,30 @@ func CopyFile(dst, src string, mode os.FileMode) {
136137
log.Fatal(err)
137138
}
138139
}
140+
141+
// ExpandPackagesNoVendor expands a cmd/go import path pattern, skipping
142+
// vendored packages.
143+
func ExpandPackagesNoVendor(patterns []string) []string {
144+
expand := false
145+
for _, pkg := range patterns {
146+
if strings.Contains(pkg, "...") {
147+
expand = true
148+
}
149+
}
150+
if expand {
151+
args := append([]string{"list"}, patterns...)
152+
cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...)
153+
out, err := cmd.CombinedOutput()
154+
if err != nil {
155+
log.Fatalf("package listing failed: %v\n%s", err, string(out))
156+
}
157+
var packages []string
158+
for _, line := range strings.Split(string(out), "\n") {
159+
if !strings.Contains(line, "/vendor/") {
160+
packages = append(packages, strings.TrimSpace(line))
161+
}
162+
}
163+
return packages
164+
}
165+
return patterns
166+
}

0 commit comments

Comments
 (0)