Skip to content

Commit 4af2ecc

Browse files
committed
src/goInstallTools: use the 'go' command from GOROOT/bin for tool install
For tools installation, we run `go get` from a temporary directory in order to use the clean module-aware go build mode. This causes an issue in environments where the choice of go is determined by the current directory. In this change we pin the go version by using GOROOT/bin/go{.exe} instead of the go binary bin path. Note: We tried to address this issue by running the go command with a temporary -modfile in the current workspace directory. Unfortunately, that approach turned out to be more complicated than expected. And add verbose logging for the installation logic (can be enabled by '"go.logging.level": "verbose"' Fixes #757 Change-Id: I7ab792a494a38dcb6b2f6fc8891fa96af5c29380 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/263977 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
1 parent f0c87a6 commit 4af2ecc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/goInstallTools.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
GoVersion,
3939
rmdirRecursive,
4040
} from './util';
41-
import { envPath, getCurrentGoRoot, getToolFromToolPath, setCurrentGoRoot } from './utils/pathUtils';
41+
import { correctBinname, envPath, getCurrentGoRoot, getToolFromToolPath, setCurrentGoRoot } from './utils/pathUtils';
4242

4343
// declinedUpdates tracks the tools that the user has declined to update.
4444
const declinedUpdates: Tool[] = [];
@@ -200,6 +200,11 @@ export async function installTool(
200200
} else {
201201
envForTools['GO111MODULE'] = 'off';
202202
}
203+
// Some users use direnv-like setup where the choice of go is affected by
204+
// the current directory path. In order to avoid choosing a different go,
205+
// we will explicitly use `GOROOT/bin/go` instead of goVersion.binaryPath
206+
// (which can be a wrapper script that switches 'go').
207+
const goBinary = path.join(getCurrentGoRoot(), 'bin', correctBinname('go'));
203208

204209
// Build the arguments list for the tool installation.
205210
const args = ['get', '-v'];
@@ -230,8 +235,9 @@ export async function installTool(
230235
cwd: toolsTmpDir,
231236
};
232237
const execFile = util.promisify(cp.execFile);
233-
const { stdout, stderr } = await execFile(goVersion.binaryPath, args, opts);
238+
const { stdout, stderr } = await execFile(goBinary, args, opts);
234239
output = `${stdout} ${stderr}`;
240+
logVerbose(`install: %s %s\n%s%s`, goBinary, args.join(' '), stdout, stderr);
235241

236242
// TODO(rstambler): Figure out why this happens and maybe delete it.
237243
if (stderr.indexOf('unexpected directory layout:') > -1) {

0 commit comments

Comments
 (0)