Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Set environment variables for go tools (#932)
Browse files Browse the repository at this point in the history
* Set environment variables for go tools

* Fix gocheck typo
  • Loading branch information
bancek authored and ramya-rao-a committed May 1, 2017
1 parent 8962e4b commit 506cc99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICheckResult[]> {
function runTool(args: string[], cwd: string, severity: string, useStdErr: boolean, toolName: string, env: any, printUnexpectedOutput?: boolean): Promise<ICheckResult[]> {
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 && (<any>err).code === 'ENOENT') {
if (toolName) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -176,6 +177,7 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)
'error',
true,
null,
env,
true
).then(result => resolve(result), err => reject(err));
});
Expand Down Expand Up @@ -223,7 +225,8 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)
cwd,
'warning',
false,
lintTool
lintTool,
env
));
}

Expand All @@ -234,7 +237,8 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)
cwd,
'warning',
true,
null
null,
env
));
}

Expand Down

0 comments on commit 506cc99

Please # to comment.