Skip to content

Commit 2918cb4

Browse files
committedOct 17, 2022
src/goToolsInformation: fix go-outline version
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>
1 parent 2e739cc commit 2918cb4

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed
 

‎src/goInstallTools.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,8 @@ async function installToolWithGo(
255255
importPath = getImportPath(tool, goVersion);
256256
} else {
257257
let version: semver.SemVer | string | undefined | null = tool.version;
258-
if (!version) {
259-
if (tool.usePrereleaseInPreviewMode && extensionInfo.isPreview) {
260-
version = await latestToolVersion(tool, true);
261-
} else if (tool.defaultVersion) {
262-
version = tool.defaultVersion;
263-
}
258+
if (!version && tool.usePrereleaseInPreviewMode && extensionInfo.isPreview) {
259+
version = await latestToolVersion(tool, true);
264260
}
265261
importPath = getImportPathWithVersion(tool, version, goVersion);
266262
}
@@ -421,7 +417,7 @@ export async function promptForMissingTool(toolName: string) {
421417
}
422418
const cmd = goVersion.lt('1.16')
423419
? `go get -v ${getImportPath(tool, goVersion)}`
424-
: `go install -v ${getImportPathWithVersion(tool, tool.defaultVersion, goVersion)}`;
420+
: `go install -v ${getImportPathWithVersion(tool, undefined, goVersion)}`;
425421
const selected = await vscode.window.showErrorMessage(
426422
`The "${tool.name}" command is not available. Run "${cmd}" to install.`,
427423
...installOptions

‎src/goTools.ts

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export function getImportPathWithVersion(
9595
if (tool.name === 'golangci-lint') {
9696
if (goVersion.lt('1.18')) return importPath + '@v1.47.3';
9797
}
98+
if (tool.defaultVersion) {
99+
return importPath + '@' + tool.defaultVersion;
100+
}
98101
return importPath + '@latest';
99102
}
100103

‎src/goToolsInformation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const allToolsInformation: { [key: string]: Tool } = {
3232
replacedByGopls: true,
3333
isImportant: true,
3434
description: 'Go to symbol in file', // GoDocumentSymbolProvider, used by 'run test' codelens
35-
defaultVersion: 'v1.0.0'
35+
defaultVersion: 'v0.0.0-20210608161538-9736a4bde949'
3636
},
3737
'go-symbols': {
3838
name: 'go-symbols',

‎test/integration/install.test.ts

+42-8
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,26 @@ suite('Installation Tests', function () {
6464
for (const p of [tmpToolsGopath, tmpToolsGopath2]) {
6565
envForTest['GOPATH'] = p;
6666
const execFile = util.promisify(cp.execFile);
67-
await execFile(goRuntimePath, ['clean', '-modcache'], {
68-
env: envForTest
69-
});
70-
rmdirRecursive(p);
67+
try {
68+
await execFile(goRuntimePath, ['clean', '-modcache'], {
69+
env: envForTest
70+
});
71+
rmdirRecursive(p);
72+
} catch (e) {
73+
console.log(`failed to clean module cache directory: ${e}`);
74+
}
7175
}
7276
});
7377

7478
// runTest actually executes the logic of the test.
7579
// If withLocalProxy is true, the test does not require internet.
7680
// If withGOBIN is true, the test will set GOBIN env var.
77-
async function runTest(testCases: installationTestCase[], withLocalProxy?: boolean, withGOBIN?: boolean) {
81+
async function runTest(
82+
testCases: installationTestCase[],
83+
withLocalProxy?: boolean,
84+
withGOBIN?: boolean,
85+
withGoVersion?: string
86+
) {
7887
const gobin = withLocalProxy && withGOBIN ? path.join(tmpToolsGopath, 'gobin') : undefined;
7988

8089
let proxyDir: string | undefined;
@@ -86,7 +95,10 @@ suite('Installation Tests', function () {
8695
value: {
8796
GOPROXY: url.pathToFileURL(proxyDir),
8897
GOSUMDB: 'off',
89-
GOBIN: gobin
98+
GOBIN: gobin,
99+
// Build environment may have GOMODCACHE set. Avoid writing
100+
// fake data to it.
101+
GOMODCACHE: path.join(tmpToolsGopath, 'pkg', 'mod')
90102
}
91103
},
92104
gopath: { value: toolsGopath }
@@ -103,11 +115,15 @@ suite('Installation Tests', function () {
103115
}
104116

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

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

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

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

199+
const gofumptDefault = allToolsInformation['gofumpt'].defaultVersion!;
200+
test('Install gofumpt with old go', async () => {
201+
await runTest(
202+
[{ name: 'gofumpt', versions: ['v0.2.1', gofumptDefault], wantVersion: 'v0.2.1' }],
203+
true, // LOCAL PROXY
204+
true, // GOBIN
205+
'go1.17' // Go Version
206+
);
207+
});
208+
209+
test('Install gofumpt with new go', async () => {
210+
await runTest(
211+
[{ name: 'gofumpt', versions: ['v0.2.1', gofumptDefault], wantVersion: gofumptDefault }],
212+
true, // LOCAL PROXY
213+
true, // GOBIN
214+
'go1.18' // Go Version
215+
);
216+
});
183217
test('Install all tools via GOPROXY', async () => {
184218
// Only run this test if we are in CI before a Nightly release.
185219
if (!shouldRunSlowTests()) {

‎tools/allTools.ts.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const allToolsInformation: { [key: string]: Tool } = {
3030
replacedByGopls: true,
3131
isImportant: true,
3232
description: 'Go to symbol in file', // GoDocumentSymbolProvider, used by 'run test' codelens
33-
defaultVersion: 'v1.0.0'
33+
defaultVersion: 'v0.0.0-20210608161538-9736a4bde949'
3434
},
3535
'go-symbols': {
3636
name: 'go-symbols',

0 commit comments

Comments
 (0)
Please sign in to comment.