Skip to content

Commit debada5

Browse files
authored
Update buildifier release; add tests for new release asset naming scheme (#56)
* Update buildifier release; add tests for new release asset naming scheme * Bump version
1 parent cc17213 commit debada5

File tree

10 files changed

+277
-8316
lines changed

10 files changed

+277
-8316
lines changed

package-lock.json

Lines changed: 19 additions & 8266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "bazel-stack-vscode",
33
"displayName": "bazel-stack-vscode",
44
"description": "Bazel Support for Visual Studio Code",
5-
"version": "0.6.7",
5+
"version": "0.7.0",
66
"publisher": "StackBuild",
77
"license": "Apache-2.0",
88
"icon": "stackb-full.png",
@@ -236,7 +236,7 @@
236236
},
237237
"bsv.buildifier.github-release": {
238238
"type": "string",
239-
"default": "3.5.0",
239+
"default": "4.0.1",
240240
"description": "The github release tag of the Buildifier release to download"
241241
},
242242
"bsv.buildifier.github-owner": {
@@ -1163,9 +1163,10 @@
11631163
"portfinder": "1.0.28",
11641164
"protobufjs": "6.10.1",
11651165
"request": "2.88.2",
1166+
"semver": "7.3.5",
11661167
"sha256-file": "1.0.0",
1167-
"shiki": "^0.2.6",
11681168
"shiki-themes": "^0.2.6",
1169+
"shiki": "^0.2.6",
11691170
"simple-lightbox": "2.1.0",
11701171
"slash": "3.0.0",
11711172
"strip-ansi": "^6.0.0",
@@ -1180,8 +1181,8 @@
11801181
"devDependencies": {
11811182
"@octokit/types": "5.2.0",
11821183
"@types/card-validator": "4.1.0",
1183-
"@types/chai": "4.2.12",
11841184
"@types/chai-string": "1.4.2",
1185+
"@types/chai": "4.2.12",
11851186
"@types/filesize": "5.0.0",
11861187
"@types/find-up": "4.0.0",
11871188
"@types/fs-extra": "9.0.1",
@@ -1190,9 +1191,10 @@
11901191
"@types/luxon": "1.24.3",
11911192
"@types/mocha": "^7.0.2",
11921193
"@types/mv": "2.1.0",
1193-
"@types/node": "^13.11.0",
11941194
"@types/node-fetch": "1.6.9",
1195+
"@types/node": "^13.11.0",
11951196
"@types/request": "2.48.5",
1197+
"@types/semver": "5.5.0",
11961198
"@types/sha256-file": "1.0.0",
11971199
"@types/sinon": "9.0.4",
11981200
"@types/slash": "3.0.0",
@@ -1203,8 +1205,8 @@
12031205
"@types/vscode": "^1.45.0",
12041206
"@typescript-eslint/eslint-plugin": "^2.30.0",
12051207
"@typescript-eslint/parser": "^2.30.0",
1206-
"chai": "4.2.0",
12071208
"chai-string": "1.5.0",
1209+
"chai": "4.2.0",
12081210
"eslint": "^6.8.0",
12091211
"glob": "^7.1.6",
12101212
"mocha": "^7.1.2",
@@ -1213,7 +1215,7 @@
12131215
"ts-loader": "^8.0.4",
12141216
"typescript": "^3.8.3",
12151217
"vscode-test": "^1.3.0",
1216-
"webpack": "^4.44.2",
1217-
"webpack-cli": "^3.3.12"
1218+
"webpack-cli": "^3.3.12",
1219+
"webpack": "^4.44.2"
12181220
}
1219-
}
1221+
}

src/buildifier/feature.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as fs from 'graceful-fs';
2+
import * as os from 'os';
23
import * as path from 'path';
34
import * as vscode from 'vscode';
5+
import * as semver from 'semver';
46
import { fail, IExtensionFeature, info } from '../common';
5-
import { platformBinaryName } from '../constants';
6-
import { GitHubReleaseAssetDownloader } from '../download';
7+
import { GitHubReleaseAssetDownloader, processPlatformBinaryName, platformOsArchBinaryName, platformBinaryName } from '../download';
78
import { BuildifierConfiguration } from './configuration';
89
import { BuildifierDiagnosticsManager } from './diagnostics';
910
import { BuildifierFormatter } from './formatter';
@@ -22,7 +23,7 @@ export class BuildifierFeature implements IExtensionFeature {
2223
const cfg = this.cfg = {
2324
owner: config.get<string>('github-owner', 'bazelbuild'),
2425
repo: config.get<string>('github-repo', 'buildtools'),
25-
releaseTag: config.get<string>('github-release', '3.3.0'),
26+
releaseTag: config.get<string>('github-release', '4.0.1'),
2627
executable: config.get<string>('executable', ''),
2728
fixOnFormat: config.get<boolean>('fix-on-format', false),
2829
verbose: config.get<number>('verbose', 0),
@@ -73,7 +74,7 @@ export class BuildifierFeature implements IExtensionFeature {
7374
*/
7475
export async function maybeInstallBuildifier(cfg: BuildifierConfiguration, storagePath: string): Promise<string> {
7576

76-
const assetName = platformBinaryName('buildifier');
77+
const assetName = versionedPlatformBinaryName(os.arch(), process.platform, 'buildifier', cfg.releaseTag);
7778

7879
const downloader = new GitHubReleaseAssetDownloader(
7980
{
@@ -109,3 +110,11 @@ export async function maybeInstallBuildifier(cfg: BuildifierConfiguration, stora
109110
return executable;
110111
}
111112

113+
export function versionedPlatformBinaryName(arch: string, platform: string, toolName: string, version: string): string {
114+
if (semver.gt(version, '3.5.0')) {
115+
return platformOsArchBinaryName(arch, platform, toolName);
116+
} else {
117+
return platformBinaryName(platform, toolName);
118+
}
119+
}
120+

src/bzl/configuration.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import * as loader from '@grpc/proto-loader';
33
import * as fs from 'graceful-fs';
44
import * as path from 'path';
55
import * as vscode from 'vscode';
6-
import { platformBinaryName } from '../constants';
7-
import { GitHubReleaseAssetDownloader } from '../download';
6+
import { GitHubReleaseAssetDownloader, processPlatformBinaryName } from '../download';
87
import { ProtoGrpcType as AuthProtoType } from '../proto/auth';
98
import { AuthServiceClient } from '../proto/build/stack/auth/v1beta1/AuthService';
109
import { Workspace } from '../proto/build/stack/bezel/v1beta1/Workspace';
@@ -166,9 +165,9 @@ export async function createBzlConfiguration(
166165
asAbsolutePath('./proto/codesearch.proto')),
167166
livegrepProtofile: config.get<string>(ConfigSection.LivegrepProto,
168167
asAbsolutePath('./proto/livegrep.proto')),
169-
defaultQuery: config.get<string>(ConfigSection.CodesearchDefaultQuery,
170-
'deps(//...)'),
171-
};
168+
defaultQuery: config.get<string>(ConfigSection.CodesearchDefaultQuery,
169+
'deps(//...)'),
170+
};
172171

173172
await setServerExecutable(server, storagePath);
174173
await setServerAddresses(server);
@@ -358,15 +357,15 @@ export function splitLabel(label: string): LabelParts | undefined {
358357
}
359358

360359
/**
361-
* Installs buildifier from a github release. If the expected file already
362-
* exists the download operation is skipped.
360+
* Installs bzl from a github release. If the expected file already exists the
361+
* download operation is skipped.
363362
*
364363
* @param cfg The configuration
365364
* @param storagePath The directory where the binary should be installed
366365
*/
367366
export async function maybeInstallExecutable(cfg: BzlServerConfiguration, storagePath: string): Promise<string> {
368367

369-
const assetName = platformBinaryName(ServerBinaryName);
368+
const assetName = processPlatformBinaryName(ServerBinaryName);
370369

371370
const downloader = new GitHubReleaseAssetDownloader(
372371
{

src/constants.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export enum Telemetry {
3535
}
3636

3737
export enum BuiltInCommands {
38-
SetContext = 'setContext',
38+
SetContext = 'setContext',
3939
ClosePanel = 'workbench.action.closePanel',
4040
MarkdownPreview = 'markdown.showPreview',
4141
Open = 'vscode.open',
@@ -45,15 +45,5 @@ export enum BuiltInCommands {
4545
}
4646

4747
export function setCommandContext(key: string, value: any) {
48-
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
49-
}
50-
51-
export function platformBinaryName(toolName: string) {
52-
if (process.platform === 'win32') {
53-
return toolName + '.exe';
54-
}
55-
if (process.platform === 'darwin') {
56-
return toolName + '.mac';
57-
}
58-
return toolName;
48+
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
5949
}

src/download.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export async function downloadAsset(url: string, filename: string, mode: number,
237237

238238
const tmpFile = tmp.fileSync();
239239

240-
return new Promise((resolve, reject) => {
240+
return new Promise<void>((resolve, reject) => {
241241
const headers: request.Headers = {
242242
Accept: 'application/octet-stream',
243243
'User-Agent': 'bazel-stack-vscode',
@@ -293,4 +293,41 @@ function getGithubToken(): string | undefined {
293293

294294
function sha256Matches(filename: string, sha256: string): boolean {
295295
return sha256File(filename) === sha256;
296-
}
296+
}
297+
298+
export function processPlatformBinaryName(toolName: string) {
299+
return platformBinaryName(process.platform, toolName);
300+
}
301+
302+
export function platformBinaryName(platform: string, toolName: string) {
303+
if (platform === 'win32') {
304+
return toolName + '.exe';
305+
}
306+
if (platform === 'darwin') {
307+
return toolName + '.mac';
308+
}
309+
return toolName;
310+
}
311+
312+
export function platformOsArchBinaryName(arch: string, platform: string, toolName: string): string {
313+
let osName = 'linux';
314+
let osArch = 'amd64';
315+
let ext = '';
316+
317+
if (platform === 'win32') {
318+
osName = 'windows';
319+
ext = '.exe';
320+
} else if (platform === 'darwin') {
321+
osName = 'darwin';
322+
} else {
323+
// assume linux, try and map os.arch()
324+
switch (arch) {
325+
case 'arm':
326+
case 'arm64':
327+
osArch = 'arm64';
328+
break;
329+
}
330+
}
331+
332+
return `${toolName}-${osName}-${osArch}${ext}`;
333+
}

src/starlark/feature.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as fs from 'graceful-fs';
22
import * as path from 'path';
33
import * as vscode from 'vscode';
44
import { fail, IExtensionFeature } from '../common';
5-
import { platformBinaryName } from '../constants';
6-
import { GitHubReleaseAssetDownloader } from '../download';
5+
import { GitHubReleaseAssetDownloader, processPlatformBinaryName } from '../download';
76
import { StardocLSPClient } from './client';
87
import { createStarlarkLSPConfiguration, StarlarkLSPConfiguration } from './configuration';
98

@@ -86,7 +85,7 @@ export class StarlarkLSPFeature implements IExtensionFeature {
8685
*/
8786
export async function maybeInstallExecutable(cfg: StarlarkLSPConfiguration, storagePath: string): Promise<string> {
8887

89-
const assetName = platformBinaryName('gostarlark');
88+
const assetName = processPlatformBinaryName('gostarlark');
9089

9190
const downloader = new GitHubReleaseAssetDownloader(
9291
{

src/test/integration/feature.buildifier.test.ts

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import sinon = require('sinon');
77
import vscode = require('vscode');
88
import { expect } from 'chai';
99
import { BuildifierConfiguration } from '../../buildifier/configuration';
10-
import { BuildifierFeatureName, maybeInstallBuildifier } from '../../buildifier/feature';
10+
import { BuildifierFeatureName, maybeInstallBuildifier, versionedPlatformBinaryName } from '../../buildifier/feature';
1111
import { BuildifierFormatter } from '../../buildifier/formatter';
1212

1313
suite(BuildifierFeatureName, function () {
@@ -26,7 +26,7 @@ suite(BuildifierFeatureName, function () {
2626
const cfg: BuildifierConfiguration = {
2727
owner: 'bazelbuild',
2828
repo: 'buildtools',
29-
releaseTag: '3.3.0',
29+
releaseTag: '4.0.1',
3030
executable: '',
3131
fixOnFormat: true,
3232
verbose: 0,
@@ -74,5 +74,91 @@ suite(BuildifierFeatureName, function () {
7474
// supposed to be.
7575
expect(edits[0].newText.slice(0, 18)).to.be.equal('load("@bazel_tools'); //...
7676
});
77+
});
78+
79+
80+
suite('versionedPlatformBinaryName', function () {
81+
interface TestCase {
82+
name: string // test name
83+
arch: string // os architecture
84+
platform: string // os platform
85+
tool: string // tool name
86+
version: string // semver string
87+
want: string // desired output string
88+
}
89+
90+
const cases: TestCase[] = [
91+
{
92+
name: 'linux 3.5.0',
93+
tool: 'buildifier',
94+
arch: 'x64',
95+
platform: 'linux',
96+
version: '3.5.0',
97+
want: 'buildifier',
98+
},
99+
{
100+
name: 'linux 3.5.0 (arm64)',
101+
tool: 'buildifier',
102+
arch: 'arm64',
103+
platform: 'linux',
104+
version: '3.5.0',
105+
want: 'buildifier',
106+
},
107+
{
108+
name: 'mac 3.5.0 ',
109+
tool: 'buildifier',
110+
arch: 'x64',
111+
platform: 'darwin',
112+
version: '3.5.0',
113+
want: 'buildifier.mac',
114+
},
115+
{
116+
name: 'windows 3.5.0 ',
117+
tool: 'buildifier',
118+
arch: 'x64',
119+
platform: 'win32',
120+
version: '3.5.0',
121+
want: 'buildifier.exe',
122+
},
123+
{
124+
name: 'linux 4.0.1',
125+
tool: 'buildifier',
126+
arch: 'x64',
127+
platform: 'linux',
128+
version: '4.0.1',
129+
want: 'buildifier-linux-amd64',
130+
},
131+
{
132+
name: 'linux 4.0.1 (arm64)',
133+
tool: 'buildifier',
134+
arch: 'arm64',
135+
platform: 'linux',
136+
version: '4.0.1',
137+
want: 'buildifier-linux-arm64',
138+
},
139+
{
140+
name: 'mac 4.0.1 ',
141+
tool: 'buildifier',
142+
arch: 'x64',
143+
platform: 'darwin',
144+
version: '4.0.1',
145+
want: 'buildifier-darwin-amd64',
146+
},
147+
{
148+
name: 'windows 4.0.1 ',
149+
tool: 'buildifier',
150+
arch: 'x64',
151+
platform: 'win32',
152+
version: '4.0.1',
153+
want: 'buildifier-windows-amd64.exe',
154+
}
77155

156+
];
157+
158+
cases.forEach(tc => {
159+
test(tc.name, () =>
160+
expect(versionedPlatformBinaryName(tc.arch, tc.platform, tc.tool, tc.version)).to.eq(tc.want)
161+
);
162+
});
78163
});
164+

0 commit comments

Comments
 (0)