mach: Split out post build tasks into their own command (#38853)

The main reason for this change is that this makes working on this part
of the build a lot easier.

Testing: No tests for this change as it just rearranges code in the
build scripts.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-08-22 11:21:15 -07:00 committed by GitHub
parent d7c55c50c5
commit f1a5da6836
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -154,18 +154,45 @@ class MachCommands(CommandBase):
status = self.run_cargo_build_like_command("rustc", opts, env=env, verbose=verbose, **kwargs)
if status == 0:
built_binary = self.get_binary_path(build_type, sanitizer=sanitizer)
if not no_package and self.target.needs_packaging():
rv = Registrar.dispatch(
return_value = Registrar.dispatch(
"package", context=self.context, build_type=build_type, flavor=flavor, sanitizer=sanitizer
)
if rv:
return rv
if return_value:
return return_value
return_value = self.run_post_build_tasks(build_type, sanitizer)
if return_value:
return return_value
# Print how long the build took
elapsed = time() - build_start
elapsed_delta = datetime.timedelta(seconds=int(elapsed))
build_message = f"{'Succeeded' if status == 0 else 'Failed'} in {elapsed_delta}"
print(build_message)
assert isinstance(status, int)
return status
@Command("run-post-build-tasks", description="Run only the post-build tasks", category="build")
@CommandBase.common_command_arguments(build_configuration=True, build_type=True)
def run_post_build_tasks_cmd(
self,
build_type: BuildType,
sanitizer: SanitizerKind = SanitizerKind.NONE,
**_kwargs: Any,
) -> int:
return self.run_post_build_tasks(build_type, sanitizer)
def run_post_build_tasks(self, build_type: BuildType, sanitizer: SanitizerKind = SanitizerKind.NONE) -> int:
target_triple = self.target.triple()
built_binary = self.get_binary_path(build_type, sanitizer=sanitizer)
binary_dir = os.path.dirname(built_binary)
assert os.path.exists(binary_dir)
if "windows" in target_triple:
if not copy_windows_dlls_to_build_directory(built_binary, self.target):
status = 1
return 1
elif "darwin" in target_triple:
servo_bin_dir = os.path.dirname(built_binary)
@ -187,14 +214,7 @@ class MachCommands(CommandBase):
Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(icon, built_binary, 0)
except ImportError:
pass
# Print how long the build took
elapsed = time() - build_start
elapsed_delta = datetime.timedelta(seconds=int(elapsed))
build_message = f"{'Succeeded' if status == 0 else 'Failed'} in {elapsed_delta}"
print(build_message)
assert isinstance(status, int)
return status
return 0
@Command("clean", description="Clean the target/ and Python virtual environment directories", category="build")
@CommandArgument("--manifest-path", default=None, help="Path to the manifest to the package to clean")