From d5bd21ad7e710754ab2f23990fb767be274b08be Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Mon, 3 Feb 2025 14:41:09 +0300 Subject: [PATCH 1/5] CI ts loader Signed-off-by: Anton Tarasov --- .gitlab-ci.yml | 1 + arkoala/loader/.gitlab-ci.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 arkoala/loader/.gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index febaee23f..e4a1255a2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,6 +30,7 @@ include: - arkoala/.gitlab-ci.yml - arkoala/ets-plugin/.gitlab-ci.yml - arkoala/tools/peer-generator/.gitlab-ci.yml + - arkoala/loader/.gitlab-ci.yml - arkoala-arkts/.gitlab-ci.yml - arkoala-arkts/libarkts/.gitlab-ci.yml - interop/.gitlab-ci.yml diff --git a/arkoala/loader/.gitlab-ci.yml b/arkoala/loader/.gitlab-ci.yml new file mode 100644 index 000000000..af6755830 --- /dev/null +++ b/arkoala/loader/.gitlab-ci.yml @@ -0,0 +1,29 @@ +# Copyright (c) 2022-2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +test arkoala-loader: + stage: test + interruptible: true + extends: .linux-vm-shell-task + before_script: + - !reference [.setup, script] + - cd arkoala/loader + needs: + - install node modules (arkoala) + - install node modules (incremental) + - build compat + - build common + - build ets-plugin + script: + - npm i --no-audit --no-fund --prefix arkoala + - npm run compile:node-test-host --prefix arkoala/loader -- Gitee From 06b3c4d5ba70e869a9b6c8c26fdbd6068b80dc04 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Tue, 4 Feb 2025 12:21:11 +0300 Subject: [PATCH 2/5] followup Signed-off-by: Anton Tarasov --- arkoala/loader/.gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arkoala/loader/.gitlab-ci.yml b/arkoala/loader/.gitlab-ci.yml index af6755830..e951b366d 100644 --- a/arkoala/loader/.gitlab-ci.yml +++ b/arkoala/loader/.gitlab-ci.yml @@ -25,5 +25,5 @@ test arkoala-loader: - build common - build ets-plugin script: - - npm i --no-audit --no-fund --prefix arkoala - - npm run compile:node-test-host --prefix arkoala/loader + - npm i --no-audit --no-fund --prefix ../.. + - npm run compile:node-test-host -- Gitee From 2b6b5cb67f5a65ead00121fe9b8b01b562566cd9 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Tue, 4 Feb 2025 15:38:43 +0300 Subject: [PATCH 3/5] followup Signed-off-by: Anton Tarasov --- arkoala/loader/.gitlab-ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arkoala/loader/.gitlab-ci.yml b/arkoala/loader/.gitlab-ci.yml index e951b366d..06909418c 100644 --- a/arkoala/loader/.gitlab-ci.yml +++ b/arkoala/loader/.gitlab-ci.yml @@ -19,11 +19,12 @@ test arkoala-loader: - !reference [.setup, script] - cd arkoala/loader needs: - - install node modules (arkoala) - install node modules (incremental) + - install node modules (interop) + - install node modules (arkoala) - build compat - build common - build ets-plugin script: - - npm i --no-audit --no-fund --prefix ../.. - - npm run compile:node-test-host + - npm i --no-audit --no-fund + - npm run test:loader -- Gitee From 86ae71758e2227d972c52e90d4f0cfa71e1e4f3e Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Thu, 6 Feb 2025 16:56:22 +0300 Subject: [PATCH 4/5] adopt to arm64 CI agent Signed-off-by: Anton Tarasov --- arkoala/loader/.gitlab-ci.yml | 2 +- arkoala/loader/package.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arkoala/loader/.gitlab-ci.yml b/arkoala/loader/.gitlab-ci.yml index 06909418c..a4b7ea913 100644 --- a/arkoala/loader/.gitlab-ci.yml +++ b/arkoala/loader/.gitlab-ci.yml @@ -27,4 +27,4 @@ test arkoala-loader: - build ets-plugin script: - npm i --no-audit --no-fund - - npm run test:loader + - npm run test:loader:ci diff --git a/arkoala/loader/package.json b/arkoala/loader/package.json index 67306b372..b647cd4a8 100644 --- a/arkoala/loader/package.json +++ b/arkoala/loader/package.json @@ -12,12 +12,14 @@ "keywords": [], "scripts": { "test:loader": "npm run compile:node-test-host && ACE_LIBRARY_PATH=../framework/build/ node ./lib/js/loader.js", + "test:loader:ci": "npm run compile:node-test-host:ci && ACE_LIBRARY_PATH=../framework/build/ node ./lib/js/loader.js", "test:loader:unmemoizing": "npm run compile:node-test-host:unmemoizing && node ./lib/unmemoized/js/loader.js", "plugins:compile": "cd ../; npm run compile -w koala-arkui && npm run compiler:plugin:compile && npm run ets:plugin:compile", "ets": "cd src/ets; ets-tsc", "test:hzvm:loader": "npm run compile:hzvm-host", "clean": "ets-tsc -b . --clean && rimraf build dist lib generated unmemoized", "compile:node-test-host": "npm run gen-resources && npm run -C ../framework compile:native-node-host && ets-tsc -b ../extension-component && npm run ets && npm run compile:node-test", + "compile:node-test-host:ci": "npm run -C ../framework compile:native-node-host && ets-tsc -b ../extension-component && npm run ets && npm run compile:node-test", "compile:node-test-host:unmemoizing": "npm run gen-resources && npm run unmemoize --prefix ../extension-component && npm run ets && ets-tsc -b tsconfig-unmemoize.json && npm run compile:node-test:unmemoizing", "compile:node-test": "WEBPACK_NO_MINIMIZE=true webpack --config webpack.config.node-test.js", "compile:node-test:unmemoizing": "WEBPACK_NO_MINIMIZE=true webpack --config webpack.config.node-test.js --env tsconfig=tsconfig-run-unmemoized.json --env unmemoized=unmemoized", -- Gitee From 53e8ea435d418656934b63e652e40bc2a87ac4f7 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Fri, 7 Feb 2025 10:23:29 +0300 Subject: [PATCH 5/5] use gen resource template on CI Signed-off-by: Anton Tarasov --- arkoala/loader/package.json | 3 +- .../ci-templates/__resources.generated.ts | 20 +++ arkoala/loader/scripts/gen-resources.js | 122 ------------------ arkoala/loader/scripts/gen-resources.ts | 13 +- 4 files changed, 32 insertions(+), 126 deletions(-) create mode 100644 arkoala/loader/scripts/ci-templates/__resources.generated.ts delete mode 100644 arkoala/loader/scripts/gen-resources.js diff --git a/arkoala/loader/package.json b/arkoala/loader/package.json index b647cd4a8..807d639cf 100644 --- a/arkoala/loader/package.json +++ b/arkoala/loader/package.json @@ -12,14 +12,13 @@ "keywords": [], "scripts": { "test:loader": "npm run compile:node-test-host && ACE_LIBRARY_PATH=../framework/build/ node ./lib/js/loader.js", - "test:loader:ci": "npm run compile:node-test-host:ci && ACE_LIBRARY_PATH=../framework/build/ node ./lib/js/loader.js", + "test:loader:ci": "CI=true npm run compile:node-test-host && ACE_LIBRARY_PATH=../framework/build/ node ./lib/js/loader.js", "test:loader:unmemoizing": "npm run compile:node-test-host:unmemoizing && node ./lib/unmemoized/js/loader.js", "plugins:compile": "cd ../; npm run compile -w koala-arkui && npm run compiler:plugin:compile && npm run ets:plugin:compile", "ets": "cd src/ets; ets-tsc", "test:hzvm:loader": "npm run compile:hzvm-host", "clean": "ets-tsc -b . --clean && rimraf build dist lib generated unmemoized", "compile:node-test-host": "npm run gen-resources && npm run -C ../framework compile:native-node-host && ets-tsc -b ../extension-component && npm run ets && npm run compile:node-test", - "compile:node-test-host:ci": "npm run -C ../framework compile:native-node-host && ets-tsc -b ../extension-component && npm run ets && npm run compile:node-test", "compile:node-test-host:unmemoizing": "npm run gen-resources && npm run unmemoize --prefix ../extension-component && npm run ets && ets-tsc -b tsconfig-unmemoize.json && npm run compile:node-test:unmemoizing", "compile:node-test": "WEBPACK_NO_MINIMIZE=true webpack --config webpack.config.node-test.js", "compile:node-test:unmemoizing": "WEBPACK_NO_MINIMIZE=true webpack --config webpack.config.node-test.js --env tsconfig=tsconfig-run-unmemoized.json --env unmemoized=unmemoized", diff --git a/arkoala/loader/scripts/ci-templates/__resources.generated.ts b/arkoala/loader/scripts/ci-templates/__resources.generated.ts new file mode 100644 index 000000000..080665a59 --- /dev/null +++ b/arkoala/loader/scripts/ci-templates/__resources.generated.ts @@ -0,0 +1,20 @@ +// THIS CODE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY + +import { __registerResources, _r, _rawfile } from "@koalaui/arkoala-arkui"; + +const bundleName: string = "ohos.arkoala"; +const moduleName: string = "arkoala-loader"; +const resources: Record = { + "string.MainAbility_desc": 16777216, + "string.MainAbility_label": 16777217, + "string.Video_src": 16777218, + "string.entry_desc": 16777219, + "string.text_label_1": 16777220, + "color.white": 16777221, + "media.icon": 16777222, + "profile.main_pages": 16777223 +}; + +__registerResources(bundleName, moduleName, resources); +export function $r(name: string, ...args: any[]) { return _r(name, ...args) }; +export function $rawfile(name: string) { return _rawfile(name) }; diff --git a/arkoala/loader/scripts/gen-resources.js b/arkoala/loader/scripts/gen-resources.js deleted file mode 100644 index 98c78f51e..000000000 --- a/arkoala/loader/scripts/gen-resources.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict"; -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -Object.defineProperty(exports, "__esModule", { value: true }); -const fs = require("fs"); -const path = require("path"); -const child_process_1 = require("child_process"); -process.on("uncaughtException", e => { - console.error(e.message || e); - process.exit(1); -}); -const ohosSdkPath = findOhosSdk(); -const srcPath = path.resolve("src"); -const buildDir = path.resolve("build"); -const generatedDir = path.resolve("generated/ets"); -const buildResourceDir = path.join(buildDir, "resources"); -console.log("OHOS SDK at ", ohosSdkPath); -const PACKAGE_NAME = "ohos.arkoala"; -runRestool(srcPath, buildResourceDir, PACKAGE_NAME); // TODO remove hardcoded values -let moduleInfo = readModuleManifest(path.join(buildResourceDir, "module.json")); // TODO generated module.json differs from DevEco, run generator -let entries = readResourceTable(path.join(buildResourceDir, "ResourceTable.txt")); -writeTypescriptSource(path.join(generatedDir, "__resources.generated.ts"), moduleInfo, entries); -function readResourceTable(filepath) { - let content = fs.readFileSync(filepath, "utf-8").trim(); - let lines = content.split(/(\r?\n)+/gm); - let entries = []; - for (const line of lines) { - let items = line.trim().split(/\s+/g); - if (items.length === 0 || items[0] === "") - continue; - if (items.length !== 3) { - throw new Error(`Illegal resource table format (at line '${items}')`); - } - const [type, name, idStr] = items; - if (!/^0x[0-9A-Fa-f]{8}$/i.test(idStr)) { // int32 in hex, 0xFFFFFFFF - throw new Error(`Illegal resource id: ${idStr}`); - } - const id = parseInt(idStr, 16); - entries.push({ type, name, id }); - } - return entries; -} -function readModuleManifest(filepath) { - var _a, _b; - let json = fs.readFileSync(filepath, "utf-8").trim(); - let manifest = JSON.parse(json); - let moduleName = manifest.module.name; - let bundleName = (_b = (_a = manifest.app) === null || _a === void 0 ? void 0 : _a.bundleName) !== null && _b !== void 0 ? _b : PACKAGE_NAME; // TODO remove hardcoded constant - return { moduleName, bundleName }; -} -function makeResourceMap(resources) { - let output = {}; - for (const { type, name, id } of resources) { - let key = type + "." + name; - if (key in output) { - throw new Error(`Duplicated resource key: ${key}`); - } - output[key] = id; - } - return output; -} -function writeTypescriptSource(filepath, module, resources, options = {}) { - var _a; - const importString = (_a = options.arkoalaImport) !== null && _a !== void 0 ? _a : "@koalaui/arkoala-arkui"; - const resourceMap = makeResourceMap(resources); - fs.mkdirSync(path.dirname(filepath), { recursive: true }); - let out = fs.createWriteStream(filepath, "utf-8"); - out.write(`// THIS CODE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n`); - out.write(`import { __registerResources, _r, _rawfile } from ${JSON.stringify(importString)};\n\n`); - out.write(`const bundleName: string = ${JSON.stringify(module.bundleName)};\n`); - out.write(`const moduleName: string = ${JSON.stringify(module.moduleName)};\n`); - out.write(`const resources: Record = ${JSON.stringify(resourceMap, null, 4)};\n\n`); - out.write(`__registerResources(bundleName, moduleName, resources);\n`); - out.write(`export function $r(name: string, ...args: any[]) { return _r(name, ...args) };\n`); - out.write(`export function $rawfile(name: string) { return _rawfile(name) };\n`); - out.end(); -} -function runRestool(srcDir, destDir, packageName, startIdMask = 0x01000000) { - var _a; - let restoolExe = path.join(ohosSdkPath, "toolchains/restool" + (process.platform === "win32" ? ".exe" : "")); - let src = (_a = process.env["ETS_RESOURCES_SRC"]) !== null && _a !== void 0 ? _a : path.resolve(srcDir); - let dst = path.resolve(destDir); - fs.mkdirSync(dst, { recursive: true }); - let headerPath = path.join(dst, "ResourceTable.h"); - let startId = "0x" + startIdMask.toString(16).toUpperCase().padStart(8, "0"); - const restoolArgs = ["-i", src, "-o", dst, "-p", packageName, "-r", headerPath, "-e", startId, "-f"]; - console.log("-------------- restool -------------------"); - console.log(restoolExe, restoolArgs.join(" ")); - let result = (0, child_process_1.spawnSync)(restoolExe, restoolArgs, { - stdio: "inherit" - }); - console.log("-------------- restool -------------------"); -} -function findOhosSdk() { - const API_VERSION = "11"; - if (process.env["HOS_SDK_HOME"]) { - return path.resolve(process.env["HOS_SDK_HOME"]); - } - let repositoryPath = path.resolve("../ohos-sdk/ohos-sdk/HarmonyOS-NEXT-DB1/openharmony"); - if (fs.existsSync(repositoryPath)) { - return repositoryPath; - } - if (process.env["LOCALAPPDATA"]) { - let osDefaultPath = path.join(process.env["LOCALAPPDATA"], "OpenHarmony/Sdk/" + API_VERSION); - if (fs.existsSync(osDefaultPath)) { - return osDefaultPath; - } - } - throw new Error("No OHOS SDK found, please provide HOS_SDK_HOME variable set to OpenHarmony SDK 10 directory path"); -} diff --git a/arkoala/loader/scripts/gen-resources.ts b/arkoala/loader/scripts/gen-resources.ts index b902532d4..2773d0b5f 100644 --- a/arkoala/loader/scripts/gen-resources.ts +++ b/arkoala/loader/scripts/gen-resources.ts @@ -26,8 +26,18 @@ const ohosSdkPath = findOhosSdk() const srcPath = path.resolve("src") const buildDir = path.resolve("build") const generatedDir = path.resolve("generated/ets") +const generatedFile = "__resources.generated.ts" const buildResourceDir = path.join(buildDir, "resources") +if (process.env.CI) { + const generatedFileTemplatePath = path.join(__dirname, "ci-templates", generatedFile) + // restool is not currently runnable on CI due to arch mismatch + console.warn("warning: use predefined template", generatedFileTemplatePath) + fs.mkdirSync(generatedDir, { recursive: true }) + fs.copyFileSync(generatedFileTemplatePath, path.join(generatedDir, generatedFile)) + process.exit(0) +} + console.log("OHOS SDK at ", ohosSdkPath) const PACKAGE_NAME = "ohos.arkoala" @@ -37,8 +47,7 @@ runRestool(srcPath, buildResourceDir, PACKAGE_NAME) // TODO remove hardcoded val let moduleInfo = readModuleManifest(path.join(buildResourceDir, "module.json")) // TODO generated module.json differs from DevEco, run generator let entries = readResourceTable(path.join(buildResourceDir, "ResourceTable.txt")) -writeTypescriptSource(path.join(generatedDir, "__resources.generated.ts"), moduleInfo, entries); - +writeTypescriptSource(path.join(generatedDir, generatedFile), moduleInfo, entries); interface ResourceTableEntry { type: string -- Gitee