Skip to content

Commit

Permalink
remove -mod and -modfile flags rather than setting them to zero
Browse files Browse the repository at this point in the history
Recently, a patch changed the argument `-mod=` to `-mod=readonly`
as the former is not really a valid flag value, and broke with go.work.
However, the latter seems to break our tests on Go 1.22.6
when listing all of runtimeLinknamed:

    panic: failed to load missing runtime-linknamed packages: golang.org/x/[email protected]:
        reading http://127.0.0.1:43357/mod/golang.org/x/crypto/@v/v0.16.1-0.20231129163542-152cdb1503eb.mod: 404 Not Found

It seems like, somehow, listing std packages was trying to download
x/crypto from GOPROXY - which is a local server with testdata/mod,
and so it does not contain x/crypto. However, this is entirely wrong,
as std vendors dependencies, including this very version of x/crypto.

Reverting the change to `-mod=readonly` resolves this issue,
which explains why we hadn't encountered this surprising GOPROXY error,
but the revert would also break users of go.work files.
Luckily, we have a better alternative: rather than trying to override
the value of the flags by adding more arguments, delete them entirely.
  • Loading branch information
mvdan committed Sep 4, 2024
1 parent d004d62 commit 4fcce60
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -231,7 +232,9 @@ func appendListedPackages(packages []string, mainBuild bool) error {
// However, when loading standard library packages,
// using those flags would likely result in an error,
// as the standard library uses its own Go module and vendoring.
args = append(args, "-mod=readonly", "-modfile=")
args = slices.DeleteFunc(args, func(arg string) bool {
return strings.HasPrefix(arg, "-mod=") || strings.HasPrefix(arg, "-modfile=")
})
}

args = append(args, packages...)
Expand Down

0 comments on commit 4fcce60

Please sign in to comment.