Skip to content

Commit

Permalink
check offline/insiders VSIX (#5341)
Browse files Browse the repository at this point in the history
* check offline/insiders VSIX

* draft

* add offline url, modify warning message

* check offline/insiders VSIX

* draft

* add offline url, modify warning message

* modify warning message

* fix reviewers comments

* changing the approach to determine the platform

* fixing the integration test

* testing

Co-authored-by: Elaheh Rashedi <[email protected]>
Co-authored-by: Bob Brown <[email protected]>
  • Loading branch information
3 people authored Apr 28, 2020
1 parent 118bed1 commit 4216aa4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
14 changes: 14 additions & 0 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,20 @@ export function checkInstallLockFile(): Promise<boolean> {
return checkFileExists(getInstallLockPath());
}

/** Get the platform that the installed binaries belong to.*/
export function getInstalledBinaryPlatform(): string | undefined {
// the LLVM/bin folder is utilized to identify the platform
let installedPlatform: string = "";
if (checkFileExistsSync(path.join(extensionPath, "LLVM/bin/clang-format.exe"))) {
installedPlatform = "win32";
} else if (checkFileExistsSync(path.join(extensionPath, "LLVM/bin/clang-format.darwin"))) {
installedPlatform = "darwin";
} else if (checkFileExistsSync(path.join(extensionPath, "LLVM/bin/clang-format"))) {
installedPlatform = "linux";
}
return installedPlatform;
}

/** Reads the content of a text file */
export function readFileText(filePath: string, encoding: string = "utf8"): Promise<string> {
return new Promise<string>((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions Extension/src/githubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as vscode from 'vscode';
import * as telemetry from './telemetry';

const testingInsidersVsixInstall: boolean = false; // Change this to true to enable testing of the Insiders vsix installation.

export const releaseDownloadUrl: string = "https://github.com/microsoft/vscode-cpptools/releases";
/**
* The object representation of a Build Asset. Each Asset corresponds to information about a release file on GitHub.
*/
Expand Down Expand Up @@ -96,7 +96,7 @@ function isArrayOfBuilds(input: any): input is Build[] {
* @param info Information about the user's operating system.
* @return VSIX filename for the extension's releases matched to the user's platform.
*/
function vsixNameForPlatform(info: PlatformInformation): string {
export function vsixNameForPlatform(info: PlatformInformation): string {
const vsixName: string | undefined = function(platformInfo): string | undefined {
switch (platformInfo.platform) {
case 'win32': return 'cpptools-win32.vsix';
Expand Down
19 changes: 17 additions & 2 deletions Extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import { PersistentState } from './LanguageServer/persistentState';

import { CppToolsApi, CppToolsExtension } from 'vscode-cpptools';
import { getTemporaryCommandRegistrarInstance, initializeTemporaryCommandRegistrar } from './commands';
import { PlatformInformation } from './platform';
import { PlatformInformation, GetOSName } from './platform';
import { PackageManager, PackageManagerError, IPackage, VersionsMatch, ArchitecturesMatch, PlatformsMatch } from './packageManager';
import { getInstallationInformation, InstallationInformation, setInstallationStage, setInstallationType, InstallationType } from './installationInformation';
import { Logger, getOutputChannelLogger, showOutputChannel } from './logger';
import { CppTools1, NullCppTools } from './cppTools1';
import { CppSettings } from './LanguageServer/settings';
import { vsixNameForPlatform, releaseDownloadUrl } from './githubAPI';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand All @@ -49,6 +50,20 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
Telemetry.activate();
util.setProgress(0);

// check if the correct offline/insiders vsix is installed on the correct platform
let installedPlatform: string | undefined = util.getInstalledBinaryPlatform();
if (!installedPlatform || (process.platform !== installedPlatform)) {
const platformInfo: PlatformInformation = await PlatformInformation.GetPlatformInformation();
const vsixName: string = vsixNameForPlatform(platformInfo);
errMsg = localize("native.binaries.not.supported", "This {0} version of the extension is incompatible with your OS. Please download and install the \"{1}\" version of the extension.", GetOSName(installedPlatform), vsixName);
const downloadLink: string = localize("download.button", "Go to Download Page");
vscode.window.showErrorMessage(errMsg, downloadLink).then(async (selection) => {
if (selection === downloadLink) {
vscode.env.openExternal(vscode.Uri.parse(releaseDownloadUrl));
}
});
}

// Register a protocol handler to serve localized versions of the schema for c_cpp_properties.json
class SchemaProvider implements vscode.TextDocumentContentProvider {
public async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
Expand Down Expand Up @@ -317,7 +332,7 @@ function handleError(error: any): void {
outputChannelLogger.appendLine(localize('failed.at.stage', "Failed at stage: {0}", installationInformation.stage));
outputChannelLogger.appendLine(errorMessage);
outputChannelLogger.appendLine("");
outputChannelLogger.appendLine(localize('failed.at.stage2', 'If you work in an offline environment or repeatedly see this error, try downloading a version of the extension with all the dependencies pre-included from https://github.com/Microsoft/vscode-cpptools/releases, then use the "Install from VSIX" command in VS Code to install it.'));
outputChannelLogger.appendLine(localize('failed.at.stage2', 'If you work in an offline environment or repeatedly see this error, try downloading a version of the extension with all the dependencies pre-included from {0}, then use the "Install from VSIX" command in VS Code to install it.', releaseDownloadUrl));
showOutputChannel();
}

Expand Down
9 changes: 9 additions & 0 deletions Extension/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import * as nls from 'vscode-nls';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();

export function GetOSName(processPlatform: string | undefined): string | undefined {
switch (processPlatform) {
case "win32": return "Windows";
case "darwin": return "MacOS";
case "linux": return "Linux";
default: return undefined;
}
}

export class PlatformInformation {
constructor(public platform: string, public architecture?: string, public distribution?: LinuxDistribution, public version?: string) { }

Expand Down

0 comments on commit 4216aa4

Please sign in to comment.