Skip to content

Commit d0c4c70

Browse files
vscode-extension: Run docker image with the same version as WAMR (#1815)
1 parent 97d2b5a commit d0c4c70

File tree

10 files changed

+133
-69
lines changed

10 files changed

+133
-69
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
docker run --rm -it --name=wasm-debug-server-ctr ^
77
-v "%cd%":/mnt ^
88
-p 1234:1234 ^
9-
wasm-debug-server:1.0 ^
9+
wasm-debug-server:%2 ^
1010
/bin/bash -c "./debug.sh %1"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ set -e
88
docker run --rm -it --name=wasm-debug-server-ctr \
99
-v "$(pwd)":/mnt \
1010
-p 1234:1234 \
11-
wasm-debug-server:1.0 \
11+
wasm-debug-server:$2 \
1212
/bin/bash -c "./debug.sh $1"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
docker run --rm --name=wasm-toolchain-ctr ^
88
-it -v "%cd%":/mnt ^
99
--env=PROJ_PATH="%cd%" ^
10-
wasm-toolchain:1.0 ^
10+
wasm-toolchain:%2 ^
1111
/bin/bash -c "./build_wasm.sh %1"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ set -e
88
docker run --rm --name=wasm-toolchain-ctr \
99
-it -v "$(pwd)":/mnt \
1010
--env=PROJ_PATH="$(pwd)" \
11-
wasm-toolchain:1.0 \
11+
wasm-toolchain:$2 \
1212
/bin/bash -c "./build_wasm.sh $1"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ set -e
77

88
docker run --rm -it --name=wasm-debug-server-ctr \
99
-v "$(pwd)":/mnt \
10-
wasm-debug-server:1.0 \
10+
wasm-debug-server:$2 \
1111
/bin/bash -c "./run.sh $1"

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import {
1818
} from './utilities/directoryUtilities';
1919
import { decorationProvider } from './decorationProvider';
2020
import { WasmDebugConfigurationProvider } from './debugConfigurationProvider';
21-
import { isLLDBInstalled, promptInstallLLDB } from './utilities/lldbUtilities';
21+
import {
22+
isLLDBInstalled,
23+
promptInstallLLDB,
24+
getWAMRExtensionVersion,
25+
} from './utilities/lldbUtilities';
2226

2327
let wasmTaskProvider: WasmTaskProvider;
2428
let wasmDebugConfigProvider: WasmDebugConfigurationProvider;
@@ -43,6 +47,8 @@ export async function activate(context: vscode.ExtensionContext) {
4347
excludeFileArr = new Array(),
4448
scriptMap = new Map();
4549

50+
const wamrVersion = getWAMRExtensionVersion(context);
51+
4652
/**
4753
* Get OS platform information for differ windows and linux execution script
4854
*/
@@ -83,7 +89,7 @@ export async function activate(context: vscode.ExtensionContext) {
8389
typeMap.set('Debug', 'Debug');
8490
typeMap.set('Destroy', 'Destroy');
8591

86-
wasmTaskProvider = new WasmTaskProvider(typeMap, scriptMap);
92+
wasmTaskProvider = new WasmTaskProvider(typeMap, scriptMap, wamrVersion);
8793

8894
vscode.tasks.registerTaskProvider('wasm', wasmTaskProvider);
8995

@@ -670,7 +676,8 @@ export async function activate(context: vscode.ExtensionContext) {
670676
let _path = curWorkspace.concat(
671677
OS_PLATFORM === 'win32'
672678
? '\\'
673-
: OS_PLATFORM === 'linux' || OS_PLATFORM === 'darwin'
679+
: OS_PLATFORM === 'linux' ||
680+
OS_PLATFORM === 'darwin'
674681
? '/'
675682
: '',
676683
option

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export interface OwnShellOption {
1515
export class WasmTaskProvider implements vscode.TaskProvider {
1616
constructor(
1717
public _type: Map<string, string>,
18-
public _script: Map<string, string>
18+
public _script: Map<string, string>,
19+
public _wamrVersion: string
1920
) {}
2021

2122
buildShellOption: OwnShellOption | undefined;
@@ -31,7 +32,11 @@ export class WasmTaskProvider implements vscode.TaskProvider {
3132
let targetName =
3233
TargetConfigPanel.BUILD_ARGS.output_file_name.split('.')[0];
3334

34-
if (os.platform() === 'linux' || os.platform() === 'darwin' || os.platform() === 'win32') {
35+
if (
36+
os.platform() === 'linux' ||
37+
os.platform() === 'darwin' ||
38+
os.platform() === 'win32'
39+
) {
3540
/* build */
3641
this.buildShellOption = {
3742
cmd:
@@ -40,7 +45,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
4045
: (this._script.get('buildScript') as string),
4146
options: {
4247
executable: this._script.get('buildScript'),
43-
shellArgs: [targetName, os.platform()],
48+
shellArgs: [targetName, this._wamrVersion],
4449
},
4550
};
4651

@@ -52,7 +57,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
5257
: (this._script.get('debugScript') as string),
5358
options: {
5459
executable: this._script.get('debugScript'),
55-
shellArgs: [targetName],
60+
shellArgs: [targetName, this._wamrVersion],
5661
},
5762
};
5863

@@ -64,7 +69,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
6469
: (this._script.get('runScript') as string),
6570
options: {
6671
executable: this._script.get('runScript'),
67-
shellArgs: [targetName],
72+
shellArgs: [targetName, this._wamrVersion],
6873
},
6974
};
7075

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

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -137,53 +137,73 @@ export function checkFolderName(folderName: string) {
137137
return valid;
138138
}
139139

140-
export function downloadFile(url: string, destinationPath: string): Promise<void> {
140+
export function downloadFile(
141+
url: string,
142+
destinationPath: string
143+
): Promise<void> {
141144
return new Promise((resolve, reject) => {
142145
const file = fileSystem.createWriteStream(destinationPath);
143146
const stream = request(url, undefined, (error, response, body) => {
144147
if (response.statusCode !== 200) {
145-
reject(new Error(`Download from ${url} failed with ${response.statusMessage}`));
148+
reject(
149+
new Error(
150+
`Download from ${url} failed with ${response.statusMessage}`
151+
)
152+
);
146153
}
147154
}).pipe(file);
148-
stream.on("close", resolve);
149-
stream.on("error", reject);
155+
stream.on('close', resolve);
156+
stream.on('error', reject);
150157
});
151158
}
152159

153-
export function unzipFile(sourcePath: string, getDestinationFileName: (entryName: string) => string): Promise<string[]> {
160+
export function unzipFile(
161+
sourcePath: string,
162+
getDestinationFileName: (entryName: string) => string
163+
): Promise<string[]> {
154164
return new Promise((resolve, reject) => {
155165
const unzippedFilePaths: string[] = [];
156-
yauzl.open(sourcePath, { lazyEntries: true }, function(error, zipfile) {
157-
if (error) {
158-
reject(error);
159-
return;
160-
}
161-
zipfile.readEntry();
162-
zipfile.on("entry", function(entry) {
163-
// This entry is a directory so skip it
164-
if (/\/$/.test(entry.fileName)) {
165-
zipfile.readEntry();
166+
yauzl.open(
167+
sourcePath,
168+
{ lazyEntries: true },
169+
function (error, zipfile) {
170+
if (error) {
171+
reject(error);
166172
return;
167-
}
168-
169-
zipfile.openReadStream(entry, function(error, readStream) {
170-
if (error) {
171-
reject(error);
173+
}
174+
zipfile.readEntry();
175+
zipfile.on('entry', function (entry) {
176+
// This entry is a directory so skip it
177+
if (/\/$/.test(entry.fileName)) {
178+
zipfile.readEntry();
172179
return;
173180
}
174-
readStream.on("end", () => zipfile.readEntry());
175-
const destinationFileName = getDestinationFileName(entry.fileName);
176-
fileSystem.mkdirSync(path.dirname(destinationFileName), { recursive: true });
177181

178-
const file = fileSystem.createWriteStream(destinationFileName);
179-
readStream.pipe(file).on("error", reject);
180-
unzippedFilePaths.push(destinationFileName);
182+
zipfile.openReadStream(entry, function (error, readStream) {
183+
if (error) {
184+
reject(error);
185+
return;
186+
}
187+
readStream.on('end', () => zipfile.readEntry());
188+
const destinationFileName = getDestinationFileName(
189+
entry.fileName
190+
);
191+
fileSystem.mkdirSync(
192+
path.dirname(destinationFileName),
193+
{ recursive: true }
194+
);
195+
196+
const file =
197+
fileSystem.createWriteStream(destinationFileName);
198+
readStream.pipe(file).on('error', reject);
199+
unzippedFilePaths.push(destinationFileName);
200+
});
201+
});
202+
zipfile.on('end', function () {
203+
zipfile.close();
204+
resolve(unzippedFilePaths);
181205
});
182-
});
183-
zipfile.on("end", function() {
184-
zipfile.close();
185-
resolve(unzippedFilePaths);
186-
});
187-
});
206+
}
207+
);
188208
});
189-
}
209+
}

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

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,41 @@ import * as vscode from 'vscode';
77
import * as os from 'os';
88
import * as path from 'path';
99
import * as fs from 'fs';
10-
import { checkIfFileExists, downloadFile, unzipFile } from './directoryUtilities';
11-
12-
const LLDB_RESOURCE_DIR = "resource/debug";
13-
const LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP: Partial<Record<NodeJS.Platform, string>> = {
14-
"linux": "x86_64-ubuntu-22.04",
15-
"darwin": "universal-macos-latest"
10+
import {
11+
checkIfFileExists,
12+
downloadFile,
13+
unzipFile,
14+
} from './directoryUtilities';
15+
16+
const LLDB_RESOURCE_DIR = 'resource/debug';
17+
const LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP: Partial<
18+
Record<NodeJS.Platform, string>
19+
> = {
20+
linux: 'x86_64-ubuntu-22.04',
21+
darwin: 'universal-macos-latest',
1622
};
1723

18-
const WAMR_LLDB_NOT_SUPPORTED_ERROR = new Error("WAMR LLDB is not supported on this platform");
24+
const WAMR_LLDB_NOT_SUPPORTED_ERROR = new Error(
25+
'WAMR LLDB is not supported on this platform'
26+
);
1927

2028
function getLLDBUnzipFilePath(destinationFolder: string, filename: string) {
21-
const dirs = filename.split("/");
22-
if (dirs[0] === "inst") {
29+
const dirs = filename.split('/');
30+
if (dirs[0] === 'inst') {
2331
dirs.shift();
2432
}
2533

2634
return path.join(destinationFolder, ...dirs);
2735
}
2836

37+
export function getWAMRExtensionVersion(
38+
context: vscode.ExtensionContext
39+
): string {
40+
return require(path.join(context.extensionPath, 'package.json')).version;
41+
}
42+
2943
function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
30-
const wamrVersion = require(path.join(context.extensionPath, "package.json")).version;
44+
const wamrVersion = getWAMRExtensionVersion(context);
3145
const lldbOsUrlSuffix = LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP[os.platform()];
3246

3347
if (!lldbOsUrlSuffix) {
@@ -40,15 +54,25 @@ function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
4054
export function isLLDBInstalled(context: vscode.ExtensionContext): boolean {
4155
const extensionPath = context.extensionPath;
4256
const lldbOSDir = os.platform();
43-
const lldbBinaryPath = path.join(extensionPath, LLDB_RESOURCE_DIR, lldbOSDir, "bin", "lldb");
57+
const lldbBinaryPath = path.join(
58+
extensionPath,
59+
LLDB_RESOURCE_DIR,
60+
lldbOSDir,
61+
'bin',
62+
'lldb'
63+
);
4464
return checkIfFileExists(lldbBinaryPath);
4565
}
4666

4767
export async function promptInstallLLDB(context: vscode.ExtensionContext) {
4868
const extensionPath = context.extensionPath;
49-
const setupPrompt = "setup";
50-
const skipPrompt = "skip";
51-
const response = await vscode.window.showWarningMessage('No LLDB instance found. Setup now?', setupPrompt, skipPrompt);
69+
const setupPrompt = 'setup';
70+
const skipPrompt = 'skip';
71+
const response = await vscode.window.showWarningMessage(
72+
'No LLDB instance found. Setup now?',
73+
setupPrompt,
74+
skipPrompt
75+
);
5276

5377
if (response === skipPrompt) {
5478
return;
@@ -61,23 +85,31 @@ export async function promptInstallLLDB(context: vscode.ExtensionContext) {
6185
throw WAMR_LLDB_NOT_SUPPORTED_ERROR;
6286
}
6387

64-
const lldbDestinationFolder = path.join(extensionPath, LLDB_RESOURCE_DIR, destinationDir);
65-
const lldbZipPath = path.join(lldbDestinationFolder, "bundle.zip");
88+
const lldbDestinationFolder = path.join(
89+
extensionPath,
90+
LLDB_RESOURCE_DIR,
91+
destinationDir
92+
);
93+
const lldbZipPath = path.join(lldbDestinationFolder, 'bundle.zip');
6694

6795
vscode.window.showInformationMessage(`Downloading LLDB...`);
6896

6997
await downloadFile(downloadUrl, lldbZipPath);
7098

71-
vscode.window.showInformationMessage(`LLDB downloaded to ${lldbZipPath}. Installing...`);
99+
vscode.window.showInformationMessage(
100+
`LLDB downloaded to ${lldbZipPath}. Installing...`
101+
);
72102

73-
const lldbFiles = await unzipFile(lldbZipPath, filename => getLLDBUnzipFilePath(lldbDestinationFolder, filename));
103+
const lldbFiles = await unzipFile(lldbZipPath, filename =>
104+
getLLDBUnzipFilePath(lldbDestinationFolder, filename)
105+
);
74106
// Allow execution of lldb
75-
lldbFiles.forEach(file => fs.chmodSync(file, "0775"));
107+
lldbFiles.forEach(file => fs.chmodSync(file, '0775'));
76108

77-
vscode.window.showInformationMessage(`LLDB installed at ${lldbDestinationFolder}`);
109+
vscode.window.showInformationMessage(
110+
`LLDB installed at ${lldbDestinationFolder}`
111+
);
78112

79113
// Remove the bundle.zip
80114
fs.unlink(lldbZipPath, () => {});
81115
}
82-
83-

0 commit comments

Comments
 (0)