Skip to content

Commit

Permalink
ohos: add signing and install steps
Browse files Browse the repository at this point in the history
Signed-off-by: Mukilan Thiyagarajan <[email protected]>
  • Loading branch information
mukilan committed Sep 11, 2024
1 parent 86860d9 commit cb19f76
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
uses: ./.github/workflows/ohos.yml
with:
profile: "release"
secrets: inherit

build-result:
name: Result
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/ohos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ jobs:
run: sudo apt update && python3 ./mach bootstrap --skip-lints
- name: Setup OpenHarmony SDK
id: setup_sdk
uses: openharmony-rs/[email protected] # TODO: this needs to be updated
uses: mukilan/[email protected].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
Expand All @@ -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 }}
Expand All @@ -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
6 changes: 0 additions & 6 deletions python/servo/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
9 changes: 8 additions & 1 deletion python/servo/package_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.")
Expand All @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions python/servo/platform/build_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Any, Dict, Optional

import servo.platform
import servo.util as util


class BuildTarget(object):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions support/openharmony/hvigor/hvigor-config.json5
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
35 changes: 34 additions & 1 deletion support/openharmony/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -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. */
Expand Down
1 change: 1 addition & 0 deletions support/openharmony/oh-package.json5
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"modelVersion": "5.0.0",
"license": "MPL",
"devDependencies": {
"@ohos/hypium": "1.0.6"
Expand Down

0 comments on commit cb19f76

Please sign in to comment.