diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-10-01 09:38:52 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2022-03-07 12:33:33 -0800 |
commit | 7d1431a06039cb29bc2585929a9fbac58bdedb0e (patch) | |
tree | 6399edd3684d983a7f20e3510cc246057c83d46c /mesonbuild/interpreter/interpreter.py | |
parent | cbc62e892aaea60a3692797c521672b95be9389d (diff) | |
download | meson-7d1431a06039cb29bc2585929a9fbac58bdedb0e.zip meson-7d1431a06039cb29bc2585929a9fbac58bdedb0e.tar.gz meson-7d1431a06039cb29bc2585929a9fbac58bdedb0e.tar.bz2 |
build: plumb structured sources into BuildTargets
Diffstat (limited to 'mesonbuild/interpreter/interpreter.py')
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 6627b5e..bc011b7 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -105,7 +105,7 @@ if T.TYPE_CHECKING: # Input source types passed to the build.Target classes SourceOutputs = T.Union[mesonlib.File, build.GeneratedList, build.BuildTarget, build.CustomTargetIndex, build.CustomTarget, - build.ExtractedObjects, build.GeneratedList] + build.ExtractedObjects, build.GeneratedList, build.StructuredSources] def _project_version_validator(value: T.Union[T.List, str, mesonlib.File, None]) -> T.Optional[str]: @@ -2863,7 +2863,7 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey else: raise InterpreterException(f'Unknown default_library value: {default_library}.') - def build_target(self, node, args, kwargs, targetclass): + def build_target(self, node: mparser.BaseNode, args, kwargs, targetclass): @FeatureNewKwargs('build target', '0.42.0', ['rust_crate_type', 'build_rpath', 'implicit_include_directories']) @FeatureNewKwargs('build target', '0.41.0', ['rust_args']) @FeatureNewKwargs('build target', '0.40.0', ['build_by_default']) @@ -2896,8 +2896,39 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey # passed to library() when default_library == 'static'. kwargs = {k: v for k, v in kwargs.items() if k in targetclass.known_kwargs} + srcs: T.List['SourceInputs'] = [] + struct: T.Optional[build.StructuredSources] = build.StructuredSources() + for s in sources: + if isinstance(s, build.StructuredSources): + struct = struct + s + else: + srcs.append(s) + + if not struct: + struct = None + else: + # Validate that we won't end up with two outputs with the same name. + # i.e, don't allow: + # [structured_sources('foo/bar.rs'), structured_sources('bar/bar.rs')] + for v in struct.sources.values(): + outputs: T.Set[str] = set() + for f in v: + o: T.List[str] + if isinstance(f, str): + o = [os.path.basename(f)] + elif isinstance(f, mesonlib.File): + o = [f.fname] + else: + o = f.get_outputs() + conflicts = outputs.intersection(o) + if conflicts: + raise InvalidArguments.from_node( + f"Conflicting sources in structured sources: {', '.join(sorted(conflicts))}", + node=node) + outputs.update(o) + kwargs['include_directories'] = self.extract_incdirs(kwargs) - target = targetclass(name, self.subdir, self.subproject, for_machine, sources, objs, self.environment, kwargs) + target = targetclass(name, self.subdir, self.subproject, for_machine, srcs, struct, objs, self.environment, kwargs) target.project_version = self.project_version self.add_stdlib_info(target) |