@aiot-toolkit/emulator 2.0.6-beta.27 → 2.0.6-beta.29
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/broker/index.d.ts +21 -0
- package/lib/broker/index.js +98 -0
- package/lib/emulatorutil/constants.js +23 -14
- package/lib/emulatorutil/running.d.ts +11 -0
- package/lib/emulatorutil/running.js +56 -17
- package/lib/index.d.ts +2 -1
- package/lib/index.js +20 -1
- package/lib/instance/common.d.ts +7 -0
- package/lib/instance/common.js +52 -30
- package/lib/instance/dev.js +5 -8
- package/lib/instance/index.js +1 -0
- package/lib/instance/minisound.js +3 -4
- package/lib/instance/miwear.js +5 -7
- package/lib/instance/miwear5.d.ts +6 -0
- package/lib/instance/miwear5.js +73 -2
- package/lib/instance/openSmartspeaker5.js +3 -4
- package/lib/instance/pre.js +5 -8
- package/lib/instance/vela5.d.ts +26 -1
- package/lib/instance/vela5.js +112 -18
- package/lib/shared/index.d.ts +8 -0
- package/lib/shared/index.js +33 -0
- package/lib/typing/Vvd.d.ts +2 -0
- package/lib/typing/Vvd.js +1 -0
- package/lib/utils/index.d.ts +23 -0
- package/lib/utils/index.js +42 -6
- package/lib/vvd/grpc/index.d.ts +1 -1
- package/lib/vvd/grpc/index.js +2 -4
- package/lib/vvd/grpc/types/proto-types.js +6 -0
- package/lib/vvd/index.d.ts +11 -5
- package/lib/vvd/index.js +91 -18
- package/lib/vvd/logcat.js +2 -6
- package/package.json +8 -10
package/lib/vvd/index.js
CHANGED
|
@@ -20,9 +20,9 @@ var _Instance = require("../typing/Instance");
|
|
|
20
20
|
var _portfinder = require("portfinder");
|
|
21
21
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
22
22
|
var _emulatorutil = require("../emulatorutil");
|
|
23
|
-
var _adb = require("@
|
|
23
|
+
var _adb = require("@aiot-toolkit/adb");
|
|
24
24
|
var _semver = require("semver");
|
|
25
|
-
var
|
|
25
|
+
var _extractZip = _interopRequireDefault(require("extract-zip"));
|
|
26
26
|
var _instance = require("../instance");
|
|
27
27
|
var _logcat = require("./logcat");
|
|
28
28
|
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
@@ -37,6 +37,53 @@ const getPort = (async () => {
|
|
|
37
37
|
const ipull = (async () => {
|
|
38
38
|
return await import('ipull');
|
|
39
39
|
})();
|
|
40
|
+
|
|
41
|
+
/** 递归去掉目录下所有文件的只读属性 */
|
|
42
|
+
function clearReadonly(dir) {
|
|
43
|
+
for (const entry of _fs.default.readdirSync(dir, {
|
|
44
|
+
withFileTypes: true
|
|
45
|
+
})) {
|
|
46
|
+
const p = _path.default.join(dir, entry.name);
|
|
47
|
+
if (entry.isDirectory()) clearReadonly(p);else if (entry.isFile()) _fs.default.chmodSync(p, 0o666);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 流式解压 zip。adm-zip 的 extractAllTo 是同步的,会把整个 zip 读进内存再解压:
|
|
53
|
+
* vela-watch-6.0.zip 在 IDE 里要阻塞扩展进程 6 分多钟、占 1.6 GB 内存,
|
|
54
|
+
* 这段时间进度条停在 100%,窗口重新加载还会让镜像只解压出一半。
|
|
55
|
+
*
|
|
56
|
+
* extract-zip 不保留压缩包里记录的修改时间,解出来的文件都是解压那一刻的时间。镜像要不要更新
|
|
57
|
+
* (isLocalImageNeedUpdate)和设备管理里的构建时间都看 nuttx 的修改时间:解压时间晚于新版本日期的旧镜像
|
|
58
|
+
* 会被当成最新的,构建时间也显示成下载时间。所以解压完按压缩包里的时间设回去,和 adm-zip 解压的结果一致。
|
|
59
|
+
*/
|
|
60
|
+
async function extractZipTo(zipFile, targetDir) {
|
|
61
|
+
const dir = _path.default.resolve(targetDir);
|
|
62
|
+
const mtimes = [];
|
|
63
|
+
await (0, _extractZip.default)(zipFile, {
|
|
64
|
+
dir,
|
|
65
|
+
onEntry: entry => {
|
|
66
|
+
// 目录项以 / 结尾,只处理文件
|
|
67
|
+
if (!entry.fileName.endsWith('/')) {
|
|
68
|
+
mtimes.push({
|
|
69
|
+
file: _path.default.join(dir, entry.fileName),
|
|
70
|
+
mtime: entry.getLastModDate()
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
for (const {
|
|
76
|
+
file,
|
|
77
|
+
mtime
|
|
78
|
+
} of mtimes) {
|
|
79
|
+
try {
|
|
80
|
+
// 跳过符号链接,免得改到它指向的文件
|
|
81
|
+
if ((await _fs.default.promises.lstat(file)).isFile()) await _fs.default.promises.utimes(file, mtime, mtime);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
_ColorConsole.default.info(`set mtime of ${file} failed: ${e}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
40
87
|
const EAvdParamsToIni = {
|
|
41
88
|
arm: {
|
|
42
89
|
abiType: 'armeabi-v7a'
|
|
@@ -63,8 +110,7 @@ exports.isHeadlessEnvironment = isHeadlessEnvironment;
|
|
|
63
110
|
class VvdManager {
|
|
64
111
|
// 需要复制的文件
|
|
65
112
|
binFiles = ['system.img', 'data.img', 'coredump.core', 'vela_data.bin', 'vela_resource.bin', 'vela_system.bin'];
|
|
66
|
-
constructor() {
|
|
67
|
-
let vvdResourcePaths = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
113
|
+
constructor(vvdResourcePaths = {}) {
|
|
68
114
|
const {
|
|
69
115
|
vvdHome,
|
|
70
116
|
sdkHome
|
|
@@ -214,20 +260,33 @@ class VvdManager {
|
|
|
214
260
|
}
|
|
215
261
|
}
|
|
216
262
|
|
|
217
|
-
/**
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
263
|
+
/**
|
|
264
|
+
* 根据名字删除AVD
|
|
265
|
+
* @param vvdName 模拟器名称
|
|
266
|
+
* @param onError 删除失败时回调失败原因,返回值仍是 false
|
|
267
|
+
*/
|
|
268
|
+
deleteVvd(vvdName, onError) {
|
|
221
269
|
try {
|
|
270
|
+
const vvdDir = this.getVvdDir(vvdName);
|
|
271
|
+
const vvdIni = _path.default.resolve(this.vvdHome, `${vvdName}.ini`);
|
|
272
|
+
// 模拟器运行后会把 data/misc/pstore/pstore.bin 设成只读,IDE 的 Electron 里 fs.rmSync
|
|
273
|
+
// 碰到只读文件会整个失败(EPERM),重试也没用,所以先去掉只读属性
|
|
274
|
+
if (process.platform === 'win32' && _fs.default.existsSync(vvdDir)) clearReadonly(vvdDir);
|
|
275
|
+
// Windows 上模拟器刚退出、杀毒软件扫描镜像文件时,文件会被短暂占用(EBUSY/EPERM),
|
|
276
|
+
// 不重试的话这次删除直接失败
|
|
222
277
|
_fs.default.rmSync(vvdDir, {
|
|
223
278
|
recursive: true,
|
|
224
|
-
force: true
|
|
279
|
+
force: true,
|
|
280
|
+
maxRetries: 5,
|
|
281
|
+
retryDelay: 100
|
|
225
282
|
});
|
|
226
283
|
_fs.default.rmSync(vvdIni, {
|
|
227
284
|
force: true
|
|
228
285
|
});
|
|
229
286
|
return true;
|
|
230
287
|
} catch (e) {
|
|
288
|
+
_ColorConsole.default.error(`delete ${vvdName} failed:`, String(e));
|
|
289
|
+
onError?.(e);
|
|
231
290
|
return false;
|
|
232
291
|
}
|
|
233
292
|
}
|
|
@@ -235,6 +294,9 @@ class VvdManager {
|
|
|
235
294
|
/** 获取已经创建的模拟器列表 */
|
|
236
295
|
getVvdList() {
|
|
237
296
|
const avdList = [];
|
|
297
|
+
if (!_fs.default.existsSync(this.vvdHome)) {
|
|
298
|
+
return avdList;
|
|
299
|
+
}
|
|
238
300
|
const files = _fs.default.readdirSync(this.vvdHome);
|
|
239
301
|
const regex = /^([\d\D]*)\.(avd|vvd)$/;
|
|
240
302
|
for (const fileName of files) {
|
|
@@ -665,6 +727,18 @@ class VvdManager {
|
|
|
665
727
|
imageType
|
|
666
728
|
});
|
|
667
729
|
} else {
|
|
730
|
+
// 已经启动完成却查不到自己的注册信息,IDE 会把它当成启动失败。把当时目录里的注册文件和
|
|
731
|
+
// 过滤后留下的记下来,才能看出是文件不在、进程判成已退出,还是被同端口、同名的另一条挡掉了
|
|
732
|
+
const files = (0, _emulatorutil.getRunningAvdConfigFiles)().map(f => {
|
|
733
|
+
try {
|
|
734
|
+
const c = (0, _ini.parse)(_fs.default.readFileSync(f, 'utf-8'));
|
|
735
|
+
return `${_path.default.basename(f)}(${c['avd.name']}@${c['port.serial']})`;
|
|
736
|
+
} catch {
|
|
737
|
+
return _path.default.basename(f);
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
const kept = (0, _emulatorutil.getRunningAvdConfig)().map(c => `${c['avd.name']}@${c['port.serial']}`);
|
|
741
|
+
logger(`${vvdName} booted but has no running registration; files: ${files.join(', ') || 'none'}; kept: ${kept.join(', ') || 'none'}`);
|
|
668
742
|
reject('get emulator running config failed');
|
|
669
743
|
}
|
|
670
744
|
}
|
|
@@ -688,15 +762,14 @@ class VvdManager {
|
|
|
688
762
|
});
|
|
689
763
|
return promise;
|
|
690
764
|
}
|
|
691
|
-
stopVvd(name) {
|
|
692
|
-
let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10 * 1000;
|
|
765
|
+
stopVvd(name, timeout = 10 * 1000) {
|
|
693
766
|
return new Promise((resolve, reject) => {
|
|
694
767
|
const config = (0, _emulatorutil.getRunningAvdConfigByName)(name);
|
|
695
768
|
if (!config) {
|
|
696
769
|
return resolve();
|
|
697
770
|
}
|
|
698
771
|
const t = setTimeout(() => {
|
|
699
|
-
(0, _utils.
|
|
772
|
+
(0, _utils.killEmulatorProcess)(config['avd.name']).then(resolve).catch(e => {
|
|
700
773
|
reject(`poweroff failed ${e}`);
|
|
701
774
|
});
|
|
702
775
|
}, timeout);
|
|
@@ -708,7 +781,7 @@ class VvdManager {
|
|
|
708
781
|
// 清理之前的文件
|
|
709
782
|
_fs.default.unlinkSync(config.path);
|
|
710
783
|
}
|
|
711
|
-
(0, _utils.
|
|
784
|
+
(0, _utils.killEmulatorProcess)(config['avd.name']).then(() => {
|
|
712
785
|
clearTimeout(t);
|
|
713
786
|
resolve();
|
|
714
787
|
}).catch(e => {
|
|
@@ -914,8 +987,8 @@ class VvdManager {
|
|
|
914
987
|
recursive: true
|
|
915
988
|
});
|
|
916
989
|
const zipFile = _path.default.resolve(this.sdkHome, _path.default.basename(u.url));
|
|
917
|
-
|
|
918
|
-
|
|
990
|
+
opt.onExtract?.(u.name);
|
|
991
|
+
await extractZipTo(zipFile, targetDir);
|
|
919
992
|
await _fs.default.promises.rm(zipFile, {
|
|
920
993
|
force: true
|
|
921
994
|
}).catch(e => {
|
|
@@ -933,7 +1006,7 @@ class VvdManager {
|
|
|
933
1006
|
}
|
|
934
1007
|
|
|
935
1008
|
/** 下载vela系统镜像 */
|
|
936
|
-
async downloadImage(imageId, opt) {
|
|
1009
|
+
async downloadImage(imageId, opt, hooks) {
|
|
937
1010
|
const downloadUrls = await (0, _constants.getImageDownloadUrl)();
|
|
938
1011
|
const u = downloadUrls[imageId];
|
|
939
1012
|
const downloader = await (await ipull).downloadFile({
|
|
@@ -947,8 +1020,8 @@ class VvdManager {
|
|
|
947
1020
|
//如果下载被取消或者出错,就不再执行后续操作
|
|
948
1021
|
if (downloader.status.downloadStatus !== 'Finished') return;
|
|
949
1022
|
const zipFile = _path.default.resolve(this.sdkHome, _Vvd.SDKParts.SYSTEM_IMAGES, _path.default.basename(u));
|
|
950
|
-
|
|
951
|
-
|
|
1023
|
+
hooks?.onExtract?.(imageId);
|
|
1024
|
+
await extractZipTo(zipFile, _path.default.resolve(this.sdkHome, _Vvd.SDKParts.SYSTEM_IMAGES, imageId));
|
|
952
1025
|
await _fs.default.promises.rm(zipFile, {
|
|
953
1026
|
force: true
|
|
954
1027
|
}).catch(e => {
|
package/lib/vvd/logcat.js
CHANGED
|
@@ -6,13 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.attachReadline = attachReadline;
|
|
7
7
|
exports.creatLogcat = creatLogcat;
|
|
8
8
|
var _readline = _interopRequireDefault(require("readline"));
|
|
9
|
-
var _adb = require("@
|
|
9
|
+
var _adb = require("@aiot-toolkit/adb");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
function creatLogcat(sn) {
|
|
12
|
-
let onStdout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : console.log;
|
|
13
|
-
let onErrout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : console.log;
|
|
14
|
-
let p = arguments.length > 3 ? arguments[3] : undefined;
|
|
15
|
-
let rls = arguments.length > 4 ? arguments[4] : undefined;
|
|
11
|
+
function creatLogcat(sn, onStdout = console.log, onErrout = console.log, p, rls) {
|
|
16
12
|
const logcatProcess = p || (0, _adb.spawnAdbCmd)('adb', ['-s', sn, 'logcat']);
|
|
17
13
|
const readlines = rls || attachReadline(logcatProcess, onStdout, onErrout);
|
|
18
14
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/emulator",
|
|
3
|
-
"version": "2.0.6-beta.
|
|
3
|
+
"version": "2.0.6-beta.29",
|
|
4
4
|
"description": "vela emulator tool.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -32,23 +32,21 @@
|
|
|
32
32
|
"emulator"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@aiot-toolkit/
|
|
35
|
+
"@aiot-toolkit/adb": "2.0.6-beta.29",
|
|
36
|
+
"@aiot-toolkit/shared-utils": "2.0.6-beta.29",
|
|
36
37
|
"@grpc/grpc-js": "^1.13.3",
|
|
37
38
|
"@grpc/proto-loader": "^0.7.13",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
39
|
+
"aedes": "^0.51.3",
|
|
40
|
+
"aedes-persistence": "^10.0.0",
|
|
40
41
|
"core-js": "^3.48.0",
|
|
41
42
|
"dayjs": "^1.11.12",
|
|
43
|
+
"extract-zip": "^2.0.1",
|
|
42
44
|
"find-process": "^1.4.7",
|
|
43
45
|
"get-port": "^7.1.0",
|
|
44
46
|
"ini": "^4.1.3",
|
|
45
47
|
"ipull": "^3.6.2",
|
|
46
48
|
"portfinder": "^1.0.32",
|
|
49
|
+
"selfsigned": "^3.0.1",
|
|
47
50
|
"semver": "^7.6.3"
|
|
48
|
-
}
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@types/adm-zip": "^0.5.5",
|
|
51
|
-
"@types/ini": "^4.1.1"
|
|
52
|
-
},
|
|
53
|
-
"gitHead": "1348e0b4f0fb3b43bc3adc4a4c5b2b0be29c680b"
|
|
51
|
+
}
|
|
54
52
|
}
|