diff options
author | Delan Azabani <dazabani@igalia.com> | 2023-10-26 16:22:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-26 08:22:14 +0000 |
commit | a3d2f0c586e97e26906bd2327395186bf140f49b (patch) | |
tree | b21cbb63ae0695b93e6ef569691ef2fbbaf2b264 /python/servo/command_base.py | |
parent | 88234309b04057d7474e51131a806105032acc28 (diff) | |
download | servo-a3d2f0c586e97e26906bd2327395186bf140f49b.tar.gz servo-a3d2f0c586e97e26906bd2327395186bf140f49b.zip |
Enable debug assertions for all builds other than official releases (#30509)
* Run main and try jobs with debug assertions
* use single quotes in workflow expressions
* set force-debug-assertions in main.yml
* set force-debug-assertions as part of decision job
* fix typo in MachCommands.build
* fix more hardcoded profile names
* fix tidy
* split cargo_profile_option on windows
* Fix running servoshell and unit tests through a symlink
* rename steps to make them less confusing
* fix more hardcoded cargo profile options
* fix missing inputs in linux-wpt and mac-wpt
* make filename an inherent method of Resource
* rework release-with-debug-assertions profile to production profile
* rework resource logic to eliminate std_test_override
* set production flag in nightly release builds
* clean up servobuild.example and windows.yml
* oops forgot to check in embedder_traits/build.rs
* fix mach test-unit behaviour through symlink
* unit tests only need current_dir and ancestors
* fix macOS package smoketest breakage
* expect css/css-color/currentcolor-003 to crash under layout 2013
* fix more references to {force,release-with}-debug-assertions
* fix local build failures under --profile production
Diffstat (limited to 'python/servo/command_base.py')
-rw-r--r-- | python/servo/command_base.py | 83 |
1 files changed, 64 insertions, 19 deletions
diff --git a/python/servo/command_base.py b/python/servo/command_base.py index 137dfeea090..752cdda4474 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -7,7 +7,7 @@ # option. This file may not be copied, modified, or distributed # except according to those terms. -from __future__ import print_function +from __future__ import print_function, annotations import contextlib from enum import Enum @@ -27,6 +27,7 @@ import tarfile import urllib import zipfile +from dataclasses import dataclass from errno import ENOENT as NO_SUCH_FILE_OR_DIRECTORY from glob import glob from os import path @@ -46,10 +47,44 @@ from servo.util import download_file, get_default_cache_dir NIGHTLY_REPOSITORY_URL = "https://servo-builds2.s3.amazonaws.com/" -class BuildType(Enum): - """ The build type of this Servo build. Either `DEV` or `RELEASE`.""" - DEV = 1 - RELEASE = 2 +@dataclass +class BuildType: + class Kind(Enum): + DEV = 1 + RELEASE = 2 + CUSTOM = 3 + + kind: Kind + profile: Optional[str] + + def dev() -> BuildType: + return BuildType(BuildType.Kind.DEV, None) + + def release() -> BuildType: + return BuildType(BuildType.Kind.RELEASE, None) + + def custom(profile: str) -> BuildType: + return BuildType(BuildType.Kind.CUSTOM, profile) + + def is_dev(self) -> bool: + return self.kind == BuildType.Kind.DEV + + def is_release(self) -> bool: + return self.kind == BuildType.Kind.RELEASE + + def is_custom(self) -> bool: + return self.kind == BuildType.Kind.CUSTOM + + def directory_name(self) -> str: + if self.is_dev(): + return "debug" + elif self.is_release(): + return "release" + else: + return self.profile + + def __eq__(self, other: object) -> bool: + raise Exception("BUG: do not compare BuildType with ==") @contextlib.contextmanager @@ -290,8 +325,7 @@ class CommandBase(object): base_path = util.get_target_dir() base_path = path.join(base_path, "android", self.config["android"]["target"]) apk_name = "servoapp.apk" - build_type_string = "release" if build_type == BuildType.RELEASE else "debug" - return path.join(base_path, build_type_string, apk_name) + return path.join(base_path, build_type.directory_name(), apk_name) def get_binary_path(self, build_type: BuildType, target=None, android=False, simpleservo=False): base_path = util.get_target_dir() @@ -310,8 +344,7 @@ class CommandBase(object): else: binary_name = "libsimpleservo.so" - build_type_string = "release" if build_type == BuildType.RELEASE else "debug" - binary_path = path.join(base_path, build_type_string, binary_name) + binary_path = path.join(base_path, build_type.directory_name(), binary_name) if not path.exists(binary_path): raise BuildNotFound('No Servo binary found. Perhaps you forgot to run `./mach build`?') @@ -701,6 +734,8 @@ class CommandBase(object): CommandArgument('--dev', '--debug', '-d', group="Build Type", action='store_true', help='Build in development mode'), + CommandArgument('--profile', group="Build Type", + help='Build with custom Cargo profile'), ] if build_configuration: @@ -762,9 +797,12 @@ class CommandBase(object): if build_type: # If `build_type` already exists in kwargs we are doing a recursive dispatch. if 'build_type' not in kwargs: - kwargs['build_type'] = self.configure_build_type(kwargs['release'], kwargs['dev']) + kwargs['build_type'] = self.configure_build_type( + kwargs['release'], kwargs['dev'], kwargs['profile'], + ) kwargs.pop('release', None) kwargs.pop('dev', None) + kwargs.pop('profile', None) if build_configuration: self.configure_cross_compilation(kwargs['target'], kwargs['android'], kwargs['win_arm64']) @@ -781,24 +819,31 @@ class CommandBase(object): return decorator_function - def configure_build_type(self, release: bool, dev: bool) -> BuildType: - if release and dev: + def configure_build_type(self, release: bool, dev: bool, profile: Optional[str]) -> BuildType: + option_count = release + dev + (profile is not None) + + if option_count > 1: print("Please specify either --dev (-d) for a development") - print(" build, or --release (-r) for an optimized build.") + print(" build, or --release (-r) for an optimized build,") + print(" or --profile PROFILE for a custom Cargo profile.") sys.exit(1) - - if not release and not dev: + elif option_count < 1: if self.config["build"]["mode"] == "dev": print("No build type specified, but .servobuild specified `--dev`.") - dev = True + return BuildType.dev() elif self.config["build"]["mode"] == "release": print("No build type specified, but .servobuild specified `--release`.") - release = True + return BuildType.release() else: print("No build type specified so assuming `--dev`.") - dev = True + return BuildType.dev() - return BuildType.DEV if dev else BuildType.RELEASE + if release: + return BuildType.release() + elif dev: + return BuildType.dev() + else: + return BuildType.custom(profile) def configure_cross_compilation( self, |