mach: introduce BuildTarget abstraction (#33114)

Introduce a new `BuildTarget` abstraction to centralize the code for
supporting different ways of choosing the build target (e.g --android,
--target x86_64-linux-android , --target aarch64-linux-ohos). This
is currently handled in an adhoc fashion in different commands (
mach package, install, run) leading to a proliferation of keyword
parameters for the commands and duplicated logic.

The patch introduces a new `allow_target_configuration` decorator to
do the validation and parsing of these parameters into the appropriate
`BuildTarget` subclass, which is now stored as an instance attribute
of the CommandBase class. All the code that previously relied on
`self.cross_compile_target` has been switched to use the BuildTarget.

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
Mukilan Thiyagarajan 2024-08-26 18:38:21 +05:30 committed by GitHub
parent 4397d8a021
commit b6d5ac09b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 519 additions and 510 deletions

View file

@ -321,12 +321,10 @@ class MachCommands(CommandBase):
)
return self._test_wpt(build_type=build_type, android=True, **kwargs)
def _test_wpt(self, build_type: BuildType, with_asan=False, android=False, **kwargs):
if not android:
os.environ.update(self.build_env())
@CommandBase.allow_target_configuration
def _test_wpt(self, build_type: BuildType, with_asan=False, **kwargs):
# TODO(mrobinson): Why do we pass the wrong binary path in when running WPT on Android?
binary_path = self.get_binary_path(build_type=build_type, asan=with_asan)
binary_path = self.get_binary_path(build_type, asan=with_asan)
return_value = wpt.run.run_tests(binary_path, **kwargs)
return return_value if not kwargs["always_succeed"] else 0
@ -388,7 +386,6 @@ class MachCommands(CommandBase):
avd = "servo-x86"
target = "i686-linux-android"
print("Assuming --target " + target)
self.cross_compile_target = target
env = self.build_env()
os.environ["PATH"] = env["PATH"]