Skip to content

Commit a90f4fb

Browse files
committed
Workaround "go list" error when upstream uses "../.." in import path
Closes: #992610
1 parent 8914933 commit a90f4fb

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

make.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,21 @@ func (u *upstream) findMains(gopath, repo string) error {
219219
"GO111MODULE=off",
220220
"GOPATH=" + gopath,
221221
}, passthroughEnv()...)
222+
222223
out, err := cmd.Output()
223224
if err != nil {
224-
return fmt.Errorf("go list %s (args: %v): %w", repo, cmd.Args, err)
225+
log.Println("WARNING: In findMains:", fmt.Errorf("%q: %w", cmd.Args, err))
226+
log.Printf("Retrying without appending \"/...\" to repo")
227+
cmd = exec.Command("go", "list", "-f", "{{.ImportPath}} {{.Name}}", repo)
228+
cmd.Stderr = os.Stderr
229+
cmd.Env = append([]string{
230+
"GO111MODULE=off",
231+
"GOPATH=" + gopath,
232+
}, passthroughEnv()...)
233+
out, err = cmd.Output()
234+
if err != nil {
235+
return fmt.Errorf("%q: %w", cmd.Args, err)
236+
}
225237
}
226238
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
227239
if strings.Contains(line, "/vendor/") ||
@@ -251,7 +263,18 @@ func (u *upstream) findDependencies(gopath, repo string) error {
251263

252264
out, err := cmd.Output()
253265
if err != nil {
254-
return fmt.Errorf("go list %s (args: %v): %w", repo, cmd.Args, err)
266+
log.Println("WARNING: In findDependencies:", fmt.Errorf("%q: %w", cmd.Args, err))
267+
log.Printf("Retrying without appending \"/...\" to repo")
268+
cmd = exec.Command("go", "list", "-f", "{{join .Imports \"\\n\"}}\n{{join .TestImports \"\\n\"}}\n{{join .XTestImports \"\\n\"}}", repo)
269+
cmd.Stderr = os.Stderr
270+
cmd.Env = append([]string{
271+
"GO111MODULE=off",
272+
"GOPATH=" + gopath,
273+
}, passthroughEnv()...)
274+
out, err = cmd.Output()
275+
if err != nil {
276+
return fmt.Errorf("%q: %w", cmd.Args, err)
277+
}
255278
}
256279

257280
godependencies := make(map[string]bool)

0 commit comments

Comments
 (0)