summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-11-03 11:04:35 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-11-12 08:14:37 -0800
commit176c6d27e3e84f884df42cff6813cc5ca77f91c8 (patch)
tree04ce87d3666b01ec8d949e5d4c3d0d0446ee51e2 /mesonbuild/interpreter
parent4f1c618392972c935d83eb7939234b3b90479df5 (diff)
downloadmeson-176c6d27e3e84f884df42cff6813cc5ca77f91c8.tar.gz
build: Use a tuple for pch data
This really isn't a list because it's not homogenous data, it's really `tuple[str, str | None] | None`, but we're using list length to decide what to do with it, and that makes for strict null issues, as an accurate annotation would be `list[str | None]`, which would require a lot of `is not None` checking. By using a tuple we don't need to keep checking length, which is more expensive than null checking. To ensure correctness I annotated some things in the VS backend
Diffstat (limited to 'mesonbuild/interpreter')
-rw-r--r--mesonbuild/interpreter/interpreter.py2
-rw-r--r--mesonbuild/interpreter/type_checking.py18
2 files changed, 14 insertions, 6 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 36647f32c..a3cdde04a 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -3479,7 +3479,7 @@ class Interpreter(InterpreterBase, HoldableObject):
self.check_for_jar_sources(sources, targetclass)
kwargs['d_import_dirs'] = self.extract_incdirs(kwargs, 'd_import_dirs')
missing: T.List[str] = []
- for each in itertools.chain(kwargs['c_pch'], kwargs['cpp_pch']):
+ for each in itertools.chain(kwargs['c_pch'] or [], kwargs['cpp_pch'] or []):
if each is not None:
if not os.path.isfile(os.path.join(self.environment.source_dir, self.subdir, each)):
missing.append(os.path.join(self.subdir, each))
diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py
index 5dc9127f3..6cd43b7c6 100644
--- a/mesonbuild/interpreter/type_checking.py
+++ b/mesonbuild/interpreter/type_checking.py
@@ -679,11 +679,19 @@ 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
+def _pch_convertor(args: T.List[str]) -> T.Optional[T.Tuple[str, T.Optional[str]]]:
+ num_args = len(args)
+
+ if num_args == 1:
+ return (args[0], None)
+
+ if num_args == 2:
+ if compilers.is_source(args[0]):
+ # Flip so that we always have [header, src]
+ return (args[1], args[0])
+ return (args[0], args[1])
+
+ return None
_PCH_ARGS: KwargInfo[T.List[str]] = KwargInfo(