Skip to content

Commit 3868802

Browse files
committed
internal/imports: change processEnv to use buildflags
This change adds a buildFlags variable to the processEnv struct rather than appending them to the GOFLAGS by using a space separator. Fixes golang/go#37108 Change-Id: I4331066c30fa51f0133504d723132527b00ce74a Reviewed-on: https://go-review.googlesource.com/c/tools/+/218857 Reviewed-by: Heschi Kreinick <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent bdd8440 commit 3868802

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

internal/imports/fix.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ type ProcessEnv struct {
749749
LocalPrefix string
750750
Debug bool
751751

752+
BuildFlags []string
753+
752754
// If non-empty, these will be used instead of the
753755
// process-wide values.
754756
GOPATH, GOROOT, GO111MODULE, GOPROXY, GOFLAGS, GOSUMDB string
@@ -821,8 +823,13 @@ func (e *ProcessEnv) buildContext() *build.Context {
821823
return &ctx
822824
}
823825

824-
func (e *ProcessEnv) invokeGo(args ...string) (*bytes.Buffer, error) {
825-
cmd := exec.Command("go", args...)
826+
func (e *ProcessEnv) invokeGo(verb string, args ...string) (*bytes.Buffer, error) {
827+
goArgs := []string{verb}
828+
if verb != "env" {
829+
goArgs = append(goArgs, e.BuildFlags...)
830+
}
831+
goArgs = append(goArgs, args...)
832+
cmd := exec.Command("go", goArgs...)
826833
stdout := &bytes.Buffer{}
827834
stderr := &bytes.Buffer{}
828835
cmd.Stdout = stdout

internal/lsp/cache/view.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func (v *view) buildProcessEnv(ctx context.Context) (*imports.ProcessEnv, error)
333333
env, buildFlags := v.env()
334334
processEnv := &imports.ProcessEnv{
335335
WorkingDir: v.folder.Filename(),
336+
BuildFlags: buildFlags,
336337
Logf: func(format string, args ...interface{}) {
337338
log.Print(ctx, fmt.Sprintf(format, args...))
338339
},
@@ -359,12 +360,6 @@ func (v *view) buildProcessEnv(ctx context.Context) (*imports.ProcessEnv, error)
359360
processEnv.GOSUMDB = split[1]
360361
}
361362
}
362-
if len(buildFlags) > 0 {
363-
if processEnv.GOFLAGS != "" {
364-
processEnv.GOFLAGS += " "
365-
}
366-
processEnv.GOFLAGS += strings.Join(buildFlags, " ")
367-
}
368363
return processEnv, nil
369364
}
370365

0 commit comments

Comments
 (0)