From cb19f76e779afba897cb9fe8b4da9fd6a6216f43 Mon Sep 17 00:00:00 2001 From: Mukilan Thiyagarajan Date: Wed, 11 Sep 2024 14:29:11 +0530 Subject: [PATCH] ohos: add signing and install steps Signed-off-by: Mukilan Thiyagarajan --- .github/workflows/main.yml | 1 + .github/workflows/ohos.yml | 19 ++++++---- python/servo/command_base.py | 6 ---- python/servo/package_commands.py | 9 ++++- python/servo/platform/build_target.py | 14 ++++++++ .../openharmony/hvigor/hvigor-config.json5 | 3 +- support/openharmony/hvigorfile.ts | 35 ++++++++++++++++++- support/openharmony/oh-package.json5 | 1 + 8 files changed, 72 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 446d4f36ef3e1..1975a65345418 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,6 +57,7 @@ jobs: uses: ./.github/workflows/ohos.yml with: profile: "release" + secrets: inherit build-result: name: Result diff --git a/.github/workflows/ohos.yml b/.github/workflows/ohos.yml index 15ae7c240ed90..cc3588e3af7ee 100644 --- a/.github/workflows/ohos.yml +++ b/.github/workflows/ohos.yml @@ -52,11 +52,10 @@ jobs: run: sudo apt update && python3 ./mach bootstrap --skip-lints - name: Setup OpenHarmony SDK id: setup_sdk - uses: openharmony-rs/setup-ohos-sdk@v0.1 # TODO: this needs to be updated + uses: mukilan/setup-ohos-sdk@v0.1.11 # TODO: this needs to be updated with: version: "4.1" - components: "native;toolchains;ets" - cache: false + components: "native;toolchains;ets;js;previewer" fixup-path: true - name: Install node for hvigor uses: actions/setup-node@v4 @@ -67,12 +66,20 @@ jobs: mkdir ~/hvigor-installation cd ~/hvigor-installation echo "@ohos:registry=https://repo.harmonyos.com/npm/" > .npmrc - npm install "@ohos/hvigor@4" "@ohos/hvigor-ohos-plugin@4" + npm install "@ohos/hvigor@5" "@ohos/hvigor-ohos-plugin@5" echo "HVIGOR_PATH=$PWD" >> $GITHUB_ENV + - name: "Setup HAP signing config" + env: + SIGNING_MATERIAL: ${{ secrets.SERVO_OHOS_SIGNING_MATERIAL }} + run: | + cd ~ + echo "${SIGNING_MATERIAL}" | base64 -d > servo-ohos-material.zip + unzip servo-ohos-material.zip + echo "SERVO_OHOS_SIGNING_CONFIG=${PWD}/servo-ohos-material/signing-configs.json" >> $GITHUB_ENV - name: Build (arch ${{ matrix.arch }} profile ${{ inputs.profile }}) env: OHOS_SDK_NATIVE: ${{ steps.setup_sdk.outputs.ohos_sdk_native }} - OHOS_BASE_SDK_HOME: ${{ steps.setup_sdk.outputs.ohos_sdk_native }} + OHOS_BASE_SDK_HOME: ${{ steps.setup_sdk.outputs.ohos-base-sdk-home }} run: | python3 ./mach build --locked --target ${{ matrix.arch }} --${{ inputs.profile }} cp -r target/cargo-timings target/cargo-timings-ohos-${{ matrix.arch }} @@ -86,4 +93,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: ${{ inputs.profile }}-binary-ohos-${{ matrix.arch }} - path: target/openharmony/${{ matrix.arch }}/${{ inputs.profile }}/entry/build/default/outputs/default/servoshell-default-unsigned.hap + path: target/openharmony/${{ matrix.arch }}/${{ inputs.profile }}/entry/build/default/outputs/default/servoshell-default-signed.hap diff --git a/python/servo/command_base.py b/python/servo/command_base.py index 69161de6549c8..ef58246940ab8 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -329,12 +329,6 @@ def rust_toolchain(self): def get_top_dir(self): return self.context.topdir - def get_apk_path(self, build_type: BuildType): - base_path = util.get_target_dir() - base_path = path.join(base_path, "android", self.target.triple()) - apk_name = "servoapp.apk" - return path.join(base_path, build_type.directory_name(), apk_name) - def get_binary_path(self, build_type: BuildType, asan: bool = False): base_path = util.get_target_dir() if asan or self.target.is_cross_build(): diff --git a/python/servo/package_commands.py b/python/servo/package_commands.py index 4deb27073d186..2621286d178a2 100644 --- a/python/servo/package_commands.py +++ b/python/servo/package_commands.py @@ -401,6 +401,9 @@ def package(self, build_type: BuildType, flavor=None, with_asan=False): @CommandArgument('--android', action='store_true', help='Install on Android') + @CommandArgument('--ohos', + action='store_true', + help='Install on OpenHarmony') @CommandArgument('--emulator', action='store_true', help='For Android, install to the only emulated device') @@ -430,7 +433,7 @@ def install(self, build_type: BuildType, emulator=False, usb=False, with_asan=Fa return 1 if self.is_android(): - pkg_path = self.get_apk_path(build_type) + pkg_path = self.target.get_package_path(build_type.directory_name()) exec_command = [self.android_adb_path(env)] if emulator and usb: print("Cannot install to both emulator and USB at the same time.") @@ -440,6 +443,10 @@ def install(self, build_type: BuildType, emulator=False, usb=False, with_asan=Fa if usb: exec_command += ["-d"] exec_command += ["install", "-r", pkg_path] + elif self.is_openharmony(): + pkg_path = self.target.get_package_path(build_type.directory_name()) + hdc_path = path.join(env["OHOS_SDK_NATIVE"], "../", "toolchains", "hdc") + exec_command = [hdc_path, "install", "-r", pkg_path] elif is_windows(): pkg_path = path.join(path.dirname(binary_path), 'msi', 'Servo.msi') exec_command = ["msiexec", "/i", pkg_path] diff --git a/python/servo/platform/build_target.py b/python/servo/platform/build_target.py index a94a3ca0831a7..39c87558edf82 100644 --- a/python/servo/platform/build_target.py +++ b/python/servo/platform/build_target.py @@ -21,6 +21,7 @@ from typing import Any, Dict, Optional import servo.platform +import servo.util as util class BuildTarget(object): @@ -237,6 +238,12 @@ def is_cross_build(self) -> bool: def needs_packaging(self) -> bool: return True + def get_package_path(self, build_type_directory: str) -> str: + base_path = util.get_target_dir() + base_path = path.join(base_path, "android", self.triple()) + apk_name = "servoapp.apk" + return path.join(base_path, build_type_directory, apk_name) + class OpenHarmonyTarget(CrossBuildTarget): def configure_build_environment(self, env: Dict[str, str], config: Dict[str, Any], topdir: pathlib.Path): @@ -371,6 +378,13 @@ def binary_name(self) -> str: def needs_packaging(self) -> bool: return True + def get_package_path(self, build_type_directory: str) -> str: + base_path = util.get_target_dir() + base_path = path.join(base_path, "openharmony", self.triple()) + hap_name = "servoshell-default-signed.hap" + build_output_path = path.join("entry", "build", "default", "outputs", "default") + return path.join(base_path, build_type_directory, build_output_path, hap_name) + def abi_string(self) -> str: abi_map = { "aarch64-unknown-linux-ohos": "arm64-v8a", diff --git a/support/openharmony/hvigor/hvigor-config.json5 b/support/openharmony/hvigor/hvigor-config.json5 index 2cddebd747bdd..9bb1d298f8540 100644 --- a/support/openharmony/hvigor/hvigor-config.json5 +++ b/support/openharmony/hvigor/hvigor-config.json5 @@ -1,7 +1,6 @@ { - "modelVersion": "4.1.2", + "modelVersion": "5.0.0", "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" }, "execution": { // "daemon": true, /* Enable daemon compilation. Default: true */ diff --git a/support/openharmony/hvigorfile.ts b/support/openharmony/hvigorfile.ts index f3cb9f1a87a81..b0b1a4e17ebff 100644 --- a/support/openharmony/hvigorfile.ts +++ b/support/openharmony/hvigorfile.ts @@ -1,4 +1,37 @@ -import { appTasks } from '@ohos/hvigor-ohos-plugin'; +import { appTasks, OhosAppContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin'; +import { getNode } from '@ohos/hvigor' +import * as fs from 'fs'; +import * as path from 'path'; + +// Obtain the root node. +const rootNode = getNode(__filename); +// Add an afterNodeEvaluate hook to the root node to modify the build-profile.json5 file. +rootNode.afterNodeEvaluate(node => { + // Obtain the context object of the app plug-in. + const appContext = node.getContext(OhosPluginId.OHOS_APP_PLUGIN) as OhosAppContext; + // Obtain the obj object read from the build-profile.json5 file through the context object. + const buildProfileOpt = appContext.getBuildProfileOpt(); + // Modify the obj object as required. In this example, signingConfigs in app is updated. + const signingConfigsPath = process.env["SERVO_OHOS_SIGNING_CONFIG"]; + if (signingConfigsPath) { + if (!fs.existsSync(signingConfigsPath)) { + // TODO + return; + } + const basePath = path.dirname(signingConfigsPath); + const signingConfigs = JSON.parse(fs.readFileSync(signingConfigsPath)); + for (const config of signingConfigs) { + config.material.certpath = path.resolve(basePath, config.material.certpath); + config.material.profile = path.resolve(basePath, config.material.profile); + config.material.storeFile = path.resolve(basePath, config.material.storeFile); + } + buildProfileOpt['app']['signingConfigs'] = signingConfigs; + } else { + console.log('Signing config not set in enviroment.') + } + // Set the obj object back to the context object to enable the build process and results. + appContext.setBuildProfileOpt(buildProfileOpt); +}) export default { system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ diff --git a/support/openharmony/oh-package.json5 b/support/openharmony/oh-package.json5 index ded7e6ff04128..c05c1d9e7e20d 100644 --- a/support/openharmony/oh-package.json5 +++ b/support/openharmony/oh-package.json5 @@ -1,4 +1,5 @@ { + "modelVersion": "5.0.0", "license": "MPL", "devDependencies": { "@ohos/hypium": "1.0.6"