Skip to content

Commit

Permalink
Update buildifier release; add tests for new release asset naming sch…
Browse files Browse the repository at this point in the history
…eme (#56)

* Update buildifier release; add tests for new release asset naming scheme
* Bump version
  • Loading branch information
pcj authored May 5, 2021
1 parent cc17213 commit debada5
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 8,316 deletions.
8,285 changes: 19 additions & 8,266 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bazel-stack-vscode",
"displayName": "bazel-stack-vscode",
"description": "Bazel Support for Visual Studio Code",
"version": "0.6.7",
"version": "0.7.0",
"publisher": "StackBuild",
"license": "Apache-2.0",
"icon": "stackb-full.png",
Expand Down Expand Up @@ -236,7 +236,7 @@
},
"bsv.buildifier.github-release": {
"type": "string",
"default": "3.5.0",
"default": "4.0.1",
"description": "The github release tag of the Buildifier release to download"
},
"bsv.buildifier.github-owner": {
Expand Down Expand Up @@ -1163,9 +1163,10 @@
"portfinder": "1.0.28",
"protobufjs": "6.10.1",
"request": "2.88.2",
"semver": "7.3.5",
"sha256-file": "1.0.0",
"shiki": "^0.2.6",
"shiki-themes": "^0.2.6",
"shiki": "^0.2.6",
"simple-lightbox": "2.1.0",
"slash": "3.0.0",
"strip-ansi": "^6.0.0",
Expand All @@ -1180,8 +1181,8 @@
"devDependencies": {
"@octokit/types": "5.2.0",
"@types/card-validator": "4.1.0",
"@types/chai": "4.2.12",
"@types/chai-string": "1.4.2",
"@types/chai": "4.2.12",
"@types/filesize": "5.0.0",
"@types/find-up": "4.0.0",
"@types/fs-extra": "9.0.1",
Expand All @@ -1190,9 +1191,10 @@
"@types/luxon": "1.24.3",
"@types/mocha": "^7.0.2",
"@types/mv": "2.1.0",
"@types/node": "^13.11.0",
"@types/node-fetch": "1.6.9",
"@types/node": "^13.11.0",
"@types/request": "2.48.5",
"@types/semver": "5.5.0",
"@types/sha256-file": "1.0.0",
"@types/sinon": "9.0.4",
"@types/slash": "3.0.0",
Expand All @@ -1203,8 +1205,8 @@
"@types/vscode": "^1.45.0",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"chai": "4.2.0",
"chai-string": "1.5.0",
"chai": "4.2.0",
"eslint": "^6.8.0",
"glob": "^7.1.6",
"mocha": "^7.1.2",
Expand All @@ -1213,7 +1215,7 @@
"ts-loader": "^8.0.4",
"typescript": "^3.8.3",
"vscode-test": "^1.3.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
"webpack-cli": "^3.3.12",
"webpack": "^4.44.2"
}
}
}
17 changes: 13 additions & 4 deletions src/buildifier/feature.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as fs from 'graceful-fs';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import * as semver from 'semver';
import { fail, IExtensionFeature, info } from '../common';
import { platformBinaryName } from '../constants';
import { GitHubReleaseAssetDownloader } from '../download';
import { GitHubReleaseAssetDownloader, processPlatformBinaryName, platformOsArchBinaryName, platformBinaryName } from '../download';
import { BuildifierConfiguration } from './configuration';
import { BuildifierDiagnosticsManager } from './diagnostics';
import { BuildifierFormatter } from './formatter';
Expand All @@ -22,7 +23,7 @@ export class BuildifierFeature implements IExtensionFeature {
const cfg = this.cfg = {
owner: config.get<string>('github-owner', 'bazelbuild'),
repo: config.get<string>('github-repo', 'buildtools'),
releaseTag: config.get<string>('github-release', '3.3.0'),
releaseTag: config.get<string>('github-release', '4.0.1'),
executable: config.get<string>('executable', ''),
fixOnFormat: config.get<boolean>('fix-on-format', false),
verbose: config.get<number>('verbose', 0),
Expand Down Expand Up @@ -73,7 +74,7 @@ export class BuildifierFeature implements IExtensionFeature {
*/
export async function maybeInstallBuildifier(cfg: BuildifierConfiguration, storagePath: string): Promise<string> {

const assetName = platformBinaryName('buildifier');
const assetName = versionedPlatformBinaryName(os.arch(), process.platform, 'buildifier', cfg.releaseTag);

const downloader = new GitHubReleaseAssetDownloader(
{
Expand Down Expand Up @@ -109,3 +110,11 @@ export async function maybeInstallBuildifier(cfg: BuildifierConfiguration, stora
return executable;
}

export function versionedPlatformBinaryName(arch: string, platform: string, toolName: string, version: string): string {
if (semver.gt(version, '3.5.0')) {
return platformOsArchBinaryName(arch, platform, toolName);
} else {
return platformBinaryName(platform, toolName);
}
}

15 changes: 7 additions & 8 deletions src/bzl/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import * as loader from '@grpc/proto-loader';
import * as fs from 'graceful-fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { platformBinaryName } from '../constants';
import { GitHubReleaseAssetDownloader } from '../download';
import { GitHubReleaseAssetDownloader, processPlatformBinaryName } from '../download';
import { ProtoGrpcType as AuthProtoType } from '../proto/auth';
import { AuthServiceClient } from '../proto/build/stack/auth/v1beta1/AuthService';
import { Workspace } from '../proto/build/stack/bezel/v1beta1/Workspace';
Expand Down Expand Up @@ -166,9 +165,9 @@ export async function createBzlConfiguration(
asAbsolutePath('./proto/codesearch.proto')),
livegrepProtofile: config.get<string>(ConfigSection.LivegrepProto,
asAbsolutePath('./proto/livegrep.proto')),
defaultQuery: config.get<string>(ConfigSection.CodesearchDefaultQuery,
'deps(//...)'),
};
defaultQuery: config.get<string>(ConfigSection.CodesearchDefaultQuery,
'deps(//...)'),
};

await setServerExecutable(server, storagePath);
await setServerAddresses(server);
Expand Down Expand Up @@ -358,15 +357,15 @@ export function splitLabel(label: string): LabelParts | undefined {
}

/**
* Installs buildifier from a github release. If the expected file already
* exists the download operation is skipped.
* Installs bzl from a github release. If the expected file already exists the
* download operation is skipped.
*
* @param cfg The configuration
* @param storagePath The directory where the binary should be installed
*/
export async function maybeInstallExecutable(cfg: BzlServerConfiguration, storagePath: string): Promise<string> {

const assetName = platformBinaryName(ServerBinaryName);
const assetName = processPlatformBinaryName(ServerBinaryName);

const downloader = new GitHubReleaseAssetDownloader(
{
Expand Down
14 changes: 2 additions & 12 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export enum Telemetry {
}

export enum BuiltInCommands {
SetContext = 'setContext',
SetContext = 'setContext',
ClosePanel = 'workbench.action.closePanel',
MarkdownPreview = 'markdown.showPreview',
Open = 'vscode.open',
Expand All @@ -45,15 +45,5 @@ export enum BuiltInCommands {
}

export function setCommandContext(key: string, value: any) {
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
}

export function platformBinaryName(toolName: string) {
if (process.platform === 'win32') {
return toolName + '.exe';
}
if (process.platform === 'darwin') {
return toolName + '.mac';
}
return toolName;
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
}
41 changes: 39 additions & 2 deletions src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export async function downloadAsset(url: string, filename: string, mode: number,

const tmpFile = tmp.fileSync();

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

function sha256Matches(filename: string, sha256: string): boolean {
return sha256File(filename) === sha256;
}
}

export function processPlatformBinaryName(toolName: string) {
return platformBinaryName(process.platform, toolName);
}

export function platformBinaryName(platform: string, toolName: string) {
if (platform === 'win32') {
return toolName + '.exe';
}
if (platform === 'darwin') {
return toolName + '.mac';
}
return toolName;
}

export function platformOsArchBinaryName(arch: string, platform: string, toolName: string): string {
let osName = 'linux';
let osArch = 'amd64';
let ext = '';

if (platform === 'win32') {
osName = 'windows';
ext = '.exe';
} else if (platform === 'darwin') {
osName = 'darwin';
} else {
// assume linux, try and map os.arch()
switch (arch) {
case 'arm':
case 'arm64':
osArch = 'arm64';
break;
}
}

return `${toolName}-${osName}-${osArch}${ext}`;
}
5 changes: 2 additions & 3 deletions src/starlark/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import * as fs from 'graceful-fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { fail, IExtensionFeature } from '../common';
import { platformBinaryName } from '../constants';
import { GitHubReleaseAssetDownloader } from '../download';
import { GitHubReleaseAssetDownloader, processPlatformBinaryName } from '../download';
import { StardocLSPClient } from './client';
import { createStarlarkLSPConfiguration, StarlarkLSPConfiguration } from './configuration';

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

const assetName = platformBinaryName('gostarlark');
const assetName = processPlatformBinaryName('gostarlark');

const downloader = new GitHubReleaseAssetDownloader(
{
Expand Down
90 changes: 88 additions & 2 deletions src/test/integration/feature.buildifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sinon = require('sinon');
import vscode = require('vscode');
import { expect } from 'chai';
import { BuildifierConfiguration } from '../../buildifier/configuration';
import { BuildifierFeatureName, maybeInstallBuildifier } from '../../buildifier/feature';
import { BuildifierFeatureName, maybeInstallBuildifier, versionedPlatformBinaryName } from '../../buildifier/feature';
import { BuildifierFormatter } from '../../buildifier/formatter';

suite(BuildifierFeatureName, function () {
Expand All @@ -26,7 +26,7 @@ suite(BuildifierFeatureName, function () {
const cfg: BuildifierConfiguration = {
owner: 'bazelbuild',
repo: 'buildtools',
releaseTag: '3.3.0',
releaseTag: '4.0.1',
executable: '',
fixOnFormat: true,
verbose: 0,
Expand Down Expand Up @@ -74,5 +74,91 @@ suite(BuildifierFeatureName, function () {
// supposed to be.
expect(edits[0].newText.slice(0, 18)).to.be.equal('load("@bazel_tools'); //...
});
});


suite('versionedPlatformBinaryName', function () {
interface TestCase {
name: string // test name
arch: string // os architecture
platform: string // os platform
tool: string // tool name
version: string // semver string
want: string // desired output string
}

const cases: TestCase[] = [
{
name: 'linux 3.5.0',
tool: 'buildifier',
arch: 'x64',
platform: 'linux',
version: '3.5.0',
want: 'buildifier',
},
{
name: 'linux 3.5.0 (arm64)',
tool: 'buildifier',
arch: 'arm64',
platform: 'linux',
version: '3.5.0',
want: 'buildifier',
},
{
name: 'mac 3.5.0 ',
tool: 'buildifier',
arch: 'x64',
platform: 'darwin',
version: '3.5.0',
want: 'buildifier.mac',
},
{
name: 'windows 3.5.0 ',
tool: 'buildifier',
arch: 'x64',
platform: 'win32',
version: '3.5.0',
want: 'buildifier.exe',
},
{
name: 'linux 4.0.1',
tool: 'buildifier',
arch: 'x64',
platform: 'linux',
version: '4.0.1',
want: 'buildifier-linux-amd64',
},
{
name: 'linux 4.0.1 (arm64)',
tool: 'buildifier',
arch: 'arm64',
platform: 'linux',
version: '4.0.1',
want: 'buildifier-linux-arm64',
},
{
name: 'mac 4.0.1 ',
tool: 'buildifier',
arch: 'x64',
platform: 'darwin',
version: '4.0.1',
want: 'buildifier-darwin-amd64',
},
{
name: 'windows 4.0.1 ',
tool: 'buildifier',
arch: 'x64',
platform: 'win32',
version: '4.0.1',
want: 'buildifier-windows-amd64.exe',
}

];

cases.forEach(tc => {
test(tc.name, () =>
expect(versionedPlatformBinaryName(tc.arch, tc.platform, tc.tool, tc.version)).to.eq(tc.want)
);
});
});

Loading

0 comments on commit debada5

Please sign in to comment.