forked from golang/vscode-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/goInstallTools.ts: fix PATH adjustment when a different go is chosen
With commits d93a0ae and a5e40ca (microsoft/vscode-go#3152), we tried to include the go binary's path to the PATH (Path on windows) in order to ensure all underlying go tools (gofmt, cgo, gopls, ...) that simply invoke 'go' can find the matching go binary by searching the PATH. We found that trick does not work when users specifies a different go version using go.alternateTools and the specified binary is not named 'go'. For example, golang.org provides an easy way to install extra versions of Go https://golang.org/doc/install#extra_versions through a wrapper, whose name includes the version. Users who take this approach should be able to configure to pick up the chosen version with ``` "go.alternateTools": { "go": "/Users/username/go/bin/go1.13.11" } ``` Previously, we just added /Users/username/go/bin (the go binary directory name) to PATH. Because there is no 'go' binary in this directory, the underlying tools failed to pick the right go tool. In this CL, we instead use the GOROOT (found from go env call) and add GOROOT/bin to the PATH. In this CL - We also arrange to call updateGoVarsFromConfig only when the relevant configs are changed (onDidChangeConfiguration setup in goMain.ts). Previously, this was called almost on every file save events if the repository has a workspace setting file (.vscode/setting.json). - We also changed initGoStatusBar to be called after the goroot is updated. That eliminates an extra call path (initGoStatusBar -> ... -> updateGoVarsFromConfig, and also, reflects goroot changes correctly when the configuration is updated. Updates golang#146 Updates golang#26 Change-Id: I9b0e42787308e17547067460960b5fdd8b678991 GitHub-Last-Rev: 995c1a3 GitHub-Pull-Request: golang#252 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/239697 Reviewed-by: Brayden Cloud <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
- Loading branch information
Showing
7 changed files
with
240 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Licensed under the MIT License. | ||
// See LICENSE in the project root for license information. | ||
|
||
// This is a helper used to fake a go binary. | ||
// It currently fakes `go env` and `go version` commands. | ||
// For `go env`, it returns FAKEGOROOT for 'GOROOT', and an empty string for others. | ||
// For `go version`, it returns FAKEGOVERSION or a default dev version string. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
|
||
if len(args) <= 1 { | ||
return | ||
} | ||
switch args[1] { | ||
case "env": | ||
fakeEnv(args[2:]) | ||
case "version": | ||
fakeVersion() | ||
default: | ||
fmt.Fprintf(os.Stderr, "not implemented") | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
func fakeEnv(args []string) { | ||
for _, a := range args { | ||
fmt.Println(os.Getenv("FAKE" + a)) | ||
} | ||
} | ||
|
||
func fakeVersion() { | ||
ver := os.Getenv("FAKEGOVERSION") | ||
if ver != "" { | ||
fmt.Println(ver) | ||
return | ||
} | ||
fmt.Println("go version devel +a07e2819 Thu Jun 18 20:58:26 2020 +0000 darwin/amd64") | ||
} |
Oops, something went wrong.