Add --production option to mach (#30707)

* --prod(uction) mach argument

* Use profile in workflows instead of production

* Use profiles in unit tests

* ups

* Build (${{ inputs.profile }})
This commit is contained in:
Samson 2023-11-10 11:38:33 +01:00 committed by GitHub
parent c78b98252a
commit 96d37d3785
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 71 deletions

View file

@ -63,6 +63,9 @@ class BuildType:
def release() -> BuildType:
return BuildType(BuildType.Kind.RELEASE, None)
def prod() -> BuildType:
return BuildType(BuildType.Kind.CUSTOM, "production")
def custom(profile: str) -> BuildType:
return BuildType(BuildType.Kind.CUSTOM, profile)
@ -72,6 +75,9 @@ class BuildType:
def is_release(self) -> bool:
return self.kind == BuildType.Kind.RELEASE
def is_prod(self) -> bool:
return self.kind == BuildType.Kind.CUSTOM and self.profile == "production"
def is_custom(self) -> bool:
return self.kind == BuildType.Kind.CUSTOM
@ -734,6 +740,9 @@ class CommandBase(object):
CommandArgument('--dev', '--debug', '-d', group="Build Type",
action='store_true',
help='Build in development mode'),
CommandArgument('--prod', '--production', group="Build Type",
action='store_true',
help='Build in release mode without debug assertions'),
CommandArgument('--profile', group="Build Type",
help='Build with custom Cargo profile'),
]
@ -798,10 +807,11 @@ class CommandBase(object):
# 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['profile'],
kwargs['release'], kwargs['dev'], kwargs['prod'], kwargs['profile'],
)
kwargs.pop('release', None)
kwargs.pop('dev', None)
kwargs.pop('prod', None)
kwargs.pop('profile', None)
if build_configuration:
@ -819,8 +829,8 @@ class CommandBase(object):
return decorator_function
def configure_build_type(self, release: bool, dev: bool, profile: Optional[str]) -> BuildType:
option_count = release + dev + (profile is not None)
def configure_build_type(self, release: bool, dev: bool, prod: bool, profile: Optional[str]) -> BuildType:
option_count = release + dev + prod + (profile is not None)
if option_count > 1:
print("Please specify either --dev (-d) for a development")
@ -842,6 +852,8 @@ class CommandBase(object):
return BuildType.release()
elif dev:
return BuildType.dev()
elif prod:
return BuildType.prod()
else:
return BuildType.custom(profile)

View file

@ -174,8 +174,8 @@ class MachCommands(CommandBase):
help="Run in bench mode")
@CommandArgument('--nocapture', default=False, action="store_true",
help="Run tests with nocapture ( show test stdout )")
@CommandBase.common_command_arguments(build_configuration=True, build_type=False)
def test_unit(self, test_name=None, package=None, bench=False, nocapture=False, **kwargs):
@CommandBase.common_command_arguments(build_configuration=True, build_type=True)
def test_unit(self, build_type: BuildType, test_name=None, package=None, bench=False, nocapture=False, **kwargs):
if test_name is None:
test_name = []
@ -239,6 +239,14 @@ class MachCommands(CommandBase):
# Gather Cargo build timings (https://doc.rust-lang.org/cargo/reference/timings.html).
args = ["--timings"]
if build_type.is_release():
args += ["--release"]
elif build_type.is_dev():
pass # there is no argument for debug
else:
args += ["--profile", build_type.profile]
for crate in packages:
args += ["-p", "%s_tests" % crate]
for crate in in_crate_packages: