Skip to content

Commit 576bbf2

Browse files
committed
interpreter: Move validation of BuildTarget(extra_files) to Interpreter
This gets us to the point that the build layer can assume it's getting valid inputs. We switch from using a check that files exist (expensive) to checking `File.is_built`, which achieves the same thing, but without doing filesystem I/O.
1 parent 0514719 commit 576bbf2

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

mesonbuild/build.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,17 +1285,7 @@ def process_kwargs(self, kwargs: BuildTargetKeywordArguments) -> None:
12851285
(str, bool))
12861286
self.install_mode = kwargs.get('install_mode', None)
12871287
self.install_tag = stringlistify(kwargs.get('install_tag', [None]))
1288-
extra_files = kwargs.get('extra_files', [])
1289-
for i in extra_files:
1290-
# TODO: use an OrderedSet instead of a list?
1291-
if i in self.extra_files:
1292-
continue
1293-
# TODO: this prevents built `File` objects from being used as
1294-
# extra_files.
1295-
trial = os.path.join(self.environment.get_source_dir(), i.subdir, i.fname)
1296-
if not os.path.isfile(trial):
1297-
raise InvalidArguments(f'Tried to add non-existing extra file {i}.')
1298-
self.extra_files.append(i)
1288+
self.extra_files = kwargs.get('extra_files', [])
12991289
self.install_rpath: str = kwargs.get('install_rpath', '')
13001290
self.build_rpath = kwargs.get('build_rpath', '')
13011291
self.resources = kwargs.get('resources', [])

mesonbuild/interpreter/interpreter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3384,7 +3384,8 @@ def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargs
33843384
sources = self.source_strings_to_files(sources)
33853385
objs = kwargs['objects']
33863386
kwargs['dependencies'] = extract_as_list(kwargs, 'dependencies')
3387-
kwargs['extra_files'] = self.source_strings_to_files(kwargs['extra_files'])
3387+
# TODO: When we can do strings -> Files in the typed_kwargs validator, do this there too
3388+
kwargs['extra_files'] = mesonlib.unique_list(self.source_strings_to_files(kwargs['extra_files']))
33883389
self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources)
33893390
if targetclass not in {build.Executable, build.SharedLibrary, build.SharedModule, build.StaticLibrary, build.Jar}:
33903391
mlog.debug('Unknown target type:', str(targetclass))

mesonbuild/interpreter/type_checking.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,24 @@ def _target_install_convertor(val: object) -> bool:
588588
return bool(val)
589589

590590

591+
def _extra_files_validator(args: T.List[T.Union[File, str]]) -> T.Optional[str]:
592+
generated = [a for a in args if isinstance(a, File) and a.is_built]
593+
if generated:
594+
return 'extra_files contains generated files: {}'.format(', '.join(f"{f.fname}" for f in generated))
595+
return None
596+
597+
591598
# Applies to all build_target like classes
592599
_ALL_TARGET_KWS: T.List[KwargInfo] = [
593600
OVERRIDE_OPTIONS_KW,
594601
KwargInfo('build_by_default', bool, default=True, since='0.38.0'),
595-
KwargInfo('extra_files', ContainerTypeInfo(list, (str, File)), default=[], listify=True),
602+
KwargInfo(
603+
'extra_files',
604+
ContainerTypeInfo(list, (str, File)),
605+
default=[],
606+
listify=True,
607+
validator=_extra_files_validator,
608+
),
596609
KwargInfo(
597610
'install',
598611
object,

0 commit comments

Comments
 (0)