From 506cc993a9bfc7917975134ce414a3412dd83bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Zakraj=C5=A1ek?= Date: Tue, 2 May 2017 01:20:04 +0200 Subject: [PATCH] Set environment variables for go tools (#932) * Set environment variables for go tools * Fix gocheck typo --- package.json | 5 +++++ src/goCheck.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c9d7f1931..2d514cf82 100644 --- a/package.json +++ b/package.json @@ -472,6 +472,11 @@ "default": null, "description": "Flags to pass to `go test`. If null, then buildFlags will be used." }, + "go.toolsEnvVars": { + "type": "object", + "default": {}, + "description": "Environment variables that will passed to the processes that run the Go tools (e.g. CGO_CFLAGS)" + }, "go.gocodeAutoBuild": { "type": "boolean", "default": true, diff --git a/src/goCheck.ts b/src/goCheck.ts index d63ecfc54..0861360d3 100644 --- a/src/goCheck.ts +++ b/src/goCheck.ts @@ -44,11 +44,11 @@ export interface ICheckResult { * @param toolName The name of the Go tool to run. If none is provided, the go runtime itself is used * @param printUnexpectedOutput If true, then output that doesnt match expected format is printed to the output channel */ -function runTool(args: string[], cwd: string, severity: string, useStdErr: boolean, toolName: string, printUnexpectedOutput?: boolean): Promise { +function runTool(args: string[], cwd: string, severity: string, useStdErr: boolean, toolName: string, env: any, printUnexpectedOutput?: boolean): Promise { let goRuntimePath = getGoRuntimePath(); let cmd = toolName ? getBinPath(toolName) : goRuntimePath; return new Promise((resolve, reject) => { - cp.execFile(cmd, args, { cwd: cwd }, (err, stdout, stderr) => { + cp.execFile(cmd, args, { env: env, cwd: cwd }, (err, stdout, stderr) => { try { if (err && (err).code === 'ENOENT') { if (toolName) { @@ -110,6 +110,7 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration) outputChannel.clear(); let runningToolsPromises = []; let cwd = path.dirname(filename); + let env = Object.assign({}, process.env, goConfig['toolsEnvVars']); let goRuntimePath = getGoRuntimePath(); if (!goRuntimePath) { @@ -176,6 +177,7 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration) 'error', true, null, + env, true ).then(result => resolve(result), err => reject(err)); }); @@ -223,7 +225,8 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration) cwd, 'warning', false, - lintTool + lintTool, + env )); } @@ -234,7 +237,8 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration) cwd, 'warning', true, - null + null, + env )); }