From 904b26733aad05504890e88c7c2e43042095b311 Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Mon, 27 Mar 2017 14:35:29 -0700 Subject: [PATCH] Use platform specific default for finding Go binary --- src/goInstallTools.ts | 13 +++++-------- src/goPath.ts | 6 ++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index cc4344448..40f78f869 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -227,23 +227,20 @@ export function updateGoPathGoRootFromConfig(): Promise { } } - if (process.env['GOPATH'] && process.env['GOROOT']) { + if (process.env['GOPATH']) { return Promise.resolve(); } - // If GOPATH and GOROOT are still not set, then use the ones from `go env` + // If GOPATH is still not set, then use the one from `go env` let goRuntimePath = getGoRuntimePath(); return new Promise((resolve, reject) => { - cp.execFile(goRuntimePath, ['env', 'GOROOT', 'GOPATH'], (err, stdout, stderr) => { + cp.execFile(goRuntimePath, ['env', 'GOPATH'], (err, stdout, stderr) => { if (err) { return reject(); } let envOutput = stdout.split('\n'); - if (!process.env['GOROOT'] && envOutput[0].trim()) { - process.env['GOROOT'] = envOutput[0].trim(); - } - if (!process.env['GOPATH'] && envOutput[1].trim()) { - process.env['GOPATH'] = envOutput[1].trim(); + if (!process.env['GOPATH'] && envOutput[0].trim()) { + process.env['GOPATH'] = envOutput[0].trim(); } return resolve(); }); diff --git a/src/goPath.ts b/src/goPath.ts index 4373192dd..1546ef54b 100644 --- a/src/goPath.ts +++ b/src/goPath.ts @@ -82,6 +82,12 @@ export function getGoRuntimePath(): string { let pathparts = (process.env.PATH).split(path.delimiter); runtimePathCache = pathparts.map(dir => path.join(dir, correctBinNameGo)).filter(candidate => fileExists(candidate))[0]; } + if (!runtimePathCache) { + let defaultPathForGo = process.platform === 'win32' ? 'C:\\Go\\bin\\go.exe' : '/usr/local/go/bin/go'; + if (fileExists(defaultPathForGo)) { + runtimePathCache = defaultPathForGo; + } + } return runtimePathCache; }