summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/build.py17
-rw-r--r--mesonbuild/interpreter/type_checking.py26
2 files changed, 25 insertions, 18 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,
)