Skip to content

Commit f8c615b

Browse files
committed
make: Unset GO111MODULE=off so that "go list" works with Go 1.21+
This fixes dh-make-golang’s failure to determine dependencies since 2023-08-21 when Go 1.21 became the default in Debian. Closes: #1050523
1 parent 5868f6f commit f8c615b

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

make.go

+17-24
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ func (u *upstream) get(gopath, repo, rev string) error {
132132
u.rr = rr
133133
dir := filepath.Join(gopath, "src", rr.Root)
134134
if rev != "" {
135+
// Run "git clone {repo} {dir}" and "git checkout {tag}"
135136
return rr.VCS.CreateAtRev(dir, rr.Repo, rev)
136137
}
138+
// Run "git clone {repo} {dir}" (or the equivalent command for hg, svn, bzr)
137139
return rr.VCS.Create(dir, rr.Repo)
138140
}
139141

@@ -216,25 +218,23 @@ func (u *upstream) tar(gopath, repo string) error {
216218
// package type).
217219
func (u *upstream) findMains(gopath, repo string) error {
218220
cmd := exec.Command("go", "list", "-e", "-f", "{{.ImportPath}} {{.Name}}", repo+"/...")
221+
cmd.Dir = filepath.Join(gopath, "src", repo)
222+
cmd.Env = passthroughEnv()
219223
cmd.Stderr = os.Stderr
220-
cmd.Env = append([]string{
221-
"GO111MODULE=off",
222-
"GOPATH=" + gopath,
223-
}, passthroughEnv()...)
224-
224+
log.Println("findMains: Running", cmd, "in", cmd.Dir)
225225
out, err := cmd.Output()
226226
if err != nil {
227227
log.Println("WARNING: In findMains:", fmt.Errorf("%q: %w", cmd.Args, err))
228+
// See https://bugs.debian.org/992610
228229
log.Printf("Retrying without appending \"/...\" to repo")
229230
cmd = exec.Command("go", "list", "-e", "-f", "{{.ImportPath}} {{.Name}}", repo)
231+
cmd.Dir = filepath.Join(gopath, "src", repo)
232+
cmd.Env = passthroughEnv()
230233
cmd.Stderr = os.Stderr
231-
cmd.Env = append([]string{
232-
"GO111MODULE=off",
233-
"GOPATH=" + gopath,
234-
}, passthroughEnv()...)
234+
log.Println("findMains: Running", cmd, "in", cmd.Dir)
235235
out, err = cmd.Output()
236236
if err != nil {
237-
return fmt.Errorf("%q: %w", cmd.Args, err)
237+
log.Println("WARNING: In findMains:", fmt.Errorf("%q: %w", cmd.Args, err))
238238
}
239239
}
240240
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
@@ -257,25 +257,22 @@ func (u *upstream) findDependencies(gopath, repo string) error {
257257
log.Printf("Determining dependencies\n")
258258

259259
cmd := exec.Command("go", "list", "-e", "-f", "{{join .Imports \"\\n\"}}\n{{join .TestImports \"\\n\"}}\n{{join .XTestImports \"\\n\"}}", repo+"/...")
260+
cmd.Dir = filepath.Join(gopath, "src", repo)
261+
cmd.Env = passthroughEnv()
260262
cmd.Stderr = os.Stderr
261-
cmd.Env = append([]string{
262-
"GO111MODULE=off",
263-
"GOPATH=" + gopath,
264-
}, passthroughEnv()...)
265263

266264
out, err := cmd.Output()
267265
if err != nil {
268266
log.Println("WARNING: In findDependencies:", fmt.Errorf("%q: %w", cmd.Args, err))
267+
// See https://bugs.debian.org/992610
269268
log.Printf("Retrying without appending \"/...\" to repo")
270269
cmd = exec.Command("go", "list", "-e", "-f", "{{join .Imports \"\\n\"}}\n{{join .TestImports \"\\n\"}}\n{{join .XTestImports \"\\n\"}}", repo)
270+
cmd.Dir = filepath.Join(gopath, "src", repo)
271+
cmd.Env = passthroughEnv()
271272
cmd.Stderr = os.Stderr
272-
cmd.Env = append([]string{
273-
"GO111MODULE=off",
274-
"GOPATH=" + gopath,
275-
}, passthroughEnv()...)
276273
out, err = cmd.Output()
277274
if err != nil {
278-
return fmt.Errorf("%q: %w", cmd.Args, err)
275+
log.Println("WARNING: In findDependencies:", fmt.Errorf("%q: %w", cmd.Args, err))
279276
}
280277
}
281278

@@ -301,12 +298,8 @@ func (u *upstream) findDependencies(gopath, repo string) error {
301298

302299
// Remove all packages which are in the standard lib.
303300
cmd = exec.Command("go", "list", "std")
304-
cmd.Dir = filepath.Join(gopath, "src", repo)
305301
cmd.Stderr = os.Stderr
306-
cmd.Env = append([]string{
307-
// Not affected by GO111MODULE
308-
"GOPATH=" + gopath,
309-
}, passthroughEnv()...)
302+
cmd.Env = passthroughEnv()
310303

311304
out, err = cmd.Output()
312305
if err != nil {

0 commit comments

Comments
 (0)