diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-10-30 09:59:13 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-11-05 11:09:03 -0800 |
| commit | 97a1c567c9813176e4bec40f6055f228b2121609 (patch) | |
| tree | 44c1f961a1742ccd788c5e538065d01f79a44314 /mesonbuild/interpreter | |
| parent | 9f9481224aa30104c89adec729272398d6a9ba86 (diff) | |
| download | meson-97a1c567c9813176e4bec40f6055f228b2121609.tar.gz | |
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. This does two checks, an initial cheap check for generated
sources, and then an I/O check via `source_strings_to_files`.
Diffstat (limited to 'mesonbuild/interpreter')
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 3 | ||||
| -rw-r--r-- | mesonbuild/interpreter/type_checking.py | 15 |
2 files changed, 16 insertions, 2 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 1c109bc2b..133e29bf3 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -3445,7 +3445,8 @@ class Interpreter(InterpreterBase, HoldableObject): sources = self.source_strings_to_files(sources) objs = kwargs['objects'] kwargs['dependencies'] = extract_as_list(kwargs, 'dependencies') - kwargs['extra_files'] = self.source_strings_to_files(kwargs['extra_files']) + # TODO: When we can do strings -> Files in the typed_kwargs validator, do this there too + kwargs['extra_files'] = mesonlib.unique_list(self.source_strings_to_files(kwargs['extra_files'])) self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources) self.__process_language_args(kwargs) if targetclass is build.StaticLibrary: diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 2d74cc244..dc60e2219 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -588,11 +588,24 @@ def _target_install_convertor(val: object) -> bool: return bool(val) +def _extra_files_validator(args: T.List[T.Union[File, str]]) -> T.Optional[str]: + generated = [a for a in args if isinstance(a, File) and a.is_built] + if generated: + return 'extra_files contains generated files: {}'.format(', '.join(f"{f.fname}" for f in generated)) + return None + + # Applies to all build_target like classes _ALL_TARGET_KWS: T.List[KwargInfo] = [ OVERRIDE_OPTIONS_KW, KwargInfo('build_by_default', bool, default=True, since='0.38.0'), - KwargInfo('extra_files', ContainerTypeInfo(list, (str, File)), default=[], listify=True), + KwargInfo( + 'extra_files', + ContainerTypeInfo(list, (str, File)), + default=[], + listify=True, + validator=_extra_files_validator, + ), KwargInfo( 'install', object, |
