Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension: customize build for tools #3254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,22 @@ Default: `"proxy"`
The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation.

Default: `""`

### `go.toolsManagement.buildFlags`

Flags to `go install` used to install the Go tools. (e.g. `["-ldflags", "-s -w"]`)

Default: `[]`
### `go.toolsManagement.buildTags`

The Go build tags used to install the Go tools.

Default: `""`
### `go.toolsManagement.envVars`

Environment variables that will be used to install the Go tools.

Default: `{}`
### `go.trace.server`

Trace the communication between VS Code and the Go language server.<br/>
Expand Down
24 changes: 24 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
"go.inferGopath",
"go.toolsGopath",
"go.toolsEnvVars",
"go.toolsManagement.buildFlags",
"go.toolsManagement.buildTags",
"go.toolsManagement.envVars",
"go.toolsManagement.go"
]
}
Expand Down Expand Up @@ -1544,6 +1547,27 @@
"description": "Automatically update the tools used by the extension, without prompting the user.",
"scope": "resource"
},
"go.toolsManagement.buildFlags": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Flags to `go install` used to install the Go tools. (e.g. [\"-ldflags\", \"-s -w\"])",
"scope": "machine-overridable"
},
"go.toolsManagement.buildTags": {
"type": "string",
"default": "",
"description": "The Go build tags used to install the Go tools.",
"scope": "machine-overridable"
},
"go.toolsManagement.envVars": {
"type": "object",
"default": {},
"description": "Environment variables that will be used to install the Go tools.",
"scope": "machine-overridable"
},
"go.enableCodeLens": {
"type": "object",
"properties": {
Expand Down
17 changes: 15 additions & 2 deletions extension/src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ async function installToolWithGo(
}
}

const env = Object.assign({}, envForTools);
const toolsBuildEnv = getGoConfig().get('toolsManagement.envVars') ?? {};
const env = Object.assign({}, envForTools, toolsBuildEnv);

let version: semver.SemVer | string | undefined | null = tool.version;
if (!version && tool.usePrereleaseInPreviewMode && extensionInfo.isPreview) {
Expand Down Expand Up @@ -291,9 +292,21 @@ async function installToolWithGoInstall(goVersion: GoVersion, env: NodeJS.Dict<s
cwd: getWorkspaceFolderPath()
};

const goConfig = getGoConfig();
const buildFlags: string[] = goConfig.get('toolsManagement.buildFlags') ?? [];
const buildTags: string = goConfig.get('toolsManagement.buildTags') ?? "";

const buildArgs: string[] = ['install', '-v'];
buildArgs.push(...buildFlags);
if (buildTags.length > 0 && buildFlags.indexOf('-tags') === -1) {
buildArgs.push('-tags');
buildArgs.push(buildTags);
}
buildArgs.push(importPath);

const execFile = util.promisify(cp.execFile);
outputChannel.trace(`$ ${goBinary} install -v ${importPath}} (cwd: ${opts.cwd})`);
await execFile(goBinary, ['install', '-v', importPath], opts);
await execFile(goBinary, buildArgs, opts);
}

export function declinedToolInstall(toolName: string) {
Expand Down