Install patched LLDB on vscode extension activation (#1637)

Download and install the WAMR patched LLDB binary on vscode extension activation.

This allows the user to download the packaged .vsix file, where the activation script
should handle determining what LLDB binary they should use, and install it in the
correct location.
This commit is contained in:
Callum Macmillan
2022-12-01 02:39:14 +00:00
committed by GitHub
parent ce3458da99
commit 6eaf779a2d
7 changed files with 202 additions and 28 deletions

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2022 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
import * as vscode from 'vscode';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
import { checkIfFileExists, downloadFile, unzipFile } from './directoryUtilities';
const LLDB_RESOURCE_DIR = "resource/debug";
const LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP: Partial<Record<NodeJS.Platform, string>> = {
"linux": "x86_64-ubuntu-22.04",
"darwin": "universal-macos-latest"
};
const WAMR_LLDB_NOT_SUPPORTED_ERROR = new Error("WAMR LLDB is not supported on this platform");
function getLLDBUnzipFilePath(destinationFolder: string, filename: string) {
const dirs = filename.split("/");
if (dirs[0] === "inst") {
dirs.shift();
}
return path.join(destinationFolder, ...dirs);
}
function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
const wamrVersion = require(path.join(context.extensionPath, "package.json")).version;
const lldbOsUrlSuffix = LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP[os.platform()];
if (!lldbOsUrlSuffix) {
throw WAMR_LLDB_NOT_SUPPORTED_ERROR;
}
return `https://github.com/bytecodealliance/wasm-micro-runtime/releases/download/WAMR-${wamrVersion}/wamr-lldb-${wamrVersion}-${lldbOsUrlSuffix}.zip`;
}
export function isLLDBInstalled(context: vscode.ExtensionContext): boolean {
const extensionPath = context.extensionPath;
const lldbOSDir = os.platform();
const lldbBinaryPath = path.join(extensionPath, LLDB_RESOURCE_DIR, lldbOSDir, "bin", "lldb");
return checkIfFileExists(lldbBinaryPath);
}
export async function promptInstallLLDB(context: vscode.ExtensionContext) {
const extensionPath = context.extensionPath;
const setupPrompt = "setup";
const skipPrompt = "skip";
const response = await vscode.window.showWarningMessage('No LLDB instance found. Setup now?', setupPrompt, skipPrompt);
if (response === skipPrompt) {
return;
}
const downloadUrl = getLLDBDownloadUrl(context);
const destinationDir = os.platform();
if (!downloadUrl) {
throw WAMR_LLDB_NOT_SUPPORTED_ERROR;
}
const lldbDestinationFolder = path.join(extensionPath, LLDB_RESOURCE_DIR, destinationDir);
const lldbZipPath = path.join(lldbDestinationFolder, "bundle.zip");
vscode.window.showInformationMessage(`Downloading LLDB...`);
await downloadFile(downloadUrl, lldbZipPath);
vscode.window.showInformationMessage(`LLDB downloaded to ${lldbZipPath}. Installing...`);
const lldbFiles = await unzipFile(lldbZipPath, filename => getLLDBUnzipFilePath(lldbDestinationFolder, filename));
// Allow execution of lldb
lldbFiles.forEach(file => fs.chmodSync(file, "0775"));
vscode.window.showInformationMessage(`LLDB installed at ${lldbDestinationFolder}`);
// Remove the bundle.zip
fs.unlink(lldbZipPath, () => {});
}