diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index febaee23fc1e2427a685ec355daaf3597dd886be..e4a1255a29a74d32c40a577bc297da72e1698bb0 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 0000000000000000000000000000000000000000..a4b7ea91330952a77d37d016a0311cd760ef6b23 --- /dev/null +++ b/arkoala/loader/.gitlab-ci.yml @@ -0,0 +1,30 @@ +# 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 (incremental) + - install node modules (interop) + - install node modules (arkoala) + - build compat + - build common + - build ets-plugin + script: + - npm i --no-audit --no-fund + - npm run test:loader:ci diff --git a/arkoala/loader/package.json b/arkoala/loader/package.json index 67306b3725801e62c5ea91f4de4f01f8cf1354bf..807d639cf58390143be692d792b08f80412f8e98 100644 --- a/arkoala/loader/package.json +++ b/arkoala/loader/package.json @@ -12,6 +12,7 @@ "keywords": [], "scripts": { "test:loader": "npm run compile:node-test-host && 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", 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 0000000000000000000000000000000000000000..080665a599cb2c6a10b2bae74b358f5dd0792c2d --- /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 98c78f51ee4a47980854ce243980ea9356e7e91e..0000000000000000000000000000000000000000 --- 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 b902532d4ea6d387ecf8c332ed1f2a3a24191d05..2773d0b5f07251200780481ee99b89d138f07b0e 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