aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo
diff options
context:
space:
mode:
authorMukilan Thiyagarajan <mukilan@igalia.com>2024-09-20 13:50:27 +0530
committerGitHub <noreply@github.com>2024-09-20 08:20:27 +0000
commit157e28c59b34ec8c7334161fda658cbbb1e66a25 (patch)
treea4f2b9b57f1c3b30333a97fb3831973c110fad99 /python/servo
parent457d37d94ee6966cad377c373d333a00c637e1ae (diff)
downloadservo-157e28c59b34ec8c7334161fda658cbbb1e66a25.tar.gz
servo-157e28c59b34ec8c7334161fda658cbbb1e66a25.zip
openharmony: add servoshell for ohos (#33295)
* openharmony: add servoshell for ohos Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> * ohos: handle missing signing config on forks Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> --------- Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Diffstat (limited to 'python/servo')
-rw-r--r--python/servo/command_base.py33
-rw-r--r--python/servo/package_commands.py63
-rw-r--r--python/servo/platform/build_target.py25
3 files changed, 112 insertions, 9 deletions
diff --git a/python/servo/command_base.py b/python/servo/command_base.py
index 4359d1c74ca..6513a1b150a 100644
--- a/python/servo/command_base.py
+++ b/python/servo/command_base.py
@@ -297,6 +297,7 @@ class CommandBase(object):
self.config.setdefault("build", {})
self.config["build"].setdefault("android", False)
+ self.config["build"].setdefault("ohos", False)
self.config["build"].setdefault("mode", "")
self.config["build"].setdefault("debug-assertions", False)
self.config["build"].setdefault("debug-mozjs", False)
@@ -328,12 +329,6 @@ class CommandBase(object):
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():
@@ -551,7 +546,12 @@ class CommandBase(object):
CommandArgument(
'--android', default=None, action='store_true',
help='Build for Android. If --target is not specified, this '
- 'will choose a default target architecture.',
+ f'will choose the default target architecture ({AndroidTarget.DEFAULT_TRIPLE}).',
+ ),
+ CommandArgument(
+ '--ohos', default=None, action='store_true',
+ help='Build for OpenHarmony. If --target is not specified, this '
+ f'will choose a default target architecture ({OpenHarmonyTarget.DEFAULT_TRIPLE}).',
),
CommandArgument('--win-arm64', action='store_true', help="Use arm64 Windows target"),
CommandArgumentGroup('Feature Selection'),
@@ -646,6 +646,7 @@ class CommandBase(object):
self.configure_build_target(kwargs, suppress_log=True)
kwargs.pop('target', False)
kwargs.pop('android', False)
+ kwargs.pop('ohos', False)
return original_function(self, *args, **kwargs)
return target_configuration_decorator
@@ -686,15 +687,28 @@ class CommandBase(object):
return
android = kwargs.get('android') or self.config["build"]["android"]
+ ohos = kwargs.get('ohos') or self.config["build"]["ohos"]
target_triple = kwargs.get('target')
+ if android and ohos:
+ print("Cannot build both android and ohos targets simultaneously.")
+ sys.exit(1)
+
if android and target_triple:
print("Please specify either --target or --android.")
sys.exit(1)
# Set the default Android target
if android and not target_triple:
- target_triple = "aarch64-linux-android"
+ target_triple = AndroidTarget.DEFAULT_TRIPLE
+
+ if ohos and target_triple:
+ print("Please specify either --target or --ohos.")
+ sys.exit(1)
+
+ # Set the default OpenHarmony target
+ if ohos and not target_triple:
+ target_triple = OpenHarmonyTarget.DEFAULT_TRIPLE
self.target = BuildTarget.from_triple(target_triple)
@@ -705,6 +719,9 @@ class CommandBase(object):
def is_android(self):
return isinstance(self.target, AndroidTarget)
+ def is_openharmony(self):
+ return isinstance(self.target, OpenHarmonyTarget)
+
def is_media_enabled(self, media_stack: Optional[str]):
"""Determine whether media is enabled based on the value of the build target
platform and the value of the '--media-stack' command-line argument.
diff --git a/python/servo/package_commands.py b/python/servo/package_commands.py
index 4b2bef89c01..cad2a73f275 100644
--- a/python/servo/package_commands.py
+++ b/python/servo/package_commands.py
@@ -35,6 +35,7 @@ from servo.command_base import (
archive_deterministically,
BuildNotFound,
cd,
+ check_output,
CommandBase,
is_windows,
)
@@ -124,6 +125,10 @@ class PackageCommands(CommandBase):
default=None,
action='store_true',
help='Package Android')
+ @CommandArgument('--ohos',
+ default=None,
+ action='store_true',
+ help='Package OpenHarmony')
@CommandArgument('--target', '-t',
default=None,
help='Package for given target platform')
@@ -178,6 +183,55 @@ class PackageCommands(CommandBase):
except subprocess.CalledProcessError as e:
print("Packaging Android exited with return value %d" % e.returncode)
return e.returncode
+ elif self.is_openharmony():
+ # hvigor doesn't support an option to place output files in a specific directory
+ # so copy the source files into the target/openharmony directory first.
+ ohos_app_dir = path.join(self.get_top_dir(), "support", "openharmony")
+ build_mode = build_type.directory_name()
+ ohos_target_dir = path.join(
+ self.get_top_dir(), "target", "openharmony", self.target.triple(), build_mode)
+ if path.exists(ohos_target_dir):
+ print("Cleaning up from previous packaging")
+ delete(ohos_target_dir)
+ shutil.copytree(ohos_app_dir, ohos_target_dir)
+
+ # Map non-debug profiles to 'release' buildMode HAP.
+ if build_type.is_custom():
+ build_mode = "release"
+
+ hvigor_command = ["--no-daemon", "assembleHap", "-p", "product=default", "-p", f"buildMode={build_mode}"]
+ # Detect if PATH already has hvigor, or else fallback to npm installation
+ # provided via HVIGOR_PATH
+ if "HVIGOR_PATH" not in env:
+ try:
+ with cd(ohos_target_dir):
+ version = check_output(["hvigorw", "--version", "--no-daemon"])
+ print(f"Found `hvigorw` with version {str(version, 'utf-8').strip()} in system PATH")
+ hvigor_command[0:0] = ["hvigorw"]
+ except FileNotFoundError:
+ print("Unable to find `hvigor` tool. Please either modify PATH to include the"
+ "path to hvigorw or set the HVIGOR_PATH environment variable to the npm"
+ "installation containing `node_modules` directory with hvigor modules.")
+ sys.exit(1)
+ else:
+ env["NODE_PATH"] = env["HVIGOR_PATH"] + "/node_modules"
+ hvigor_script = f"{env['HVIGOR_PATH']}/node_modules/@ohos/hvigor/bin/hvigor.js"
+ hvigor_command[0:0] = ["node", hvigor_script]
+
+ abi_string = self.target.abi_string()
+ ohos_libs_dir = path.join(ohos_target_dir, "entry", "libs", abi_string)
+ os.makedirs(ohos_libs_dir)
+ # The libservoshell.so binary that was built needs to be copied
+ # into the app folder heirarchy where hvigor expects it.
+ print(f"Copying {binary_path} to {ohos_libs_dir}")
+ shutil.copy(binary_path, ohos_libs_dir)
+ try:
+ with cd(ohos_target_dir):
+ print("Calling", hvigor_command)
+ subprocess.check_call(hvigor_command, env=env)
+ except subprocess.CalledProcessError as e:
+ print("Packaging OpenHarmony exited with return value %d" % e.returncode)
+ return e.returncode
elif 'darwin' in self.target.triple():
print("Creating Servo.app")
dir_to_dmg = path.join(target_dir, 'dmg')
@@ -347,6 +401,9 @@ class PackageCommands(CommandBase):
@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')
@@ -376,7 +433,7 @@ class PackageCommands(CommandBase):
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.")
@@ -386,6 +443,10 @@ class PackageCommands(CommandBase):
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 bf795386b5a..ecdb6c71c13 100644
--- a/python/servo/platform/build_target.py
+++ b/python/servo/platform/build_target.py
@@ -21,6 +21,7 @@ from packaging.version import parse as parse_version
from typing import Any, Dict, Optional
import servo.platform
+import servo.util as util
class BuildTarget(object):
@@ -61,6 +62,8 @@ class CrossBuildTarget(BuildTarget):
class AndroidTarget(CrossBuildTarget):
+ DEFAULT_TRIPLE = "aarch64-linux-android"
+
def ndk_configuration(self) -> Dict[str, str]:
target = self.triple()
config = {}
@@ -237,8 +240,16 @@ class AndroidTarget(CrossBuildTarget):
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):
+ DEFAULT_TRIPLE = "aarch64-unknown-linux-ohos"
+
def configure_build_environment(self, env: Dict[str, str], config: Dict[str, Any], topdir: pathlib.Path):
# Paths to OpenHarmony SDK and build tools:
# Note: `OHOS_SDK_NATIVE` is the CMake variable name the `hvigor` build-system
@@ -370,3 +381,17 @@ class OpenHarmonyTarget(CrossBuildTarget):
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",
+ "x86_64-unknown-linux-ohos": "x86_64"
+ }
+ return abi_map[self.triple()]