Skip to content

Commit 6198aaa

Browse files
committed
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.
1 parent 8b30058 commit 6198aaa

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

mesonbuild/build.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,23 +1593,6 @@ def check_can_link_together(self, t: BuildTargetTypes) -> None:
15931593
def add_pch(self, language: str, pchlist: T.List[str]) -> None:
15941594
if not pchlist:
15951595
return
1596-
elif len(pchlist) == 1:
1597-
if not is_header(pchlist[0]):
1598-
raise InvalidArguments(f'PCH argument {pchlist[0]} is not a header.')
1599-
elif len(pchlist) == 2:
1600-
if is_header(pchlist[0]):
1601-
if not is_source(pchlist[1]):
1602-
raise InvalidArguments('PCH definition must contain one header and at most one source.')
1603-
elif is_source(pchlist[0]):
1604-
if not is_header(pchlist[1]):
1605-
raise InvalidArguments('PCH definition must contain one header and at most one source.')
1606-
pchlist = [pchlist[1], pchlist[0]]
1607-
else:
1608-
raise InvalidArguments(f'PCH argument {pchlist[0]} is of unknown type.')
1609-
1610-
if os.path.dirname(pchlist[0]) != os.path.dirname(pchlist[1]):
1611-
raise InvalidArguments('PCH files must be stored in the same folder.')
1612-
16131596
for f in pchlist:
16141597
if not os.path.isfile(os.path.join(self.environment.source_dir, self.subdir, f)):
16151598
raise MesonException(f'File {f} does not exist.')

mesonbuild/interpreter/type_checking.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,23 @@ def _name_suffix_validator(arg: T.Optional[T.Union[str, T.List]]) -> T.Optional[
653653

654654

655655
def _pch_validator(args: T.List[str]) -> T.Optional[str]:
656-
if len(args) > 2:
656+
num_args = len(args)
657+
if num_args == 1:
658+
if not compilers.is_header(args[0]):
659+
return f'PCH argument {args[0]} is not a header.'
660+
elif num_args == 2:
661+
if compilers.is_header(args[0]):
662+
if not compilers.is_source(args[1]):
663+
return 'PCH definition must contain one header and at most one source.'
664+
elif compilers.is_source(args[0]):
665+
if not compilers.is_header(args[1]):
666+
return 'PCH definition must contain one header and at most one source.'
667+
else:
668+
return f'PCH argument {args[0]} has neither a known header or code extension.'
669+
670+
if os.path.dirname(args[0]) != os.path.dirname(args[1]):
671+
return 'PCH files must be stored in the same folder.'
672+
elif num_args > 2:
657673
return 'A maximum of two elements are allowed for PCH arguments'
658674
return None
659675

@@ -663,13 +679,21 @@ def _pch_feature_validator(args: T.List[str]) -> T.Iterable[FeatureCheckBase]:
663679
yield FeatureDeprecated('PCH source files', '0.50.0', 'Only a single header file should be used.')
664680

665681

682+
def _pch_convertor(args: T.List[str]) -> T.List[str]:
683+
# Flip so that we always have [header, src]
684+
if len(args) == 2 and compilers.is_source(args[0]):
685+
return [args[1], args[0]]
686+
return args
687+
688+
666689
_PCH_ARGS: KwargInfo[T.List[str]] = KwargInfo(
667690
'pch',
668691
ContainerTypeInfo(list, str),
669692
listify=True,
670693
default=[],
671694
validator=_pch_validator,
672695
feature_validator=_pch_feature_validator,
696+
convertor=_pch_convertor,
673697
)
674698

675699

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stdout": [
33
{
4-
"line": "test cases/failing/87 pch source different folder/meson.build:4:6: ERROR: PCH files must be stored in the same folder."
4+
"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."
55
}
66
]
77
}

0 commit comments

Comments
 (0)