ohos: Support product flavors (#33512)

* ohos: Support product flavors

Support different product flavors (e.g. with different signing
configurations) by supporting --flavor on ohos.
The flavor influences the package path for OH packages, so
allow the flavor parameter on build + package + install

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* Fix smoketest

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
This commit is contained in:
Jonathan Schwender 2024-09-26 08:58:30 +02:00 committed by GitHub
parent a97afebdcc
commit 7fdaccde55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 14 deletions

View file

@ -59,7 +59,7 @@ class MachCommands(CommandBase):
help="Command-line arguments to be passed through to Cargo")
@CommandBase.common_command_arguments(build_configuration=True, build_type=True)
def build(self, build_type: BuildType, jobs=None, params=None, no_package=False,
verbose=False, very_verbose=False, with_asan=False, **kwargs):
verbose=False, very_verbose=False, with_asan=False, flavor=None, **kwargs):
opts = params or []
if build_type.is_release():
@ -134,7 +134,7 @@ class MachCommands(CommandBase):
built_binary = self.get_binary_path(build_type, asan=with_asan)
if not no_package and self.target.needs_packaging():
rv = Registrar.dispatch("package", context=self.context, build_type=build_type, flavor=None)
rv = Registrar.dispatch("package", context=self.context, build_type=build_type, flavor=flavor)
if rv:
return rv

View file

@ -531,7 +531,11 @@ class CommandBase(object):
help='Build in release mode without debug assertions'),
CommandArgument('--profile', group="Build Type",
help='Build with custom Cargo profile'),
CommandArgument('--with-asan', action='store_true', help="Build with AddressSanitizer")
CommandArgument('--with-asan', action='store_true', help="Build with AddressSanitizer"),
CommandArgument(
'--flavor', default=None, group="Build Type",
help='Product flavor to be used when packaging with Gradle/Hvigor (android/ohos).'
),
]
if build_configuration:

View file

@ -132,9 +132,6 @@ class PackageCommands(CommandBase):
@CommandArgument('--target', '-t',
default=None,
help='Package for given target platform')
@CommandArgument('--flavor', '-f',
default=None,
help='Package using the given Gradle flavor')
@CommandBase.common_command_arguments(build_configuration=False, build_type=True)
@CommandBase.allow_target_configuration
def package(self, build_type: BuildType, flavor=None, with_asan=False):
@ -203,7 +200,13 @@ class PackageCommands(CommandBase):
if build_type.is_custom():
build_mode = "release"
hvigor_command = ["--no-daemon", "assembleHap", "-p", "product=default", "-p", f"buildMode={build_mode}"]
flavor_name = "default"
if flavor is not None:
flavor_name = flavor
hvigor_command = ["--no-daemon", "assembleHap",
"-p", f"product={flavor_name}",
"-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:
@ -419,7 +422,7 @@ class PackageCommands(CommandBase):
help='Install the given target platform')
@CommandBase.common_command_arguments(build_configuration=False, build_type=True)
@CommandBase.allow_target_configuration
def install(self, build_type: BuildType, emulator=False, usb=False, with_asan=False):
def install(self, build_type: BuildType, emulator=False, usb=False, with_asan=False, flavor=None):
env = self.build_env()
try:
binary_path = self.get_binary_path(build_type, asan=with_asan)
@ -448,7 +451,7 @@ class PackageCommands(CommandBase):
exec_command += ["-d"]
exec_command += ["install", "-r", pkg_path]
elif self.is_openharmony():
pkg_path = self.target.get_package_path(build_type.directory_name())
pkg_path = self.target.get_package_path(build_type.directory_name(), flavor=flavor)
hdc_path = path.join(env["OHOS_SDK_NATIVE"], "../", "toolchains", "hdc")
exec_command = [hdc_path, "install", "-r", pkg_path]
elif is_windows():
@ -458,7 +461,7 @@ class PackageCommands(CommandBase):
if not path.exists(pkg_path):
print("Servo package not found. Packaging servo...")
result = Registrar.dispatch(
"package", context=self.context, build_type=build_type
"package", context=self.context, build_type=build_type, flavor=flavor
)
if result != 0:
return result

View file

@ -382,11 +382,13 @@ class OpenHarmonyTarget(CrossBuildTarget):
def needs_packaging(self) -> bool:
return True
def get_package_path(self, build_type_directory: str) -> str:
def get_package_path(self, build_type_directory: str, flavor: Optional[str] = None) -> 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")
if not flavor:
flavor = "default"
build_output_path = path.join("entry", "build", flavor, "outputs", "default")
return path.join(base_path, build_type_directory, build_output_path, hap_name)
def abi_string(self) -> str:

View file

@ -806,7 +806,7 @@ tests/wpt/mozilla/tests for Servo-only tests""" % reference_path)
@CommandArgument('params', nargs='...',
help="Command-line arguments to be passed through to Servo")
@CommandBase.common_command_arguments(binary_selection=True)
def smoketest(self, servo_binary: str, params):
def smoketest(self, servo_binary: str, params, **kwargs):
# We pass `-f` here so that any thread panic will cause Servo to exit,
# preventing a panic from hanging execution. This means that these kind
# of panics won't cause timeouts on CI.