diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 9c2cb1ae7..025af1505 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1152,10 +1152,10 @@ class BuildTarget(Target): # was not specified and win_subsystem should be used instead. self.gui_app = None if kwargs.get('gui_app') is not None: - if 'win_subsystem' in kwargs: + if kwargs.get('win_subsystem') is not None: raise InvalidArguments('Can specify only gui_app or win_subsystem for a target, not both.') self.gui_app = kwargs['gui_app'] - self.win_subsystem = self.validate_win_subsystem(kwargs.get('win_subsystem', 'console')) + self.win_subsystem = kwargs.get('win_subsystem', 'console') elif 'gui_app' in kwargs: raise InvalidArguments('Argument gui_app can only be used on executables.') elif 'win_subsystem' in kwargs: @@ -1240,12 +1240,6 @@ class BuildTarget(Target): raise InvalidArguments(f'Invalid rust_dependency_map "{rust_dependency_map}": must be a dictionary with string values.') self.rust_dependency_map = rust_dependency_map - def validate_win_subsystem(self, value: str) -> str: - value = value.lower() - if re.fullmatch(r'(boot_application|console|efi_application|efi_boot_service_driver|efi_rom|efi_runtime_driver|native|posix|windows)(,\d+(\.\d+)?)?', value) is None: - raise InvalidArguments(f'Invalid value for win_subsystem: {value}.') - return value - def _extract_pic_pie(self, kwargs, arg: str, option: str): # Check if we have -fPIC, -fpic, -fPIE, or -fpie in cflags all_flags = self.extra_args['c'] + self.extra_args['cpp'] diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 69a48faf4..125562fe3 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1807,7 +1807,6 @@ class Interpreter(InterpreterBase, HoldableObject): return Disabler() @FeatureNewKwargs('executable', '0.42.0', ['implib']) - @FeatureNewKwargs('executable', '0.56.0', ['win_subsystem']) @permittedKwargs(build.known_exe_kwargs) @typed_pos_args('executable', str, varargs=(str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList, build.StructuredSources, build.ExtractedObjects, build.BuildTarget)) @typed_kwargs('executable', *EXECUTABLE_KWS, allow_unknown=True) diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 07b6165f7..13b7430b3 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -329,6 +329,7 @@ class _BuildTarget(_BaseBuildTarget): class Executable(_BuildTarget): gui_app: T.Optional[bool] + win_subsystem: T.Optional[str] class StaticLibrary(_BuildTarget): diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 2b78eb6c8..b919d6a54 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -5,6 +5,7 @@ from __future__ import annotations import os +import re import typing as T from .. import compilers @@ -490,10 +491,22 @@ _BUILD_TARGET_KWS: T.List[KwargInfo] = [ *_ALL_TARGET_KWS, ] +def _validate_win_subsystem(value: T.Optional[str]) -> T.Optional[str]: + if value is not None: + if re.fullmatch(r'(boot_application|console|efi_application|efi_boot_service_driver|efi_rom|efi_runtime_driver|native|posix|windows)(,\d+(\.\d+)?)?', value) is None: + return f'Invalid value for win_subsystem: {value}.' + return None + # Arguments exclusive to Executable. These are separated to make integrating # them into build_target easier _EXCLUSIVE_EXECUTABLE_KWS: T.List[KwargInfo] = [ - KwargInfo('gui_app', (bool, NoneType), deprecated='0.56.0', deprecated_message="Use 'win_subsystem' instead") + KwargInfo('gui_app', (bool, NoneType), deprecated='0.56.0', deprecated_message="Use 'win_subsystem' instead"), + KwargInfo( + 'win_subsystem', + (str, NoneType), + convertor=lambda x: x.lower() if isinstance(x, str) else None, + validator=_validate_win_subsystem, + ), ] # The total list of arguments used by Executable