summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-11-03 10:28:52 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-11-12 08:14:37 -0800
commit6198aaa30c99fc3c183dfdacf789fa05d9d268d8 (patch)
tree1807dcf13df7b4076092bd68d9ad3acfbeaaf779
parent8b30058c0f845fd85515865b4fca8cd0f8ab10ce (diff)
downloadmeson-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.
-rw-r--r--mesonbuild/build.py17
-rw-r--r--mesonbuild/interpreter/type_checking.py26
-rw-r--r--test cases/failing/87 pch source different folder/test.json2
3 files changed, 26 insertions, 19 deletions
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,
)
diff --git a/test cases/failing/87 pch source different folder/test.json b/test cases/failing/87 pch source different folder/test.json
index 0a9d39d6f..fd18d6866 100644
--- a/test cases/failing/87 pch source different folder/test.json
+++ b/test cases/failing/87 pch source different folder/test.json
@@ -1,7 +1,7 @@
{
"stdout": [
{
- "line": "test cases/failing/87 pch source different folder/meson.build:4:6: ERROR: PCH files must be stored in the same folder."
+ "line": "test cases/failing/87 pch source different folder/meson.build:4:6: ERROR: executable keyword argument \"c_pch\" PCH files must be stored in the same folder."
}
]
}