Skip to content

Commit 5fc8835

Browse files
JAORMXEric Stroczynski
and
Eric Stroczynski
committed
Only add explicit -mod=vendor if needed (#2332)
* Only add explicit -mod=vendor if needed -mod=vendor is not needed if it's already set in GOFLAGS. So lets not set it unless it's needed. This is an issue for commands such as `go test` and `go vet` ( see: golang/go#32471 ). This avois such an issue. * Add comments for -mod=vendor flag addition This takes into us the suggestions from @estroz and adds the relevant comments for the addition of the -mod=vendor GOFLAG Co-authored-by: Eric Stroczynski <[email protected]>
1 parent 0c3fd14 commit 5fc8835

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/util/projutil/exec.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ func (opts GoCmdOptions) getGeneralArgsWithCmd(cmd string) ([]string, error) {
124124
}
125125
// Does the first "go" subcommand accept -mod=vendor?
126126
_, ok := validVendorCmds[bargs[0]]
127-
if err == nil && info.IsDir() && ok {
127+
// TODO: remove needsModVendor when
128+
// https://github.com/golang/go/issues/32471 is resolved.
129+
if err == nil && info.IsDir() && ok && needsModVendor() {
128130
bargs = append(bargs, "-mod=vendor")
129131
}
130132
}
@@ -135,6 +137,14 @@ func (opts GoCmdOptions) getGeneralArgsWithCmd(cmd string) ([]string, error) {
135137
return bargs, nil
136138
}
137139

140+
// needsModVendor resolves https://github.com/golang/go/issues/32471,
141+
// where any flags in GOFLAGS that are also set in the CLI are
142+
// duplicated, causing 'go' invocation errors.
143+
// TODO: remove once the issue is resolved.
144+
func needsModVendor() bool {
145+
return !strings.Contains(os.Getenv("GOFLAGS"), "-mod=vendor")
146+
}
147+
138148
func (opts GoCmdOptions) setCmdFields(c *exec.Cmd) {
139149
c.Env = append(c.Env, os.Environ()...)
140150
if len(opts.Env) != 0 {

0 commit comments

Comments
 (0)