Skip to content

Commit

Permalink
src/goToolsInformation: fix go-outline version
Browse files Browse the repository at this point in the history
There is no v1.0.0 version.

The tagging of go-outline project doesn't follow go modules
versioning convention, so the release tag version is not
recognized.

Since we pinned the 3rd party tools versions after
https://go-review.googlesource.com/c/vscode-go/+/435375
we also need to adjust the code path that pick the version
of tools whose latest versions require go 1.18+ to build.
Use Tool.defaultVersion only if we are handling these special
cases. (gofumpt, golangci-lint, staticcheck)

Also, set GOMODCACHE explicitly when interacting with the
fake local proxy. When the test runs in an environment with
GOMODCACHE is set, the test ends up polluting the specified
GOMODCACHE with fake data from the local test proxy. Our
intention was to use GOPATH[0]/pkg/mod as module cache
during the test.

Fixes #2485
Updates #1850

Change-Id: Iad6cb662f637d444b9a8047db2aa166965144db8
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/442786
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
  • Loading branch information
hyangah committed Oct 17, 2022
1 parent 2e739cc commit 2918cb4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
10 changes: 3 additions & 7 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,8 @@ async function installToolWithGo(
importPath = getImportPath(tool, goVersion);
} else {
let version: semver.SemVer | string | undefined | null = tool.version;
if (!version) {
if (tool.usePrereleaseInPreviewMode && extensionInfo.isPreview) {
version = await latestToolVersion(tool, true);
} else if (tool.defaultVersion) {
version = tool.defaultVersion;
}
if (!version && tool.usePrereleaseInPreviewMode && extensionInfo.isPreview) {
version = await latestToolVersion(tool, true);
}
importPath = getImportPathWithVersion(tool, version, goVersion);
}
Expand Down Expand Up @@ -421,7 +417,7 @@ export async function promptForMissingTool(toolName: string) {
}
const cmd = goVersion.lt('1.16')
? `go get -v ${getImportPath(tool, goVersion)}`
: `go install -v ${getImportPathWithVersion(tool, tool.defaultVersion, goVersion)}`;
: `go install -v ${getImportPathWithVersion(tool, undefined, goVersion)}`;
const selected = await vscode.window.showErrorMessage(
`The "${tool.name}" command is not available. Run "${cmd}" to install.`,
...installOptions
Expand Down
3 changes: 3 additions & 0 deletions src/goTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export function getImportPathWithVersion(
if (tool.name === 'golangci-lint') {
if (goVersion.lt('1.18')) return importPath + '@v1.47.3';
}
if (tool.defaultVersion) {
return importPath + '@' + tool.defaultVersion;
}
return importPath + '@latest';
}

Expand Down
2 changes: 1 addition & 1 deletion src/goToolsInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const allToolsInformation: { [key: string]: Tool } = {
replacedByGopls: true,
isImportant: true,
description: 'Go to symbol in file', // GoDocumentSymbolProvider, used by 'run test' codelens
defaultVersion: 'v1.0.0'
defaultVersion: 'v0.0.0-20210608161538-9736a4bde949'
},
'go-symbols': {
name: 'go-symbols',
Expand Down
50 changes: 42 additions & 8 deletions test/integration/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ suite('Installation Tests', function () {
for (const p of [tmpToolsGopath, tmpToolsGopath2]) {
envForTest['GOPATH'] = p;
const execFile = util.promisify(cp.execFile);
await execFile(goRuntimePath, ['clean', '-modcache'], {
env: envForTest
});
rmdirRecursive(p);
try {
await execFile(goRuntimePath, ['clean', '-modcache'], {
env: envForTest
});
rmdirRecursive(p);
} catch (e) {
console.log(`failed to clean module cache directory: ${e}`);
}
}
});

// runTest actually executes the logic of the test.
// If withLocalProxy is true, the test does not require internet.
// If withGOBIN is true, the test will set GOBIN env var.
async function runTest(testCases: installationTestCase[], withLocalProxy?: boolean, withGOBIN?: boolean) {
async function runTest(
testCases: installationTestCase[],
withLocalProxy?: boolean,
withGOBIN?: boolean,
withGoVersion?: string
) {
const gobin = withLocalProxy && withGOBIN ? path.join(tmpToolsGopath, 'gobin') : undefined;

let proxyDir: string | undefined;
Expand All @@ -86,7 +95,10 @@ suite('Installation Tests', function () {
value: {
GOPROXY: url.pathToFileURL(proxyDir),
GOSUMDB: 'off',
GOBIN: gobin
GOBIN: gobin,
// Build environment may have GOMODCACHE set. Avoid writing
// fake data to it.
GOMODCACHE: path.join(tmpToolsGopath, 'pkg', 'mod')
}
},
gopath: { value: toolsGopath }
Expand All @@ -103,11 +115,15 @@ suite('Installation Tests', function () {
}

const missingTools = testCases.map((tc) => getToolAtVersion(tc.name));
const goVersion = await getGoVersion();
const goVersion = withGoVersion
? /* we want a fake go version, but need the real 'go' binary to run `go install` */
new GoVersion(getBinPath('go'), `go version ${withGoVersion} amd64/linux`)
: await getGoVersion();

sandbox.stub(vscode.commands, 'executeCommand').withArgs('go.languageserver.restart');

await installTools(missingTools, goVersion);
const failures = await installTools(missingTools, goVersion);
assert(!failures || failures.length === 0, `installTools failed: ${JSON.stringify(failures)}`);

// Confirm that each expected tool has been installed.
const checks: Promise<void>[] = [];
Expand Down Expand Up @@ -180,6 +196,24 @@ suite('Installation Tests', function () {
);
});

const gofumptDefault = allToolsInformation['gofumpt'].defaultVersion!;
test('Install gofumpt with old go', async () => {
await runTest(
[{ name: 'gofumpt', versions: ['v0.2.1', gofumptDefault], wantVersion: 'v0.2.1' }],
true, // LOCAL PROXY
true, // GOBIN
'go1.17' // Go Version
);
});

test('Install gofumpt with new go', async () => {
await runTest(
[{ name: 'gofumpt', versions: ['v0.2.1', gofumptDefault], wantVersion: gofumptDefault }],
true, // LOCAL PROXY
true, // GOBIN
'go1.18' // Go Version
);
});
test('Install all tools via GOPROXY', async () => {
// Only run this test if we are in CI before a Nightly release.
if (!shouldRunSlowTests()) {
Expand Down
2 changes: 1 addition & 1 deletion tools/allTools.ts.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const allToolsInformation: { [key: string]: Tool } = {
replacedByGopls: true,
isImportant: true,
description: 'Go to symbol in file', // GoDocumentSymbolProvider, used by 'run test' codelens
defaultVersion: 'v1.0.0'
defaultVersion: 'v0.0.0-20210608161538-9736a4bde949'
},
'go-symbols': {
name: 'go-symbols',
Expand Down

0 comments on commit 2918cb4

Please sign in to comment.