From 6198aaa30c99fc3c183dfdacf789fa05d9d268d8 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 3 Nov 2025 10:28:52 -0800 Subject: interpreter: Move most of the remaining validation to the Interpreter What's left requires the Environment, so it will have to be handled in the interpreter implementation for now. --- mesonbuild/build.py | 17 ----------------- mesonbuild/interpreter/type_checking.py | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 18 deletions(-) (limited to 'mesonbuild') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 8241efa1d..03b1f3db8 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1593,23 +1593,6 @@ class BuildTarget(Target): def add_pch(self, language: str, pchlist: T.List[str]) -> None: if not pchlist: return - elif len(pchlist) == 1: - if not is_header(pchlist[0]): - raise InvalidArguments(f'PCH argument {pchlist[0]} is not a header.') - elif len(pchlist) == 2: - if is_header(pchlist[0]): - if not is_source(pchlist[1]): - raise InvalidArguments('PCH definition must contain one header and at most one source.') - elif is_source(pchlist[0]): - if not is_header(pchlist[1]): - raise InvalidArguments('PCH definition must contain one header and at most one source.') - pchlist = [pchlist[1], pchlist[0]] - else: - raise InvalidArguments(f'PCH argument {pchlist[0]} is of unknown type.') - - if os.path.dirname(pchlist[0]) != os.path.dirname(pchlist[1]): - raise InvalidArguments('PCH files must be stored in the same folder.') - for f in pchlist: if not os.path.isfile(os.path.join(self.environment.source_dir, self.subdir, f)): raise MesonException(f'File {f} does not exist.') diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index e582cd91b..5dc9127f3 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -653,7 +653,23 @@ _NAME_PREFIX_KW: KwargInfo[T.Optional[T.Union[str, T.List]]] = KwargInfo( def _pch_validator(args: T.List[str]) -> T.Optional[str]: - if len(args) > 2: + num_args = len(args) + if num_args == 1: + if not compilers.is_header(args[0]): + return f'PCH argument {args[0]} is not a header.' + elif num_args == 2: + if compilers.is_header(args[0]): + if not compilers.is_source(args[1]): + return 'PCH definition must contain one header and at most one source.' + elif compilers.is_source(args[0]): + if not compilers.is_header(args[1]): + return 'PCH definition must contain one header and at most one source.' + else: + return f'PCH argument {args[0]} has neither a known header or code extension.' + + if os.path.dirname(args[0]) != os.path.dirname(args[1]): + return 'PCH files must be stored in the same folder.' + elif num_args > 2: return 'A maximum of two elements are allowed for PCH arguments' return None @@ -663,6 +679,13 @@ def _pch_feature_validator(args: T.List[str]) -> T.Iterable[FeatureCheckBase]: yield FeatureDeprecated('PCH source files', '0.50.0', 'Only a single header file should be used.') +def _pch_convertor(args: T.List[str]) -> T.List[str]: + # Flip so that we always have [header, src] + if len(args) == 2 and compilers.is_source(args[0]): + return [args[1], args[0]] + return args + + _PCH_ARGS: KwargInfo[T.List[str]] = KwargInfo( 'pch', ContainerTypeInfo(list, str), @@ -670,6 +693,7 @@ _PCH_ARGS: KwargInfo[T.List[str]] = KwargInfo( default=[], validator=_pch_validator, feature_validator=_pch_feature_validator, + convertor=_pch_convertor, ) -- cgit v1.2.3