diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-11-03 10:28:52 -0800 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-11-12 08:14:37 -0800 |
| commit | 6198aaa30c99fc3c183dfdacf789fa05d9d268d8 (patch) | |
| tree | 1807dcf13df7b4076092bd68d9ad3acfbeaaf779 /mesonbuild/interpreter | |
| parent | 8b30058c0f845fd85515865b4fca8cd0f8ab10ce (diff) | |
| download | meson-6198aaa30c99fc3c183dfdacf789fa05d9d268d8.tar.gz | |
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.
Diffstat (limited to 'mesonbuild/interpreter')
| -rw-r--r-- | mesonbuild/interpreter/type_checking.py | 26 |
1 files changed, 25 insertions, 1 deletions
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, ) |
