Skip to content

Commit

Permalink
make: Unset GO111MODULE=off so that "go list" works with Go 1.21+
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anthonyfok committed Mar 22, 2024
1 parent 5868f6f commit f8c615b
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions make.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ func (u *upstream) get(gopath, repo, rev string) error {
u.rr = rr
dir := filepath.Join(gopath, "src", rr.Root)
if rev != "" {
// Run "git clone {repo} {dir}" and "git checkout {tag}"
return rr.VCS.CreateAtRev(dir, rr.Repo, rev)
}
// Run "git clone {repo} {dir}" (or the equivalent command for hg, svn, bzr)
return rr.VCS.Create(dir, rr.Repo)
}

Expand Down Expand Up @@ -216,25 +218,23 @@ func (u *upstream) tar(gopath, repo string) error {
// package type).
func (u *upstream) findMains(gopath, repo string) error {
cmd := exec.Command("go", "list", "-e", "-f", "{{.ImportPath}} {{.Name}}", repo+"/...")
cmd.Dir = filepath.Join(gopath, "src", repo)
cmd.Env = passthroughEnv()
cmd.Stderr = os.Stderr
cmd.Env = append([]string{
"GO111MODULE=off",
"GOPATH=" + gopath,
}, passthroughEnv()...)

log.Println("findMains: Running", cmd, "in", cmd.Dir)
out, err := cmd.Output()
if err != nil {
log.Println("WARNING: In findMains:", fmt.Errorf("%q: %w", cmd.Args, err))
// See https://bugs.debian.org/992610
log.Printf("Retrying without appending \"/...\" to repo")
cmd = exec.Command("go", "list", "-e", "-f", "{{.ImportPath}} {{.Name}}", repo)
cmd.Dir = filepath.Join(gopath, "src", repo)
cmd.Env = passthroughEnv()
cmd.Stderr = os.Stderr
cmd.Env = append([]string{
"GO111MODULE=off",
"GOPATH=" + gopath,
}, passthroughEnv()...)
log.Println("findMains: Running", cmd, "in", cmd.Dir)
out, err = cmd.Output()
if err != nil {
return fmt.Errorf("%q: %w", cmd.Args, err)
log.Println("WARNING: In findMains:", fmt.Errorf("%q: %w", cmd.Args, err))
}
}
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
Expand All @@ -257,25 +257,22 @@ func (u *upstream) findDependencies(gopath, repo string) error {
log.Printf("Determining dependencies\n")

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

out, err := cmd.Output()
if err != nil {
log.Println("WARNING: In findDependencies:", fmt.Errorf("%q: %w", cmd.Args, err))
// See https://bugs.debian.org/992610
log.Printf("Retrying without appending \"/...\" to repo")
cmd = exec.Command("go", "list", "-e", "-f", "{{join .Imports \"\\n\"}}\n{{join .TestImports \"\\n\"}}\n{{join .XTestImports \"\\n\"}}", repo)
cmd.Dir = filepath.Join(gopath, "src", repo)
cmd.Env = passthroughEnv()
cmd.Stderr = os.Stderr
cmd.Env = append([]string{
"GO111MODULE=off",
"GOPATH=" + gopath,
}, passthroughEnv()...)
out, err = cmd.Output()
if err != nil {
return fmt.Errorf("%q: %w", cmd.Args, err)
log.Println("WARNING: In findDependencies:", fmt.Errorf("%q: %w", cmd.Args, err))
}
}

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

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

out, err = cmd.Output()
if err != nil {
Expand Down

0 comments on commit f8c615b

Please sign in to comment.