diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 73d7b7a7d31722c9d6bcf0086a32be22c4dd3480..b0bc6f05881b15bd1e828ebfbd47338af34f71e4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,7 @@ stages: - test - idlize - build-with-idlize + - pack workflow: rules: @@ -21,6 +22,7 @@ include: - incremental/runtime/.gitlab-ci.yml - incremental/demo-playground/.gitlab-ci.yml - arkoala/tools/peer-generator/.gitlab-ci.yml + - arkoala-arkts/.gitlab-ci.yml - arkoala-arkts/loader/.gitlab-ci.yml unmemoize arkoala-arkts/arkui: diff --git a/arkoala-arkts/.gitlab-ci.yml b/arkoala-arkts/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..ad34ea986d6985f5c7d077ac363e804bb187e777 --- /dev/null +++ b/arkoala-arkts/.gitlab-ci.yml @@ -0,0 +1,15 @@ +pack arkoala-arkts har-arm32 (linux): + stage: pack + interruptible: true + extends: + - .linux-vm-shell-task + needs: [] + script: + - !reference [.setup, script] + - npm run panda:sdk:install --prefix arkoala-arkts + - npm run trivial:all:har-arm32 --prefix arkoala-arkts + - cp $CI_PROJECT_DIR/arkoala-arkts/har/app/arkoala/build/default/outputs/default/arkoala.har $CI_PROJECT_DIR/arkoala-arkts.har + artifacts: + expire_in: 1 day + paths: + - arkoala-arkts.har diff --git a/arkoala-arkts/har/package.json b/arkoala-arkts/har/package.json index 59f47e1de4b490821e7274dee651f8d9b088adaa..e83080ba7194b59d67b2bfff349b78644aa0e3af 100644 --- a/arkoala-arkts/har/package.json +++ b/arkoala-arkts/har/package.json @@ -24,8 +24,8 @@ "native:build-arm32": "npm run --prefix ../../arkoala/framework compile:native-panda-with-hzvm-ohos-arm32", "bundle": "node scripts/build-arkoala-har.mjs --arch arm", "build": "npm run cli-tools:check && cd app && DEVECO_SDK_HOME=../../../arkoala/ohos-sdk/ohos-sdk ../command-line-tools/hvigor/bin/hvigorw --no-daemon --mode module -p product=default -p module=arkoala@default assembleHar", - "arkoala:har": "npm run bundle && npm run build", - "arkoala:har-arm32": "npm run bundle && npm run build", + "arkoala:har": "npm run --prefix ../../arkoala/ohos-sdk download && npm run bundle && npm run build", + "arkoala:har-arm32": "npm run --prefix ../../arkoala/ohos-sdk download && npm run bundle && npm run build", "all": "npm run native:clean && npm run compile:arkoala && npm run native:build && npm run arkoala:har", "all-arm32": "npm run native:clean && npm run compile:arkoala-arkts && npm run native:build-arm32 && npm run arkoala:har-arm32", "cli-tools:chmod:bz": "node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", diff --git a/arkoala-arkts/har/scripts/build-arkoala-har.mjs b/arkoala-arkts/har/scripts/build-arkoala-har.mjs index bc6a7b2fdce772cb2cb5feadf7fa39057e3fa80e..e3f847fcd5c62265bf0e296a5725452dba3de59a 100644 --- a/arkoala-arkts/har/scripts/build-arkoala-har.mjs +++ b/arkoala-arkts/har/scripts/build-arkoala-har.mjs @@ -15,7 +15,6 @@ const _dirname = dirname(fileURLToPath(import.meta.url)) const OHOS_SDK_PATH = process.env.HOS_SDK_HOME ?? path.join(_dirname, `../../../arkoala/ohos-sdk/ohos-sdk`) const NATIVE_SDK_PATH = path.join(OHOS_SDK_PATH, `HarmonyOS-NEXT-DB1/openharmony/native`) -const LIBCSHARED_PATH = path.join(NATIVE_SDK_PATH, `llvm/lib/${arch}-linux-ohos/libc++_shared.so`) const CWD = process.cwd() const BUNDLE_PATH = path.join(CWD, "arkoala-har-bundle") @@ -44,7 +43,7 @@ function main() { rollupLaunch() /* we don't yet know which files should be in har */ - copyFilesToHar(LIBCSHARED_PATH, path.join(HAR_PATH, `libs/armeabi-v7a/libc++_shared.so`)) + copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/build/libc++.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libc++.so`)) copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/native/build-hzvm-ohos-arm32-vmloader/libArkoalaLoader.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libArkoalaLoader.so`)) copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/native/build-hzvm-ohos-arm32-vmloader/libvmloader.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libvmloader.so`)) copyFilesToHar(path.join(_dirname, `../../../arkoala/framework/native/build-panda-ohos-arm32/libArkoalaNative_ark.so`), path.join(HAR_PATH, `libs/armeabi-v7a/libArkoalaNative_ark.so`)) diff --git a/arkoala/framework/package.json b/arkoala/framework/package.json index c9ae2443f5346f0bfd5744f71970a8750f045538..9b7843d47716a9ca58f1ff384802ea3bf82721d8 100644 --- a/arkoala/framework/package.json +++ b/arkoala/framework/package.json @@ -23,6 +23,9 @@ "@types/node": "^18.0.0" }, "scripts": { + "prepare:compiler": "test $(node -e \"console.log(process.platform)\") != \"linux\" && npm run --prefix ../ohos-sdk download || npm run install:toolchain --prefix ../tools/compiler", + "prepare:arm64": "npm run prepare:compiler && npm run install:sysroot:arm64 --prefix ../tools/compiler", + "prepare:arm32": "npm run prepare:compiler && npm run install:sysroot:arm32 --prefix ../tools/compiler", "clean": "memo-tsc -b . --clean && rimraf -g build dist lib generated native/build-* *.ini", "configure:native-node-host": "cd native && meson setup -D vm_kind=node build-node-host", "compile:native-node-host": "npm run configure:native-node-host && cd native && meson compile -C build-node-host && meson install -C build-node-host", @@ -32,22 +35,22 @@ "compile:native-panda-host": "npm run configure:native-panda-host && cd native && meson compile -C build-panda-host && meson install -C build-panda-host", "configure:native-jvm-host": "cd native && meson setup -D vm_kind=jvm build-jvm-host -D jdk_dir=$JAVA_HOME", "compile:native-jvm-host": "npm run configure:native-jvm-host && cd native && meson compile -C build-jvm-host && meson install -C build-jvm-host", - "configure:native-hzvm-ohos-arm64": "npm run --prefix ../ohos-sdk download && cd native && node ../scripts/configure.mjs hzvm-ohos-arm64", + "configure:native-hzvm-ohos-arm64": "npm run prepare:arm64 && cd native && node ../scripts/configure.mjs hzvm-ohos-arm64", "compile:native-hzvm-ohos-arm64": "npm run configure:native-hzvm-ohos-arm64 && cd native && meson compile -C build-hzvm-ohos-arm64 && meson install -C build-hzvm-ohos-arm64", - "configure:native-hzvm-ohos-arm32": "npm run --prefix ../ohos-sdk download && cd native && node ../scripts/configure.mjs hzvm-ohos-arm32", + "configure:native-hzvm-ohos-arm32": "npm run prepare:arm32 && cd native && node ../scripts/configure.mjs hzvm-ohos-arm32", "compile:native-hzvm-ohos-arm32": "npm run configure:native-hzvm-ohos-arm32 && cd native && meson compile -C build-hzvm-ohos-arm32 && meson install -C build-hzvm-ohos-arm32", "configure:native-hzvm-ohos": "npm run configure:native-hzvm-ohos-arm64", "compile:native-hzvm-ohos": "memo-tsc -b . && npm run compile:native-hzvm-ohos-arm64", - "configure:native-panda-ohos-arm64": "npm run --prefix ../ohos-sdk download && cd native && node ../scripts/configure.mjs panda-ohos-arm64", + "configure:native-panda-ohos-arm64": "npm run prepare:arm64 && cd native && node ../scripts/configure.mjs panda-ohos-arm64", "compile:native-panda-ohos-arm64": "npm run configure:native-panda-ohos-arm64 && cd native && meson compile -C build-panda-ohos-arm64 && meson install -C build-panda-ohos-arm64", - "configure:native-panda-ohos-arm32": "npm run --prefix ../ohos-sdk download && cd native && node ../scripts/configure.mjs panda-ohos-arm32", + "configure:native-panda-ohos-arm32": "npm run prepare:arm32 && cd native && node ../scripts/configure.mjs panda-ohos-arm32", "compile:native-panda-ohos-arm32": "npm run configure:native-panda-ohos-arm32 && cd native && meson compile -C build-panda-ohos-arm32 && meson install -C build-panda-ohos-arm32", "configure:native-panda-with-node-host": "npm run configure:native-panda-host && cd native && meson setup -D vm_kind=node -D vmloader=true -D arkoala=false build-node-host-vmloader", "compile:native-panda-with-node-host": "npm run configure:native-panda-with-node-host && cd native && npm run compile:native-panda-host && meson compile -C build-node-host-vmloader && meson install -C build-node-host-vmloader", "configure:native-panda-with-hzvm-ohos-arm64": "npm run configure:native-panda-ohos-arm64 && cd native && node ../scripts/configure.mjs hzvm-ohos-arm64-vmloader", - "compile:native-panda-with-hzvm-ohos-arm64": "npm run configure:native-panda-with-hzvm-ohos-arm64 && npm run compile:native-panda-ohos-arm64 && cd native && meson compile -C build-hzvm-ohos-arm64-vmloader && meson install -C build-hzvm-ohos-arm64-vmloader", + "compile:native-panda-with-hzvm-ohos-arm64": "npm run configure:native-panda-with-hzvm-ohos-arm64 && npm run compile:native-panda-ohos-arm64 && cd native && meson compile -C build-hzvm-ohos-arm64-vmloader && meson install -C build-hzvm-ohos-arm64-vmloader && npm run copy:libcpp:arm64 --prefix ../../tools/compiler", "configure:native-panda-with-hzvm-ohos-arm32": "npm run configure:native-panda-ohos-arm32 && cd native && node ../scripts/configure.mjs hzvm-ohos-arm32-vmloader", - "compile:native-panda-with-hzvm-ohos-arm32": "npm run configure:native-panda-with-hzvm-ohos-arm32 && npm run compile:native-panda-ohos-arm32 && cd native && meson compile -C build-hzvm-ohos-arm32-vmloader && meson install -C build-hzvm-ohos-arm32-vmloader", + "compile:native-panda-with-hzvm-ohos-arm32": "npm run configure:native-panda-with-hzvm-ohos-arm32 && npm run compile:native-panda-ohos-arm32 && cd native && meson compile -C build-hzvm-ohos-arm32-vmloader && meson install -C build-hzvm-ohos-arm32-vmloader && npm run copy:libcpp:arm32 --prefix ../../tools/compiler", "compile:node-host": "memo-tsc -b . && npm run compile:native-node-host", "compile": "npm run compile:node-host", "compile:hzvm-host": "memo-tsc -b . && npm run compile:native-hzvm-host", diff --git a/arkoala/framework/scripts/configure.mjs b/arkoala/framework/scripts/configure.mjs index feba326ebd4f9762207b2a6682ae90904b8a475f..02aa3cd07f0c58ea9bc1951877002298a25ca765 100644 --- a/arkoala/framework/scripts/configure.mjs +++ b/arkoala/framework/scripts/configure.mjs @@ -271,16 +271,21 @@ function createAndroidCrossFile(target) { function createOhosCrossFile(target) { let cf = CrossFile(target, root); - let sdkNativePath = ohSdkInfo(OHCONF.sdkPath(), OH_SDK_COMPONENT.native).path + let sdkNativePath = "" let compilersPath = "" let suffix = "" if (platform == 'win32') { suffix = ".exe"; } - compilersPath = path.join(sdkNativePath, "llvm", "bin"); + if (platform == 'linux') { + compilersPath = path.resolve('../../tools/compiler/llvm-toolchain/bin') + } else { + sdkNativePath = ohSdkInfo(OHCONF.sdkPath(), OH_SDK_COMPONENT.native).path + compilersPath = path.join(sdkNativePath, "llvm", "bin") + } let cflags = [ - '--sysroot=' + path.resolve(path.join(sdkNativePath, 'sysroot')) + '--sysroot=' + path.resolve(`../../tools/compiler/sysroot-${ target.includes('arm64') ? 'arm64' : 'arm' }`) ] let cpu = 'unknown' if (target == 'hzvm-ohos-arm64' || target == 'hzvm-ohos-arm64-vmloader' || target == 'panda-ohos-arm64') { diff --git a/arkoala/har/package.json b/arkoala/har/package.json index 6b6df362d93179675466335cb9fa78a3c9fb931a..4e48bea77c8bf041a2fcb16df90a277c82b4a7b6 100644 --- a/arkoala/har/package.json +++ b/arkoala/har/package.json @@ -26,8 +26,8 @@ "native:build-arm32": "npm run --prefix ../framework compile:native-hzvm-ohos-arm32", "bundle": "node scripts/build-arkoala-har.mjs", "build": "npm run cli-tools:check && cd app && DEVECO_SDK_HOME=../../ohos-sdk/ohos-sdk ../command-line-tools/hvigor/bin/hvigorw --no-daemon --mode module -p product=default -p module=arkoala@default assembleHar", - "arkoala:har": "npm run copy && npm run bundle && npm run build", - "arkoala:har-arm32": "npm run copy:arm32 && npm run bundle && npm run build", + "arkoala:har": "npm run --prefix ../../arkoala/ohos-sdk download && npm run copy && npm run bundle && npm run build", + "arkoala:har-arm32": "npm run --prefix ../../arkoala/ohos-sdk download && npm run copy:arm32 && npm run bundle && npm run build", "all": "npm run native:clean && npm run compile:arkoala && npm run native:build && npm run arkoala:har", "all-arm32": "npm run native:clean && npm run compile:arkoala && npm run native:build-arm32 && npm run arkoala:har-arm32", "cli-tools:chmod:bz": "node ../ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", diff --git a/arkoala/tools/compiler/.gitignore b/arkoala/tools/compiler/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6079007102878aab5cd97e3ac5b2b75f44860aa3 --- /dev/null +++ b/arkoala/tools/compiler/.gitignore @@ -0,0 +1,3 @@ +llvm-toolchain +sysroot-arm +sysroot-arm64 diff --git a/arkoala/tools/compiler/install.mjs b/arkoala/tools/compiler/install.mjs new file mode 100644 index 0000000000000000000000000000000000000000..54b1f41dda360b6ddbafca645c826011e2df71ab --- /dev/null +++ b/arkoala/tools/compiler/install.mjs @@ -0,0 +1,67 @@ +import { existsSync } from "fs" +import path from "path" +import chalk from "chalk" + +function log(msg) { + console.log(chalk.green(msg)) +} + +const platform_resolve = (() => { + switch (process.platform) { + case "linux": return "linux" + default: throw new Error(`Unsupported platform ${process.platform}`) + } +}) + +const arch_resolve = (() => { + switch (process.arch) { + case "x64": return "x86_64" + case "arm64": return "arm64" + default: throw new Error(`Unsupported arch ${process.platform}`) + } +}) + +const generic_package_archive_resolve = (async (koala_bz) => { + switch (koala_bz) { + case 0: + const { generic_package_archive_gitlab } = await import("../../../../sdk/scripts/gitlab/gitlab.mjs") + return generic_package_archive_gitlab + case 1: + const { generic_package_archive_openlab } = await import("../../ohos-sdk/scripts/openlab.mjs") + return generic_package_archive_openlab + default: throw new Error(`Invalid koala_bz ${koala_bz}`) + } +}) + +const koala_bz = parseInt(process.env.KOALA_BZ ?? "0") +const generic_package_archive = await generic_package_archive_resolve(koala_bz) + +if (process.argv[2] == 'toolchain') { + const llvm_toolchain = `llvm-toolchain-${platform_resolve()}_${arch_resolve()}` + if (existsSync("./llvm-toolchain")) { + log(`> ${llvm_toolchain} is already installed at ${ path.resolve("./llvm-toolchain") }`) + } else { + generic_package_archive( + "compiler", + "1.0.0", + `${llvm_toolchain}.tar.gz`, + path.resolve("./llvm-toolchain") + ) + } +} + +if (process.argv[2] == 'sysroot') { + const sysroot_arm = `sysroot-arm` + const sysroot_arm64 = `sysroot-arm64` + const sysroot = process.argv[3] == 'arm64' ? sysroot_arm64 : sysroot_arm + if (existsSync(`./${sysroot}`)) { + log(`> ${sysroot} is already installed at ${ path.resolve(`./${sysroot}`) }`) + } else { + generic_package_archive( + "compiler", + "1.0.0", + `${sysroot}.tar.gz`, + path.resolve(`./${sysroot}`) + ) + } +} diff --git a/arkoala/tools/compiler/package.json b/arkoala/tools/compiler/package.json new file mode 100644 index 0000000000000000000000000000000000000000..e7701b8d708e24a8306fe4bae59195cc69aedeab --- /dev/null +++ b/arkoala/tools/compiler/package.json @@ -0,0 +1,12 @@ +{ + "name": "compiler-installer", + "version": "1.0.0", + "description": "", + "scripts": { + "install:toolchain": "node install.mjs toolchain", + "install:sysroot:arm64": "node install.mjs sysroot arm64", + "install:sysroot:arm32": "node install.mjs sysroot arm32", + "copy:libcpp:arm64": "cp sysroot-arm64/libc++.so ../../framework/build", + "copy:libcpp:arm32": "cp sysroot-arm/libc++.so ../../framework/build" + } +} \ No newline at end of file diff --git a/arkoala/tools/peer-generator/.gitlab-ci.yml b/arkoala/tools/peer-generator/.gitlab-ci.yml index 341aa76710ed6d7e8ed8d30e31e21a1068be72e4..a144582e854fe54d05777bc2a07c7337c818266d 100644 --- a/arkoala/tools/peer-generator/.gitlab-ci.yml +++ b/arkoala/tools/peer-generator/.gitlab-ci.yml @@ -5,10 +5,10 @@ Idlize generate arkoala/arkui (linux): extends: - .linux-vm-shell-task needs: [] - script: + before_script: - !reference [.setup, script] - - KOALA_BZ=1 OPENLAB_USERNAME=koala-ci OPENLAB_PASSWORD=w1llUgu3ss npm run ohos-sdk --prefix arkoala/arkui-common - - npm i --prefix arkoala/tools/peer-generator + - KOALA_BZ=1 npm run ohos-sdk --prefix arkoala/arkui-common + script: - npm run generate:ts --prefix arkoala/tools/peer-generator artifacts: paths: @@ -24,8 +24,9 @@ Build generated arkoala/arkui (linux): - .linux-vm-shell-task needs: - Idlize generate arkoala/arkui (linux) - script: + before_script: - !reference [.setup, script] + script: - npm run compile --prefix arkoala/arkui artifacts: paths: @@ -40,12 +41,13 @@ Build generated ArkoalaNative (linux, linux, node): - .linux-vm-shell-task needs: - Idlize generate arkoala/arkui (linux) - script: + before_script: - !reference [.setup, script] + script: - npm run compile:native-node-host --prefix arkoala/framework artifacts: paths: - - arkoala/framework/build/ArkoalaNative_linux_x64.node + - arkoala/framework/build/ArkoalaNative_linux_arm64.node - arkoala/framework/build/libace_compatible_mock.so expire_in: 1 day @@ -57,9 +59,10 @@ Build generated ArkoalaNative (linux, ohos-arm64, hzvm): - .linux-vm-shell-task needs: - Idlize generate arkoala/arkui (linux) - script: + before_script: - !reference [.setup, script] - - KOALA_BZ=1 OPENLAB_USERNAME=koala-ci OPENLAB_PASSWORD=w1llUgu3ss npm run compile:native-hzvm-ohos-arm64 --prefix arkoala/framework + script: + - KOALA_BZ=1 npm run compile:native-hzvm-ohos-arm64 --prefix arkoala/framework artifacts: paths: - arkoala/framework/build/libArkoalaNative.so @@ -73,9 +76,10 @@ Build generated ArkoalaNative (linux, ohos-arm32, hzvm): - .linux-vm-shell-task needs: - Idlize generate arkoala/arkui (linux) - script: + before_script: - !reference [.setup, script] - - KOALA_BZ=1 OPENLAB_USERNAME=koala-ci OPENLAB_PASSWORD=w1llUgu3ss npm run compile:native-hzvm-ohos-arm32 --prefix arkoala/framework + script: + - KOALA_BZ=1 npm run compile:native-hzvm-ohos-arm32 --prefix arkoala/framework artifacts: paths: - arkoala/framework/build/libArkoalaNative.so @@ -88,10 +92,10 @@ Idlize generate arkoala-arkts/arkui (linux): extends: - .linux-vm-shell-task needs: [] - script: + before_script: - !reference [.setup, script] - - KOALA_BZ=1 OPENLAB_USERNAME=koala-ci OPENLAB_PASSWORD=w1llUgu3ss npm run ohos-sdk --prefix arkoala/arkui-common - - npm i --prefix arkoala/tools/peer-generator + - KOALA_BZ=1 npm run ohos-sdk --prefix arkoala/arkui-common + script: - npm run generate:arkts --prefix arkoala/tools/peer-generator artifacts: paths: @@ -107,9 +111,10 @@ Build generated arkoala-arkts/arkui (linux): - .linux-vm-shell-task needs: - Idlize generate arkoala-arkts/arkui (linux) - script: + before_script: - !reference [.setup, script] - npm run panda:sdk:install --prefix arkoala-arkts + script: - npm run compile:arkts:unmemoized --prefix arkoala-arkts/arkui || npm run compile:trivial --prefix arkoala-arkts/arkui # TODO: remove trivial artifacts: paths: @@ -124,14 +129,15 @@ Build generated ArkoalaNative (linux, linux, node+panda): - .linux-vm-shell-task needs: - Idlize generate arkoala-arkts/arkui (linux) - script: + before_script: - !reference [.setup, script] + script: - npm run compile:native-panda-with-node-host --prefix arkoala/framework artifacts: paths: - arkoala/framework/build/ArkoalaLoader.node - arkoala/framework/build/libvmloader.so - - arkoala/framework/build/libArkoalaNative_linux_x64_ark.so + - arkoala/framework/build/libArkoalaNative_linux_arm64_ark.so - arkoala/framework/build/libace_compatible_mock.so expire_in: 1 day @@ -143,12 +149,14 @@ Build generated ArkoalaNative (linux, ohos-arm32, hzvm+panda): - .linux-vm-shell-task needs: - Idlize generate arkoala-arkts/arkui (linux) - script: + before_script: - !reference [.setup, script] - - KOALA_BZ=1 OPENLAB_USERNAME=koala-ci OPENLAB_PASSWORD=w1llUgu3ss npm run compile:native-hzvm-ohos-arm32 --prefix arkoala/framework + script: + - KOALA_BZ=1 npm run compile:native-hzvm-ohos-arm32 --prefix arkoala/framework artifacts: paths: - arkoala/framework/build/libArkoalaLoader.so - arkoala/framework/build/libvmloader.so - arkoala/framework/build/libArkoalaNative_ark.so + - arkoala/framework/build/libc++.so expire_in: 1 day diff --git a/gitlab/setup.yml b/gitlab/setup.yml index a8f79b844f7d419d4121a5e371abbb792a4983ee..925df0d61a42eca7afc37adda5df071aa38cb138 100644 --- a/gitlab/setup.yml +++ b/gitlab/setup.yml @@ -13,7 +13,6 @@ - cd arkoala && npm i --no-audit --no-fund && cd .. - cd arkoala-arkts && npm i --no-audit --no-fund && cd .. - cd interop && npm i --no-audit --no-fund && cd .. - - KOALA_BZ=1 npm run ohos-sdk --prefix arkoala/arkui-common cd - .linux-vm-shell-task: tags: diff --git a/interop/src/cpp/ohos/hilog/log.h b/interop/src/cpp/ohos/hilog/log.h new file mode 100644 index 0000000000000000000000000000000000000000..7452137c280d212fc271cca2f31466f0dc11bd6f --- /dev/null +++ b/interop/src/cpp/ohos/hilog/log.h @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2021-2022 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. + */ + +#ifndef HIVIEWDFX_HILOG_H +#define HIVIEWDFX_HILOG_H +/** + * @addtogroup HiLog + * @{ + * + * @brief Provides logging functions. + * + * For example, you can use these functions to output logs of the specified log type, service domain, log tag, + * and log level. + * + * @syscap SystemCapability.HiviewDFX.HiLog + * + * @since 8 + */ + +/** + * @file log.h + * + * @brief Defines the logging functions of the HiLog module. + * + * Before outputting logs, you must define the service domain, and log tag, use the function with + * the specified log type and level, and specify the privacy identifier.\n + * \n + * + * Sample code:\n + * Defining the service domain and log tag:\n + * #include \n + * #define LOG_DOMAIN 0x0201\n + * #define LOG_TAG "MY_TAG"\n + * Outputting logs:\n + * HILOG_WARN({@link LOG_APP}, "Failed to visit %{private}s, reason:%{public}d.", url, errno);\n + * Output result:\n + * 05-06 15:01:06.870 1051 1051 W 0201/MY_TAG: Failed to visit , reason:503.\n + * + * @since 8 + */ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the service domain for a log file. + * + * The service domain is used to identify the subsystem and module of a service. Its value is a hexadecimal integer + * ranging from 0x0 to 0xFFFF. If the value is beyond the range, its significant bits are automatically truncated. \n + * + * @since 8 + */ +#ifndef LOG_DOMAIN +#define LOG_DOMAIN 0 +#endif + +/** + * @brief Defines a string constant used to identify the class, file, or service. + * + * @since 8 + */ +#ifndef LOG_TAG +#define LOG_TAG NULL +#endif + +/** + * @brief Enumerates log types. + * + * Currently, LOG_APP is available. \n + * + * @since 8 + */ +typedef enum { + /** Third-party application logs */ + LOG_APP = 0, +} LogType; + +/** + * @brief Enumerates log levels. + * + * You are advised to select log levels based on their respective usage scenarios:\n + *
  • DEBUG: used for debugging and disabled from commercial releases
  • \n + *
  • INFO: used for logging important system running status and steps in key processes
  • \n + *
  • WARN: used for logging unexpected exceptions that have little impact on user experience and can + * automatically recover. Logs at this level are generally output when such exceptions are detected and + * captured.
  • \n + *
  • ERROR: used for logging malfunction that affects user experience and cannot automatically + * recover
  • \n + *
  • FATAL: used for logging major exceptions that have severely affected user experience and should + * not occur.
\n + * + * @since 8 + */ +typedef enum { + /** Debug level to be used by {@link OH_LOG_DEBUG} */ + LOG_DEBUG = 3, + /** Informational level to be used by {@link OH_LOG_INFO} */ + LOG_INFO = 4, + /** Warning level to be used by {@link OH_LOG_WARN} */ + LOG_WARN = 5, + /** Error level to be used by {@link OH_LOG_ERROR} */ + LOG_ERROR = 6, + /** Fatal level to be used by {@link OH_LOG_FATAL} */ + LOG_FATAL = 7, +} LogLevel; + +/** + * @brief Outputs logs. + * + * You can use this function to output logs based on the specified log type, log level, service domain, log tag, + * and variable parameters determined by the format specifier and privacy identifier in the printf format. + * + * @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}. + * @param level Indicates the log level, which can be LOG_DEBUG, LOG_INFO, LOG_WARN, + * LOG_ERROR, and LOG_FATAL. + * @param domain Indicates the service domain of logs. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. + * @param tag Indicates the log tag, which is a string used to identify the class, file, or service behavior. + * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy + * identifier. Specifically, {public} or {private} is added between the % character and the format specifier + * in each parameter. \n + * @param ... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers + * in the format string. + * @return Returns 0 or a larger value if the operation is successful; returns a value smaller + * than 0 otherwise. + * @since 8 + */ +int OH_LOG_Print(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) + __attribute__((__format__(os_log, 5, 6))); + +/** + * @brief Checks whether logs of the specified service domain, log tag, and log level can be output. + * + * @param domain Indicates the service domain of logs. + * @param tag Indicates the log tag. + * @param level Indicates the log level. + * @return Returns true if the specified logs can be output; returns false otherwise. + * @since 8 + */ +bool OH_LOG_IsLoggable(unsigned int domain, const char *tag, LogLevel level); + +/** + * @brief Outputs debug logs. This is a function-like macro. + * + * Before calling this function, define the log service domain and log tag. Generally, you need to define them at + * the beginning of the source file. \n + * + * @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}. + * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the + * privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier + * in each parameter. \n + * @param ... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers + * in the format string. + * @see OH_LOG_Print + * @since 8 + */ +#define OH_LOG_DEBUG(type, ...) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +/** + * @brief Outputs informational logs. This is a function-like macro. + * + * Before calling this function, define the log service domain and log tag. Generally, you need to define them + * at the beginning of the source file. \n + * + * @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}. + * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy + * identifier. Specifically, {public} or {private} is added between the % character and the format specifier in + * each parameter. \n + * @param ... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers + * in the format string. + * @see OH_LOG_Print + * @since 8 + */ +#define OH_LOG_INFO(type, ...) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +/** + * @brief Outputs warning logs. This is a function-like macro. + * + * Before calling this function, define the log service domain and log tag. Generally, you need to define them + * at the beginning of the source file. \n + * + * @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}. + * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the + * privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier + * in each parameter. \n + * @param ... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers + * in the format string. + * @see OH_LOG_Print + * @since 8 + */ +#define OH_LOG_WARN(type, ...) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +/** + * @brief Outputs error logs. This is a function-like macro. + * + * Before calling this function, define the log service domain and log tag. Generally, you need to define + * them at the beginning of the source file. \n + * + * @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}. + * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy + * identifier. Specifically, {public} or {private} is added between the % character and the format specifier in each + * parameter. \n + * @param ... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers + * in the format string. + * @see OH_LOG_Print + * @since 8 + */ +#define OH_LOG_ERROR(type, ...) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +/** + * @brief Outputs fatal logs. This is a function-like macro. + * + * Before calling this function, define the log service domain and log tag. Generally, you need to define them at + * the beginning of the source file. \n + * + * @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}. + * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the privacy + * identifier. Specifically, {public} or {private} is added between the % character and the format specifier in + * each parameter. \n + * @param ... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers + * in the format string. + * @see OH_LOG_Print + * @since 8 + */ +#define OH_LOG_FATAL(type, ...) ((void)OH_LOG_Print((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +/** + * @brief Defines the function pointer type for the user-defined log processing function. + * + * @param type Indicates the log type. The type for third-party applications is defined by {@link LOG_APP}. + * @param level Indicates the log level, which can be LOG_DEBUG, LOG_INFO, LOG_WARN, + * LOG_ERROR, and LOG_FATAL. + * @param domain Indicates the service domain of logs. Its value is a hexadecimal integer ranging from 0x0 to 0xFFFF. + * @param tag Indicates the log tag, which is a string used to identify the class, file, or service behavior. + * @param msg Indicates the log message itself, which is a formatted log string. + * @since 11 + */ +typedef void (*LogCallback)(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg); + +/** + * @brief Set the user-defined log processing function. + * + * After calling this function, the callback function implemented by the user can receive all hilogs of the + * current process. + * Note that it will not change the default behavior of hilog logs of the current process, no matter whether this + * interface is called or not. \n + * + * @param callback Indicates the callback function implemented by the user. If you do not need to process hilog logs, + * you can transfer a null pointer. + * @since 11 + */ +void OH_LOG_SetCallback(LogCallback callback); + +#ifdef __cplusplus +} +#endif +/** @} */ + +#ifdef HILOG_RAWFORMAT +#include "hilog/log_inner.h" +#endif + +#endif // HIVIEWDFX_HILOG_C_H