@aiot-toolkit/emulator 2.0.2-beta.10 → 2.0.2-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/avd/index.d.ts +4 -0
- package/lib/avd/index.js +35 -30
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -1
- package/lib/instance/common.d.ts +5 -0
- package/lib/instance/common.js +25 -11
- package/lib/instance/dev.d.ts +11 -1
- package/lib/instance/dev.js +91 -46
- package/lib/instance/index.d.ts +4 -2
- package/lib/instance/index.js +9 -3
- package/lib/instance/miwear.d.ts +3 -0
- package/lib/instance/miwear.js +68 -97
- package/lib/instance/pre.d.ts +8 -0
- package/lib/instance/pre.js +19 -0
- package/lib/instance/preDev.js +27 -28
- package/lib/static/avdConfigIni.json +3 -3
- package/lib/static/constants.d.ts +7 -0
- package/lib/static/constants.js +30 -6
- package/lib/typing/Avd.d.ts +1 -0
- package/lib/typing/Instance.d.ts +2 -2
- package/lib/utils/index.d.ts +20 -0
- package/lib/utils/index.js +65 -8
- package/package.json +7 -5
package/lib/instance/miwear.js
CHANGED
|
@@ -35,14 +35,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const
|
|
38
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
39
39
|
const adbMiwt = __importStar(require("@miwt/adb"));
|
|
40
40
|
const child_process_1 = require("child_process");
|
|
41
41
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
42
42
|
const os_1 = __importDefault(require("os"));
|
|
43
43
|
const path_1 = __importDefault(require("path"));
|
|
44
44
|
const ws_1 = __importStar(require("ws"));
|
|
45
|
-
const constants_1 = require("../static/constants");
|
|
46
45
|
const utils_1 = require("../utils");
|
|
47
46
|
const common_1 = __importDefault(require("./common"));
|
|
48
47
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
@@ -55,8 +54,10 @@ class MiwearInstance extends common_1.default {
|
|
|
55
54
|
constructor(params) {
|
|
56
55
|
super(params);
|
|
57
56
|
this.params = params;
|
|
57
|
+
this.quickappStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
|
|
58
58
|
this.appPathInEmulator = '/data/quickapp/app';
|
|
59
59
|
this.reconnectCount = 0;
|
|
60
|
+
this.emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* 1. 启动模拟器
|
|
@@ -66,13 +67,13 @@ class MiwearInstance extends common_1.default {
|
|
|
66
67
|
start(options) {
|
|
67
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
69
|
this.startOptions = options;
|
|
69
|
-
this.sn = `
|
|
70
|
+
this.sn = `emulator-${this.startOptions.adbPort}`;
|
|
70
71
|
// 启动模拟器
|
|
71
72
|
yield this.startGoldfish(options);
|
|
72
73
|
// adb连接模拟器
|
|
73
|
-
const connected = yield this.
|
|
74
|
+
const connected = yield this.isConnected();
|
|
74
75
|
if (connected) {
|
|
75
|
-
|
|
76
|
+
shared_utils_1.ColorConsole.info('### Emulator ### Goldfish emulator connected successfully');
|
|
76
77
|
// 如果是首次启动,创建server端监听事件
|
|
77
78
|
if (this.isFirstStart && this.startOptions.serverPort) {
|
|
78
79
|
yield this.createWebsockeServer();
|
|
@@ -83,7 +84,7 @@ class MiwearInstance extends common_1.default {
|
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
86
|
const msg = '### Emulator ### Failed to connect emulator, please check whether the adb is normal';
|
|
86
|
-
|
|
87
|
+
shared_utils_1.ColorConsole.throw(msg);
|
|
87
88
|
throw new Error(msg);
|
|
88
89
|
}
|
|
89
90
|
});
|
|
@@ -104,20 +105,20 @@ class MiwearInstance extends common_1.default {
|
|
|
104
105
|
const { avdName, devtool, origin = 'terminal' } = options;
|
|
105
106
|
// 获取emulator bin的绝对路径
|
|
106
107
|
const emulatorBin = this.getEmulatorBinPath();
|
|
107
|
-
|
|
108
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
108
109
|
// 获取vela镜像的绝对路径
|
|
109
110
|
const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
|
|
110
|
-
const { avdArch, avdImagePath } = avdInfo;
|
|
111
|
-
|
|
111
|
+
const { avdArch, avdImagePath, customImagePath } = avdInfo;
|
|
112
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### adb port: ${options.adbPort}`);
|
|
112
113
|
if (!avdImagePath) {
|
|
113
|
-
return
|
|
114
|
+
return shared_utils_1.ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
114
115
|
}
|
|
115
|
-
const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
let portMappingStr =
|
|
116
|
+
const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
|
|
117
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
118
|
+
// 端口映射
|
|
119
|
+
let portMappingStr = ``;
|
|
119
120
|
if (devtool) {
|
|
120
|
-
portMappingStr +=
|
|
121
|
+
portMappingStr += `-network-user-mode-options hostfwd=tcp:127.0.0.1:${options.debugPort}-10.0.2.15:101`;
|
|
121
122
|
}
|
|
122
123
|
// 设备挂载节点
|
|
123
124
|
const systemImageBin = path_1.default.resolve(avdImagePath, 'vela_resource.bin'); // 只读
|
|
@@ -145,61 +146,50 @@ class MiwearInstance extends common_1.default {
|
|
|
145
146
|
-drive index=2,id=vendor,if=none,format=raw,file=${coreBin},read-only \
|
|
146
147
|
-device virtio-blk-device,bus=virtio-mmio-bus.4,drive=vendor \
|
|
147
148
|
-device virtio-snd,bus=virtio-mmio-bus.2 -allow-host-audio -semihosting`;
|
|
148
|
-
//
|
|
149
|
+
// grpc配置
|
|
149
150
|
let windowStr = '';
|
|
150
|
-
let
|
|
151
|
-
if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.
|
|
152
|
-
windowStr = '-
|
|
153
|
-
|
|
154
|
-
vncStr = `-vnc :${portSuffix}`;
|
|
151
|
+
let grpcStr = '';
|
|
152
|
+
if ((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.grpcPort) {
|
|
153
|
+
windowStr = '-qt-hide-window';
|
|
154
|
+
grpcStr = ` -idle-grpc-timeout 300 -grpc ${this.startOptions.grpcPort}`;
|
|
155
155
|
}
|
|
156
156
|
// 启动模拟器的命令和参数
|
|
157
|
-
const cmd = `${emulatorBin} -nuttx -avd ${avdName} -avd-arch ${avdArch} -show-kernel -kernel ${nuttxBinPath} ${portMappingStr} ${windowStr}
|
|
157
|
+
const cmd = `${emulatorBin} -nuttx -avd ${avdName} -port ${options.adbPort} -avd-arch ${avdArch} -show-kernel -kernel ${nuttxBinPath} ${portMappingStr} ${windowStr} ${grpcStr} -qemu ${imageMountStr}`;
|
|
158
158
|
const spawnArgs = cmd.split(' ');
|
|
159
159
|
const spawnBin = spawnArgs.shift();
|
|
160
|
-
|
|
160
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Start CMD: ${cmd}`);
|
|
161
161
|
return new Promise((resolve) => {
|
|
162
|
-
var _a, _b, _c
|
|
162
|
+
var _a, _b, _c;
|
|
163
163
|
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, {
|
|
164
164
|
stdio: 'pipe',
|
|
165
165
|
shell: true,
|
|
166
166
|
cwd: this.sdkHome
|
|
167
167
|
});
|
|
168
|
-
// 处理origin为terminal
|
|
169
|
-
if (origin === 'terminal') {
|
|
170
|
-
process.stdout.pipe(this.goldfishProcess.stdin);
|
|
171
|
-
(_a = this.goldfishProcess.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
172
|
-
(_b = this.goldfishProcess.stderr) === null || _b === void 0 ? void 0 : _b.pipe(process.stderr);
|
|
173
|
-
}
|
|
174
168
|
// 监听模拟器的退出事件
|
|
175
169
|
this.goldfishProcess.on('exit', (code) => {
|
|
176
|
-
|
|
170
|
+
shared_utils_1.ColorConsole.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
177
171
|
if (options.exitCallback) {
|
|
178
172
|
options.exitCallback(code);
|
|
179
173
|
}
|
|
180
174
|
});
|
|
181
175
|
// 监听错误流
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
187
|
-
}
|
|
176
|
+
(_a = this.goldfishProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
177
|
+
const stderrCb = options.stderrCallback || console.log;
|
|
178
|
+
stderrCb(data.toString());
|
|
179
|
+
});
|
|
188
180
|
// 监听输出流
|
|
189
|
-
(
|
|
181
|
+
(_c = (_b = this.goldfishProcess) === null || _b === void 0 ? void 0 : _b.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
|
|
190
182
|
const msg = data.toString();
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// this.launchQuickapp()
|
|
198
|
-
// }
|
|
183
|
+
const stdoutCb = options.stdoutCallback || console.log;
|
|
184
|
+
stdoutCb(msg);
|
|
185
|
+
// 应用安装成功,则启动它
|
|
186
|
+
if (msg.match(/InstallState_Finished|install finished/)) {
|
|
187
|
+
shared_utils_1.ColorConsole.info(`### Emulator ### Install quickapp successfully`);
|
|
188
|
+
this.launchQuickapp();
|
|
199
189
|
}
|
|
200
190
|
// 匹配到,则认为模拟器启动成功
|
|
201
|
-
if (msg.match(
|
|
202
|
-
|
|
191
|
+
if (msg.match(this.emulatorStartedFlag)) {
|
|
192
|
+
shared_utils_1.ColorConsole.info(`### Emulator ### Goldfish emulator starts successfully`);
|
|
203
193
|
resolve();
|
|
204
194
|
}
|
|
205
195
|
});
|
|
@@ -226,7 +216,7 @@ class MiwearInstance extends common_1.default {
|
|
|
226
216
|
.readdirSync(releaseDir)
|
|
227
217
|
.filter((item) => item.includes(appPackageName) && item.endsWith('.rpk'));
|
|
228
218
|
if (files.length === 0) {
|
|
229
|
-
|
|
219
|
+
shared_utils_1.ColorConsole.error(`### Emulator the rpk does not exist`);
|
|
230
220
|
}
|
|
231
221
|
const rpkPath = path_1.default.resolve(releaseDir, files[0]);
|
|
232
222
|
// 调试模式需要push一个文件至miwear中
|
|
@@ -235,7 +225,7 @@ class MiwearInstance extends common_1.default {
|
|
|
235
225
|
yield adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} push ${debuggerCfgFile} /data/debugger_ip.cfg`);
|
|
236
226
|
}
|
|
237
227
|
else {
|
|
238
|
-
adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell rm /data/debugger_ip.cfg`);
|
|
228
|
+
yield adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell rm /data/debugger_ip.cfg`);
|
|
239
229
|
}
|
|
240
230
|
this.installRpkToAppList(rpkPath, this.appPathInEmulator);
|
|
241
231
|
});
|
|
@@ -249,39 +239,15 @@ class MiwearInstance extends common_1.default {
|
|
|
249
239
|
*/
|
|
250
240
|
installRpkToAppList(rpkPath, targetDir) {
|
|
251
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const installCmd = `adb -s ${this.sn} shell pm install ${targetPath}`;
|
|
262
|
-
ColorConsole_1.default.info(`### Emulator ### Excuting cmd: ${installCmd}`);
|
|
263
|
-
yield adbMiwt.execAdbCmdAsync(installCmd);
|
|
264
|
-
// 3. 应用安装成功后,启动应用
|
|
265
|
-
const lsCmd = `adb -s ${this.sn} shell ls ${this.appPathInEmulator}`;
|
|
266
|
-
let installed = false;
|
|
267
|
-
let currCount = 0;
|
|
268
|
-
while (!installed && currCount < 10) {
|
|
269
|
-
yield (0, utils_1.sleep)(1000);
|
|
270
|
-
const res = yield adbMiwt.execAdbCmdAsync(lsCmd);
|
|
271
|
-
// 如果没有上传的rpk了,则表示安装成功
|
|
272
|
-
installed = !res.includes(`${packageName}.rpk`);
|
|
273
|
-
currCount++;
|
|
274
|
-
}
|
|
275
|
-
if (installed) {
|
|
276
|
-
this.launchQuickapp();
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
ColorConsole_1.default.error(`### Emulator ### install ${packageName} failed`);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
catch (e) {
|
|
283
|
-
ColorConsole_1.default.error(`### Emulator ### ${e.message}`);
|
|
284
|
-
}
|
|
242
|
+
const { package: packageName } = this.projectInfo;
|
|
243
|
+
// 1. adb push应用的rpk
|
|
244
|
+
const targetPath = `${targetDir}/${packageName}.rpk`;
|
|
245
|
+
const pushCmd = `adb -s ${this.sn} push "${rpkPath}" ${targetPath}`;
|
|
246
|
+
shared_utils_1.ColorConsole.info(`### Emulator ### Excuting cmd: ${pushCmd}`);
|
|
247
|
+
yield adbMiwt.execAdbCmdAsync(pushCmd);
|
|
248
|
+
const installCmd = `adb -s ${this.sn} shell pm install ${targetPath}`;
|
|
249
|
+
shared_utils_1.ColorConsole.info(`### Emulator ### Excuting cmd: ${installCmd}`);
|
|
250
|
+
yield adbMiwt.execAdbCmdAsync(installCmd);
|
|
285
251
|
});
|
|
286
252
|
}
|
|
287
253
|
/** 使用am start启动快应用 */
|
|
@@ -289,7 +255,7 @@ class MiwearInstance extends common_1.default {
|
|
|
289
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
256
|
const { package: packageName } = this.projectInfo;
|
|
291
257
|
const startCmd = `adb -s ${this.sn} shell am start ${packageName}`;
|
|
292
|
-
|
|
258
|
+
shared_utils_1.ColorConsole.info(`### Emulator ### Excuting cmd: ${startCmd}`);
|
|
293
259
|
adbMiwt.execAdbCmdAsync(startCmd);
|
|
294
260
|
});
|
|
295
261
|
}
|
|
@@ -305,7 +271,7 @@ class MiwearInstance extends common_1.default {
|
|
|
305
271
|
}
|
|
306
272
|
this.debugSocket = new ws_1.default(`ws://localhost:${(_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.debugPort}`);
|
|
307
273
|
this.debugSocket.onopen = () => {
|
|
308
|
-
|
|
274
|
+
shared_utils_1.ColorConsole.info(`### Emulator debugSocket connect success`);
|
|
309
275
|
return resolve();
|
|
310
276
|
};
|
|
311
277
|
this.debugSocket.onerror = (errorEvent) => {
|
|
@@ -313,7 +279,7 @@ class MiwearInstance extends common_1.default {
|
|
|
313
279
|
// 重连机制
|
|
314
280
|
(_a = this.debugSocket) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
315
281
|
if (this.reconnectCount < MAX_RECONNECT_COUNT) {
|
|
316
|
-
|
|
282
|
+
shared_utils_1.ColorConsole.info(`### Emulator the ${this.reconnectCount + 1}th time to reconnect debug server`);
|
|
317
283
|
this.reconnectCount++;
|
|
318
284
|
setTimeout(() => this.initDebugSocket(), 2000);
|
|
319
285
|
}
|
|
@@ -326,7 +292,7 @@ class MiwearInstance extends common_1.default {
|
|
|
326
292
|
this.debugSocket.onclose = (closeEvent) => {
|
|
327
293
|
this.debugSocket = undefined;
|
|
328
294
|
this.reconnectCount = 0;
|
|
329
|
-
|
|
295
|
+
shared_utils_1.ColorConsole.log(`### Emulator debugSocket connect close: ${closeEvent.reason}`);
|
|
330
296
|
};
|
|
331
297
|
});
|
|
332
298
|
}
|
|
@@ -349,7 +315,7 @@ class MiwearInstance extends common_1.default {
|
|
|
349
315
|
}
|
|
350
316
|
}
|
|
351
317
|
catch (e) {
|
|
352
|
-
|
|
318
|
+
shared_utils_1.ColorConsole.error(`${e}`);
|
|
353
319
|
}
|
|
354
320
|
});
|
|
355
321
|
}
|
|
@@ -370,7 +336,7 @@ class MiwearInstance extends common_1.default {
|
|
|
370
336
|
const sourcePath = path_1.default.resolve(this.projectPath, './build/*');
|
|
371
337
|
yield adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} push ${sourcePath} ${this.appPathInEmulator}/${appPackageName}`);
|
|
372
338
|
}
|
|
373
|
-
|
|
339
|
+
shared_utils_1.ColorConsole.info(`### Emulator push to ${this.appPathInEmulator}/${appPackageName} successfully`);
|
|
374
340
|
});
|
|
375
341
|
}
|
|
376
342
|
/** 在模拟器中重启快应用(基于am命令,需要保证镜像中已经有am功能)
|
|
@@ -378,24 +344,29 @@ class MiwearInstance extends common_1.default {
|
|
|
378
344
|
* 2. nsh中执行am stop命令退出快应用
|
|
379
345
|
* 3. nsh中执行am start命令启动快应用
|
|
380
346
|
*/
|
|
347
|
+
pushAndReloadApp() {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
// 1. 将整包重新推到miwear中(TODO:增量更新)
|
|
350
|
+
yield this.pushBuild();
|
|
351
|
+
yield this.reloadApp();
|
|
352
|
+
});
|
|
353
|
+
}
|
|
381
354
|
reloadApp() {
|
|
382
355
|
return __awaiter(this, void 0, void 0, function* () {
|
|
383
356
|
try {
|
|
384
|
-
// 1. 将整包重新推到miwear中(TODO:增量更新)
|
|
385
357
|
const { package: appPackageName } = this.projectInfo;
|
|
386
|
-
yield this.pushBuild();
|
|
387
358
|
// 2. 执行am stop和am start命令
|
|
388
359
|
const stopCmd = `adb -s ${this.sn} shell am stop ${appPackageName}`;
|
|
389
360
|
yield adbMiwt.execAdbCmdAsync(stopCmd);
|
|
390
|
-
|
|
361
|
+
shared_utils_1.ColorConsole.info(`### Emulator stop ${appPackageName} successfully`);
|
|
391
362
|
// 这里是为了等am stop命令清除资源等
|
|
392
363
|
yield (0, utils_1.sleep)(500);
|
|
393
364
|
const startCmd = `adb -s ${this.sn} shell am start ${appPackageName}`;
|
|
394
365
|
yield adbMiwt.execAdbCmdAsync(startCmd);
|
|
395
|
-
|
|
366
|
+
shared_utils_1.ColorConsole.info(`### Emulator start ${appPackageName} successfully`);
|
|
396
367
|
}
|
|
397
368
|
catch (e) {
|
|
398
|
-
|
|
369
|
+
shared_utils_1.ColorConsole.error(`${e}`);
|
|
399
370
|
}
|
|
400
371
|
});
|
|
401
372
|
}
|
|
@@ -409,15 +380,15 @@ class MiwearInstance extends common_1.default {
|
|
|
409
380
|
port: (_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.serverPort
|
|
410
381
|
});
|
|
411
382
|
wsServer.on('connection', (socket) => {
|
|
412
|
-
|
|
383
|
+
shared_utils_1.ColorConsole.success(`### App Socket server ### Websocket connects to websocket server`);
|
|
413
384
|
socket.on('error', (err) => {
|
|
414
|
-
|
|
385
|
+
shared_utils_1.ColorConsole.error(`### App Socket server ### Websocket server error: ${err.message}`);
|
|
415
386
|
});
|
|
416
387
|
// data的格式:{ type: string, data: any }
|
|
417
388
|
socket.on('message', (data) => __awaiter(this, void 0, void 0, function* () {
|
|
418
389
|
var _a;
|
|
419
390
|
const message = JSON.parse(data.toString());
|
|
420
|
-
|
|
391
|
+
shared_utils_1.ColorConsole.log(`### App Socket server ### Websocket server get data: ${data}`);
|
|
421
392
|
if (message.type === 'restart') {
|
|
422
393
|
// 非调试模式下无法热更新
|
|
423
394
|
if (!((_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.devtool)) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dev_1 = __importDefault(require("./dev"));
|
|
7
|
+
const miwear_1 = __importDefault(require("./miwear"));
|
|
8
|
+
/**
|
|
9
|
+
* 不带 miwear 的 4.0 镜像
|
|
10
|
+
*/
|
|
11
|
+
class PreInstance extends dev_1.default {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.appRunDir = '/data/quickapp/app';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// pre 镜像的 启动 方式与 MiwearInstance 一致
|
|
18
|
+
PreInstance.prototype.startGoldfish = miwear_1.default.prototype.startGoldfish;
|
|
19
|
+
exports.default = PreInstance;
|
package/lib/instance/preDev.js
CHANGED
|
@@ -35,8 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const
|
|
39
|
-
const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
|
|
38
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
40
39
|
const adbMiwt = __importStar(require("@miwt/adb"));
|
|
41
40
|
const child_process_1 = require("child_process");
|
|
42
41
|
const find_process_1 = __importDefault(require("find-process"));
|
|
@@ -78,7 +77,7 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
78
77
|
// adb连接快应用
|
|
79
78
|
const connected = yield this.connectGoldfish();
|
|
80
79
|
if (connected) {
|
|
81
|
-
|
|
80
|
+
shared_utils_1.ColorConsole.log('### Emulator ### Goldfish emulator connected successfully');
|
|
82
81
|
// 如果是首次启动,创建server端监听事件
|
|
83
82
|
if (this.isFirstStart && this.startOptions.serverPort) {
|
|
84
83
|
yield this.createWebsockeServer();
|
|
@@ -88,7 +87,7 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
88
87
|
this.isFirstStart = false;
|
|
89
88
|
}
|
|
90
89
|
else {
|
|
91
|
-
|
|
90
|
+
shared_utils_1.ColorConsole.throw('### Emulator ### Failed to connect emulator, please check whether the adb is normal');
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
93
|
}
|
|
@@ -103,19 +102,19 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
103
102
|
const { package: packageName } = this.projectInfo;
|
|
104
103
|
const appMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
105
104
|
const mountCmd = `adb -s 127.0.0.1:${options.adbPort} shell mount -t v9fs -o tag=10.0.2.2,port=${this.host9pPort},aname=${appMountDir} /data`;
|
|
106
|
-
|
|
105
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Excuting adb cmd: ${mountCmd}`);
|
|
107
106
|
adbMiwt.execAdbCmdSync(mountCmd);
|
|
108
107
|
let vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp app/${packageName} &`;
|
|
109
108
|
// 调试情况下,需要加--jsdebugger=10.0.2.15:101
|
|
110
109
|
if (options.devtool) {
|
|
111
110
|
vappCmd = `adb -s 127.0.0.1:${options.adbPort} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`;
|
|
112
111
|
}
|
|
113
|
-
|
|
112
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Excuting adb cmd: ${vappCmd}`);
|
|
114
113
|
// vapp进程会一直pending,不会退出。这里必须加stdio: 'ignore',否则快应用无法运行成功
|
|
115
114
|
adbMiwt.execAdbCmdAsync(vappCmd, { stdio: 'ignore', encoding: 'utf-8' });
|
|
116
115
|
}
|
|
117
116
|
catch (e) {
|
|
118
|
-
|
|
117
|
+
shared_utils_1.ColorConsole.error(`### Emulator ### Failed to startup quickapp: ${e.message}`);
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
/** host启动9pServer
|
|
@@ -127,10 +126,10 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
127
126
|
const yaFileName = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
|
|
128
127
|
const pidList = yield (0, find_process_1.default)('name', yaFileName);
|
|
129
128
|
if (pidList.length > 0) {
|
|
130
|
-
|
|
129
|
+
shared_utils_1.ColorConsole.log('### Emulator ### 9p server started in host');
|
|
131
130
|
return resolve();
|
|
132
131
|
}
|
|
133
|
-
|
|
132
|
+
shared_utils_1.ColorConsole.log('### Emulator ### Starting 9p server in host');
|
|
134
133
|
const quickappMountDir = path_1.default.resolve(this.sdkHome, 'qa');
|
|
135
134
|
const toolsHome = path_1.default.resolve(this.sdkHome, 'tools');
|
|
136
135
|
const serverBinPath = path_1.default.resolve(toolsHome, yaFileName);
|
|
@@ -148,14 +147,14 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
148
147
|
(_a = this.v9fsProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
149
148
|
const output = data.toString();
|
|
150
149
|
if (output.match(/Server started, listening on: 127.0.0.1:(\d+)/)) {
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
shared_utils_1.ColorConsole.log(output);
|
|
151
|
+
shared_utils_1.ColorConsole.log('### Emulator ### 9p server starts successfully');
|
|
153
152
|
return resolve();
|
|
154
153
|
}
|
|
155
154
|
});
|
|
156
155
|
// 监听exit事件,判断9p server是否退出了
|
|
157
156
|
this.v9fsProcess.on('exit', (code) => {
|
|
158
|
-
|
|
157
|
+
shared_utils_1.ColorConsole.error(`### Emulator ### ya-vm-file-server exited with code ${code}`);
|
|
159
158
|
return reject();
|
|
160
159
|
});
|
|
161
160
|
}));
|
|
@@ -175,29 +174,29 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
175
174
|
const { avdName, devtool, origin = 'terminal' } = options;
|
|
176
175
|
// 获取emulator bin的绝对路径
|
|
177
176
|
const emulatorBin = this.getEmulatorBinPath();
|
|
178
|
-
|
|
177
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### emulator path: ${emulatorBin}`);
|
|
179
178
|
// 获取vela镜像的绝对路径
|
|
180
179
|
const avdInfo = this.velaAvdCls.getVelaAvdInfo(avdName);
|
|
181
|
-
const { avdArch, avdImagePath } = avdInfo;
|
|
182
|
-
|
|
180
|
+
const { avdArch, avdImagePath, customImagePath } = avdInfo;
|
|
181
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### adb port: ${options.adbPort}`);
|
|
183
182
|
if (!avdImagePath) {
|
|
184
|
-
return
|
|
183
|
+
return shared_utils_1.ColorConsole.throw(`### Emulator ### Unable to find vela image via avd`);
|
|
185
184
|
}
|
|
186
|
-
const nuttxBinPath = path_1.default.resolve(avdImagePath, 'nuttx');
|
|
187
|
-
|
|
185
|
+
const nuttxBinPath = path_1.default.resolve(customImagePath || avdImagePath, 'nuttx');
|
|
186
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### nuttx path: ${nuttxBinPath}`);
|
|
188
187
|
// 端口映射,adb端口和debug端口
|
|
189
188
|
let portMappingStr = `user,id=u1,hostfwd=tcp:127.0.0.1:${options.adbPort}-10.0.2.15:5555`;
|
|
190
189
|
if (devtool) {
|
|
191
|
-
|
|
190
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### debug port: ${options.debugPort}`);
|
|
192
191
|
portMappingStr += `,hostfwd=tcp:127.0.0.1:${options.debugPort}-10.0.2.15:101`;
|
|
193
192
|
}
|
|
194
|
-
|
|
193
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Start qemu with TCP: ${portMappingStr}`);
|
|
195
194
|
// vnc配置
|
|
196
195
|
let noWindow = false;
|
|
197
196
|
let vncStr = '';
|
|
198
|
-
if (options.
|
|
197
|
+
if (options.grpcPort) {
|
|
199
198
|
noWindow = true;
|
|
200
|
-
const portSuffix = options.
|
|
199
|
+
const portSuffix = options.grpcPort - constants_1.defaultVncPort;
|
|
201
200
|
vncStr = `-vnc :${portSuffix}`;
|
|
202
201
|
}
|
|
203
202
|
// 启动goldfish的命令和参数
|
|
@@ -219,7 +218,7 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
219
218
|
'-device',
|
|
220
219
|
'virtio-net-device,netdev=u1,bus=virtio-mmio-bus.3'
|
|
221
220
|
];
|
|
222
|
-
|
|
221
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Start CMD: ${spawnBin} ${spawnArgs.join(' ')}`);
|
|
223
222
|
return new Promise((resolve) => {
|
|
224
223
|
var _a, _b, _c, _d;
|
|
225
224
|
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, { stdio: 'pipe', shell: true });
|
|
@@ -234,7 +233,7 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
234
233
|
}
|
|
235
234
|
// 监听模拟器的退出事件
|
|
236
235
|
this.goldfishProcess.on('exit', (code) => {
|
|
237
|
-
|
|
236
|
+
shared_utils_1.ColorConsole.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
238
237
|
if (options.exitCallback) {
|
|
239
238
|
options.exitCallback(code);
|
|
240
239
|
}
|
|
@@ -247,7 +246,7 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
247
246
|
stdoutCb(msg);
|
|
248
247
|
}
|
|
249
248
|
if (msg.includes('(NSH)')) {
|
|
250
|
-
|
|
249
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Goldfish emulator starts successfully`);
|
|
251
250
|
resolve();
|
|
252
251
|
}
|
|
253
252
|
});
|
|
@@ -262,10 +261,10 @@ class OldGoldfishInstance extends common_1.default {
|
|
|
262
261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
263
262
|
const { package: appPackageName } = this.projectInfo;
|
|
264
263
|
const appRunDir = path_1.default.resolve(this.sdkHome, 'qa/app', appPackageName);
|
|
265
|
-
|
|
264
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Pushing ${appPackageName} to ${appRunDir}`);
|
|
266
265
|
fs_1.default.rmSync(appRunDir, { recursive: true, force: true });
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
shared_utils_1.FileUtil.copyFiles(sourceRoot, appRunDir);
|
|
267
|
+
shared_utils_1.ColorConsole.log(`### Emulator ### Push ${appPackageName} to ${appRunDir} successfully`);
|
|
269
268
|
});
|
|
270
269
|
}
|
|
271
270
|
/** 停止模拟器并释放相关资源 */
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"hw.arc": false,
|
|
11
11
|
"hw.audioInput": "yes",
|
|
12
12
|
"hw.battery": "yes",
|
|
13
|
-
"hw.camera.back": "
|
|
14
|
-
"hw.camera.front": "
|
|
13
|
+
"hw.camera.back": "None",
|
|
14
|
+
"hw.camera.front": "None",
|
|
15
15
|
"hw.cpu.arch": "arm",
|
|
16
16
|
"hw.cpu.ncore": 4,
|
|
17
17
|
"hw.dPad": "no",
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
"skin.dynamic": "no",
|
|
37
37
|
"skin.name": "",
|
|
38
38
|
"skin.path": ""
|
|
39
|
-
}
|
|
39
|
+
}
|
|
@@ -8,10 +8,17 @@ export declare const defaultToolsHome: string;
|
|
|
8
8
|
export declare const defaultVncPort = 5900;
|
|
9
9
|
export declare const defaultAdbPort = 5555;
|
|
10
10
|
export declare const defaultDebugPort = 10055;
|
|
11
|
+
/**
|
|
12
|
+
* vela-release-4.0 : vela 4.0 带 miwear
|
|
13
|
+
* vela-pre-4.0 : vela 4.0 不带 miwear
|
|
14
|
+
* vela-dev-0.0.4 : vela 4.0 dev 分支
|
|
15
|
+
*/
|
|
11
16
|
export declare const VelaImageVersionList: {
|
|
12
17
|
label: string;
|
|
13
18
|
value: string;
|
|
14
19
|
time: string;
|
|
20
|
+
hide: boolean;
|
|
21
|
+
icon: null;
|
|
15
22
|
}[];
|
|
16
23
|
export declare const EmulatorEnvVersion: {
|
|
17
24
|
name: string;
|
package/lib/static/constants.js
CHANGED
|
@@ -16,21 +16,45 @@ exports.defaultToolsHome = path_1.default.resolve(exports.defaultSDKHome, 'tools
|
|
|
16
16
|
exports.defaultVncPort = 5900;
|
|
17
17
|
exports.defaultAdbPort = 5555;
|
|
18
18
|
exports.defaultDebugPort = 10055;
|
|
19
|
+
// 不确定vela镜像的发布策略,暂时需要手动更新此列表
|
|
20
|
+
// 0.0.2和0.0.3版本比较特殊,线上是一个nuttx文件。其他版本都是一个zip包,包含nuttx data.img和vela_source.img
|
|
21
|
+
/**
|
|
22
|
+
* vela-release-4.0 : vela 4.0 带 miwear
|
|
23
|
+
* vela-pre-4.0 : vela 4.0 不带 miwear
|
|
24
|
+
* vela-dev-0.0.4 : vela 4.0 dev 分支
|
|
25
|
+
*/
|
|
19
26
|
exports.VelaImageVersionList = [
|
|
20
27
|
{
|
|
21
|
-
label: 'vela
|
|
28
|
+
label: 'vela-4.0-正式版',
|
|
22
29
|
value: 'vela-release-4.0',
|
|
23
|
-
time: '2024-
|
|
30
|
+
time: '2024-07-15T15:57:00',
|
|
31
|
+
hide: false,
|
|
32
|
+
icon: null
|
|
24
33
|
},
|
|
25
34
|
{
|
|
26
|
-
label: 'vela
|
|
27
|
-
value: 'vela-
|
|
28
|
-
time: '
|
|
35
|
+
label: 'vela-4.0-测试版',
|
|
36
|
+
value: 'vela-pre-4.0',
|
|
37
|
+
time: '2024-07-151T07:07:00',
|
|
38
|
+
hide: false,
|
|
39
|
+
icon: null
|
|
29
40
|
},
|
|
41
|
+
// 废弃 0.0.2 版本
|
|
42
|
+
// {
|
|
43
|
+
// label: 'vela开发版(dev, 0.0.2)',
|
|
44
|
+
// value: 'vela-dev-0.0.2',
|
|
45
|
+
// time: '2023-12-04T16:31:00',
|
|
46
|
+
// },
|
|
47
|
+
{
|
|
48
|
+
label: 'vela-dev-开发版',
|
|
49
|
+
value: 'vela-dev-0.0.4',
|
|
50
|
+
time: '2024-07-12T11:12:00',
|
|
51
|
+
hide: true,
|
|
52
|
+
icon: null
|
|
53
|
+
}
|
|
30
54
|
];
|
|
31
55
|
exports.EmulatorEnvVersion = {
|
|
32
56
|
name: '模拟器资源版本管理',
|
|
33
|
-
emulator: '0.0.
|
|
57
|
+
emulator: '0.0.4',
|
|
34
58
|
qa: '0.0.1',
|
|
35
59
|
skins: '0.0.1',
|
|
36
60
|
'system-images': exports.VelaImageVersionList[0].value,
|