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 golang/vscode-go#757

Change-Id: I7ab792a494a38dcb6b2f6fc8891fa96af5c29380
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/263977
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts
index e250a45..d0e179c 100644
--- a/src/goInstallTools.ts
+++ b/src/goInstallTools.ts
@@ -38,7 +38,7 @@
 	GoVersion,
 	rmdirRecursive,
 } from './util';
-import { envPath, getCurrentGoRoot, getToolFromToolPath, setCurrentGoRoot } from './utils/pathUtils';
+import { correctBinname, envPath, getCurrentGoRoot, getToolFromToolPath, setCurrentGoRoot } from './utils/pathUtils';
 
 // declinedUpdates tracks the tools that the user has declined to update.
 const declinedUpdates: Tool[] = [];
@@ -200,6 +200,11 @@
 	} else {
 		envForTools['GO111MODULE'] = 'off';
 	}
+	// Some users use direnv-like setup where the choice of go is affected by
+	// the current directory path. In order to avoid choosing a different go,
+	// we will explicitly use `GOROOT/bin/go` instead of goVersion.binaryPath
+	// (which can be a wrapper script that switches 'go').
+	const goBinary = path.join(getCurrentGoRoot(), 'bin', correctBinname('go'));
 
 	// Build the arguments list for the tool installation.
 	const args = ['get', '-v'];
@@ -230,8 +235,9 @@
 			cwd: toolsTmpDir,
 		};
 		const execFile = util.promisify(cp.execFile);
-		const { stdout, stderr } = await execFile(goVersion.binaryPath, args, opts);
+		const { stdout, stderr } = await execFile(goBinary, args, opts);
 		output = `${stdout} ${stderr}`;
+		logVerbose(`install: %s %s\n%s%s`, goBinary, args.join(' '), stdout, stderr);
 
 		// TODO(rstambler): Figure out why this happens and maybe delete it.
 		if (stderr.indexOf('unexpected directory layout:') > -1) {