Explorar el Código

vscode-extension: Run docker image with the same version as WAMR (#1815)

TianlongLiang hace 3 años
padre
commit
fe210f02f2

+ 1 - 1
test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.bat

@@ -6,5 +6,5 @@
 docker run --rm -it --name=wasm-debug-server-ctr ^
            -v "%cd%":/mnt ^
            -p 1234:1234 ^
-           wasm-debug-server:1.0 ^
+           wasm-debug-server:%2 ^
            /bin/bash -c "./debug.sh %1"

+ 1 - 1
test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.sh

@@ -8,5 +8,5 @@ set -e
 docker run --rm -it --name=wasm-debug-server-ctr \
            -v "$(pwd)":/mnt \
            -p 1234:1234 \
-           wasm-debug-server:1.0 \
+           wasm-debug-server:$2 \
            /bin/bash -c "./debug.sh $1"

+ 1 - 1
test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.bat

@@ -7,5 +7,5 @@
 docker run --rm --name=wasm-toolchain-ctr ^
                 -it -v "%cd%":/mnt ^
                 --env=PROJ_PATH="%cd%" ^
-                wasm-toolchain:1.0  ^
+                wasm-toolchain:%2  ^
                 /bin/bash -c "./build_wasm.sh %1"

+ 1 - 1
test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.sh

@@ -8,5 +8,5 @@ set -e
 docker run --rm --name=wasm-toolchain-ctr \
                 -it -v "$(pwd)":/mnt \
                 --env=PROJ_PATH="$(pwd)" \
-                wasm-toolchain:1.0  \
+                wasm-toolchain:$2  \
                 /bin/bash -c "./build_wasm.sh $1"

+ 1 - 1
test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.bat

@@ -5,5 +5,5 @@
 
 docker run --rm -it --name=wasm-debug-server-ctr ^
            -v "%cd%":/mnt ^
-           wasm-debug-server:1.0 ^
+           wasm-debug-server:%2 ^
            /bin/bash -c "./run.sh %1"

+ 1 - 1
test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.sh

@@ -7,5 +7,5 @@ set -e
 
 docker run --rm -it --name=wasm-debug-server-ctr \
            -v "$(pwd)":/mnt \
-           wasm-debug-server:1.0 \
+           wasm-debug-server:$2 \
            /bin/bash -c "./run.sh $1"

+ 10 - 3
test-tools/wamr-ide/VSCode-Extension/src/extension.ts

@@ -18,7 +18,11 @@ import {
 } from './utilities/directoryUtilities';
 import { decorationProvider } from './decorationProvider';
 import { WasmDebugConfigurationProvider } from './debugConfigurationProvider';
-import { isLLDBInstalled, promptInstallLLDB } from './utilities/lldbUtilities';
+import {
+    isLLDBInstalled,
+    promptInstallLLDB,
+    getWAMRExtensionVersion,
+} from './utilities/lldbUtilities';
 
 let wasmTaskProvider: WasmTaskProvider;
 let wasmDebugConfigProvider: WasmDebugConfigurationProvider;
@@ -43,6 +47,8 @@ export async function activate(context: vscode.ExtensionContext) {
         excludeFileArr = new Array(),
         scriptMap = new Map();
 
+    const wamrVersion = getWAMRExtensionVersion(context);
+
     /**
      * Get OS platform information for differ windows and linux execution script
      */
@@ -83,7 +89,7 @@ export async function activate(context: vscode.ExtensionContext) {
     typeMap.set('Debug', 'Debug');
     typeMap.set('Destroy', 'Destroy');
 
-    wasmTaskProvider = new WasmTaskProvider(typeMap, scriptMap);
+    wasmTaskProvider = new WasmTaskProvider(typeMap, scriptMap, wamrVersion);
 
     vscode.tasks.registerTaskProvider('wasm', wasmTaskProvider);
 
@@ -670,7 +676,8 @@ export async function activate(context: vscode.ExtensionContext) {
                                 let _path = curWorkspace.concat(
                                     OS_PLATFORM === 'win32'
                                         ? '\\'
-                                        : OS_PLATFORM === 'linux' || OS_PLATFORM === 'darwin'
+                                        : OS_PLATFORM === 'linux' ||
+                                          OS_PLATFORM === 'darwin'
                                         ? '/'
                                         : '',
                                     option

+ 10 - 5
test-tools/wamr-ide/VSCode-Extension/src/taskProvider.ts

@@ -15,7 +15,8 @@ export interface OwnShellOption {
 export class WasmTaskProvider implements vscode.TaskProvider {
     constructor(
         public _type: Map<string, string>,
-        public _script: Map<string, string>
+        public _script: Map<string, string>,
+        public _wamrVersion: string
     ) {}
 
     buildShellOption: OwnShellOption | undefined;
@@ -31,7 +32,11 @@ export class WasmTaskProvider implements vscode.TaskProvider {
             let targetName =
                 TargetConfigPanel.BUILD_ARGS.output_file_name.split('.')[0];
 
-            if (os.platform() === 'linux' || os.platform() === 'darwin' || os.platform() === 'win32') {
+            if (
+                os.platform() === 'linux' ||
+                os.platform() === 'darwin' ||
+                os.platform() === 'win32'
+            ) {
                 /* build */
                 this.buildShellOption = {
                     cmd:
@@ -40,7 +45,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
                             : (this._script.get('buildScript') as string),
                     options: {
                         executable: this._script.get('buildScript'),
-                        shellArgs: [targetName, os.platform()],
+                        shellArgs: [targetName, this._wamrVersion],
                     },
                 };
 
@@ -52,7 +57,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
                             : (this._script.get('debugScript') as string),
                     options: {
                         executable: this._script.get('debugScript'),
-                        shellArgs: [targetName],
+                        shellArgs: [targetName, this._wamrVersion],
                     },
                 };
 
@@ -64,7 +69,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
                             : (this._script.get('runScript') as string),
                     options: {
                         executable: this._script.get('runScript'),
-                        shellArgs: [targetName],
+                        shellArgs: [targetName, this._wamrVersion],
                     },
                 };
 

+ 53 - 33
test-tools/wamr-ide/VSCode-Extension/src/utilities/directoryUtilities.ts

@@ -137,53 +137,73 @@ export function checkFolderName(folderName: string) {
     return valid;
 }
 
-export function downloadFile(url: string, destinationPath: string): Promise<void> {
+export function downloadFile(
+    url: string,
+    destinationPath: string
+): Promise<void> {
     return new Promise((resolve, reject) => {
         const file = fileSystem.createWriteStream(destinationPath);
         const stream = request(url, undefined, (error, response, body) => {
             if (response.statusCode !== 200) {
-                reject(new Error(`Download from ${url} failed with ${response.statusMessage}`));
+                reject(
+                    new Error(
+                        `Download from ${url} failed with ${response.statusMessage}`
+                    )
+                );
             }
         }).pipe(file);
-        stream.on("close", resolve);
-        stream.on("error", reject);
+        stream.on('close', resolve);
+        stream.on('error', reject);
     });
 }
 
-export function unzipFile(sourcePath: string, getDestinationFileName: (entryName: string) => string): Promise<string[]> {
+export function unzipFile(
+    sourcePath: string,
+    getDestinationFileName: (entryName: string) => string
+): Promise<string[]> {
     return new Promise((resolve, reject) => {
         const unzippedFilePaths: string[] = [];
-        yauzl.open(sourcePath, { lazyEntries: true }, function(error, zipfile) {
-            if (error) {
-                reject(error);
-                return;
-            }
-            zipfile.readEntry();
-            zipfile.on("entry", function(entry) {
-                // This entry is a directory so skip it
-                if (/\/$/.test(entry.fileName)) {
-                    zipfile.readEntry();
+        yauzl.open(
+            sourcePath,
+            { lazyEntries: true },
+            function (error, zipfile) {
+                if (error) {
+                    reject(error);
                     return;
-                } 
-
-                zipfile.openReadStream(entry, function(error, readStream) {
-                    if (error) {
-                        reject(error);
+                }
+                zipfile.readEntry();
+                zipfile.on('entry', function (entry) {
+                    // This entry is a directory so skip it
+                    if (/\/$/.test(entry.fileName)) {
+                        zipfile.readEntry();
                         return;
                     }
-                    readStream.on("end", () => zipfile.readEntry());
-                    const destinationFileName = getDestinationFileName(entry.fileName);
-                    fileSystem.mkdirSync(path.dirname(destinationFileName), { recursive: true });
 
-                    const file = fileSystem.createWriteStream(destinationFileName);
-                    readStream.pipe(file).on("error", reject);
-                    unzippedFilePaths.push(destinationFileName);
+                    zipfile.openReadStream(entry, function (error, readStream) {
+                        if (error) {
+                            reject(error);
+                            return;
+                        }
+                        readStream.on('end', () => zipfile.readEntry());
+                        const destinationFileName = getDestinationFileName(
+                            entry.fileName
+                        );
+                        fileSystem.mkdirSync(
+                            path.dirname(destinationFileName),
+                            { recursive: true }
+                        );
+
+                        const file =
+                            fileSystem.createWriteStream(destinationFileName);
+                        readStream.pipe(file).on('error', reject);
+                        unzippedFilePaths.push(destinationFileName);
+                    });
+                });
+                zipfile.on('end', function () {
+                    zipfile.close();
+                    resolve(unzippedFilePaths);
                 });
-            });
-            zipfile.on("end", function() {
-                zipfile.close();
-                resolve(unzippedFilePaths);
-            });
-        });
+            }
+        );
     });
-} 
+}

+ 54 - 22
test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts

@@ -7,27 +7,41 @@ 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"
+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");
+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") {
+    const dirs = filename.split('/');
+    if (dirs[0] === 'inst') {
         dirs.shift();
     }
 
     return path.join(destinationFolder, ...dirs);
 }
 
+export function getWAMRExtensionVersion(
+    context: vscode.ExtensionContext
+): string {
+    return require(path.join(context.extensionPath, 'package.json')).version;
+}
+
 function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
-    const wamrVersion = require(path.join(context.extensionPath, "package.json")).version;
+    const wamrVersion = getWAMRExtensionVersion(context);
     const lldbOsUrlSuffix = LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP[os.platform()];
 
     if (!lldbOsUrlSuffix) {
@@ -40,15 +54,25 @@ function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
 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");
+    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);
+    const setupPrompt = 'setup';
+    const skipPrompt = 'skip';
+    const response = await vscode.window.showWarningMessage(
+        'No LLDB instance found. Setup now?',
+        setupPrompt,
+        skipPrompt
+    );
 
     if (response === skipPrompt) {
         return;
@@ -61,23 +85,31 @@ export async function promptInstallLLDB(context: vscode.ExtensionContext) {
         throw WAMR_LLDB_NOT_SUPPORTED_ERROR;
     }
 
-    const lldbDestinationFolder = path.join(extensionPath, LLDB_RESOURCE_DIR, destinationDir);
-    const lldbZipPath = path.join(lldbDestinationFolder, "bundle.zip");
+    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...`);
+    vscode.window.showInformationMessage(
+        `LLDB downloaded to ${lldbZipPath}. Installing...`
+    );
 
-    const lldbFiles = await unzipFile(lldbZipPath, filename => getLLDBUnzipFilePath(lldbDestinationFolder, filename));
+    const lldbFiles = await unzipFile(lldbZipPath, filename =>
+        getLLDBUnzipFilePath(lldbDestinationFolder, filename)
+    );
     // Allow execution of lldb
-    lldbFiles.forEach(file => fs.chmodSync(file, "0775"));
+    lldbFiles.forEach(file => fs.chmodSync(file, '0775'));
 
-    vscode.window.showInformationMessage(`LLDB installed at ${lldbDestinationFolder}`);
+    vscode.window.showInformationMessage(
+        `LLDB installed at ${lldbDestinationFolder}`
+    );
 
     // Remove the bundle.zip
     fs.unlink(lldbZipPath, () => {});
 }
-
-