Skip to content

Commit 1e5d7f2

Browse files
committed
custom_target: catch and reject input files that do not exist
Currently there is a try/except around the function that detects and rejects this, which instead of rejecting it, spawns a warning and continue. This warning exists because of 'test cases/vala/9 gir/' which passes a vala generated output that isn't a return value (!!!) using string joining with the meson.current_build_dir() function (also !!!) because we officially document this (!!! for a third time) as the only way to make a vala shared library generate a typelib with a custom_command from the automatically generated gir: https://mesonbuild.com/Vala.html#gobject-introspection-and-language-bindings In #3061 we converted strings to Files, but only if none of them were this vala hack. Due to the precise implementation, we also failed to convert strings to Files if any other error occurred, but since we only want to ignore errors for generated vala outputs, tighten that check and specifically call out generated files in the warning. Fixes #8635
1 parent d9c73a6 commit 1e5d7f2

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

‎mesonbuild/interpreter/interpreter.py‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,11 +1768,7 @@ def _func_custom_target_impl(self, node, args, kwargs):
17681768
name = ''
17691769
kwargs['install_mode'] = self._get_kwarg_install_mode(kwargs)
17701770
if 'input' in kwargs:
1771-
try:
1772-
kwargs['input'] = self.source_strings_to_files(extract_as_list(kwargs, 'input'))
1773-
except mesonlib.MesonException:
1774-
mlog.warning(f'''Custom target input '{kwargs['input']}' can't be converted to File object(s).
1775-
This will become a hard error in the future.''', location=node)
1771+
kwargs['input'] = self.source_strings_to_files(extract_as_list(kwargs, 'input'), strict=False)
17761772
kwargs['env'] = self.unpack_env_kwarg(kwargs)
17771773
if 'command' in kwargs and isinstance(kwargs['command'], list) and kwargs['command']:
17781774
if isinstance(kwargs['command'][0], str):
@@ -2610,12 +2606,15 @@ def validate_within_subproject(self, subdir, fname):
26102606
raise InterpreterException(f'Sandbox violation: Tried to grab {inputtype} {norm.name} from a nested subproject.')
26112607

26122608
@T.overload
2613-
def source_strings_to_files(self, sources: T.List['mesonlib.FileOrString']) -> T.List['mesonlib.File']: ...
2609+
def source_strings_to_files(self, sources: T.List['mesonlib.FileOrString'], strict: bool = True) -> T.List['mesonlib.File']: ...
2610+
2611+
@T.overload
2612+
def source_strings_to_files(self, sources: T.List['mesonlib.FileOrString'], strict: bool = False) -> T.List['mesonlib.FileOrString']: ... # noqa: F811
26142613

26152614
@T.overload
2616-
def source_strings_to_files(self, sources: T.List['SourceInputs']) -> T.List['SourceOutputs']: ... # noqa: F811
2615+
def source_strings_to_files(self, sources: T.List['SourceInputs'], strict: bool = True) -> T.List['SourceOutputs']: ... # noqa: F811
26172616

2618-
def source_strings_to_files(self, sources: T.List['SourceInputs']) -> T.List['SourceOutputs']: # noqa: F811
2617+
def source_strings_to_files(self, sources: T.List['SourceInputs'], strict: bool = True) -> T.List['SourceOutputs']: # noqa: F811
26192618
"""Lower inputs to a list of Targets and Files, replacing any strings.
26202619
26212620
:param sources: A raw (Meson DSL) list of inputs (targets, files, and
@@ -2629,8 +2628,13 @@ def source_strings_to_files(self, sources: T.List['SourceInputs']) -> T.List['So
26292628
results: T.List['SourceOutputs'] = []
26302629
for s in sources:
26312630
if isinstance(s, str):
2632-
self.validate_within_subproject(self.subdir, s)
2633-
results.append(mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s))
2631+
if not strict and s.startswith(self.environment.get_build_dir()):
2632+
results.append(s)
2633+
mlog.warning(f'Source item {s!r} cannot be converted to File object, because it is a generated file. '
2634+
'This will become a hard error in the future.', location=self.current_node)
2635+
else:
2636+
self.validate_within_subproject(self.subdir, s)
2637+
results.append(mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s))
26342638
elif isinstance(s, mesonlib.File):
26352639
results.append(s)
26362640
elif isinstance(s, (build.GeneratedList, build.BuildTarget,

0 commit comments

Comments
 (0)