build: Simplify BuildTarget.process_sourcelist
@@ -613,16 +613,12 @@ class BuildTarget(Target):
self.pch = {}
self.extra_args: T.Dict[str, T.List['FileOrString']] = {}
self.sources: T.List[File] = []
- self.generated: T.Sequence[T.Union[GeneratedList, CustomTarget, CustomTargetIndex]] = []
+ self.generated: T.List[T.Union[GeneratedList, CustomTarget, CustomTargetIndex]] = []
self.d_features = {}
self.pic = False
self.pie = False
# Track build_rpath entries so we can remove them at install time
self.rpath_dirs_to_remove: T.Set[bytes] = set()
- # Sources can be:
- # 1. Pre-existing source files in the source tree
- # 2. Pre-existing sources generated by configure_file in the build tree
- # 3. Sources files generated by another target or a Generator
self.process_sourcelist(sources)
# Objects can be:
# 1. Pre-existing objects provided by the user with the `objects:` kwarg
@@ -680,19 +676,23 @@ class BuildTarget(Target):
msg = 'Bad object of type {!r} in target {!r}.'.format(type(s).__name__, self.name)
raise InvalidArguments(msg)
- def process_sourcelist(self, sources):
- sources = listify(sources)
- added_sources = {} # If the same source is defined multiple times, use it only once.
- for s in unholder(sources):
+ def process_sourcelist(self, sources: T.List['SourceOutputs']) -> None:
+ """Split sources into generated and static sources.
+
+ Sources can be:
+ 1. Pre-existing source files in the source tree (static)
+ 2. Pre-existing sources generated by configure_file in the build tree.
+ (static as they are only regenerated if meson itself is regenerated)
+ 3. Sources files generated by another target or a Generator (generated)
+ """
+ added_sources: T.Set[File] = set() # If the same source is defined multiple times, use it only once.
+ for s in sources:
if isinstance(s, File):
if s not in added_sources:
self.sources.append(s)
- added_sources[s] = True
- elif isinstance(s, (GeneratedList, CustomTarget, CustomTargetIndex)):
+ added_sources.add(s)
+ elif isinstance(s, (CustomTarget, CustomTargetIndex, GeneratedList)):
self.generated.append(s)
- else:
- msg = 'Bad source of type {!r} in target {!r}.'.format(type(s).__name__, self.name)
- raise InvalidArguments(msg)
@staticmethod
def can_compile_remove_sources(compiler, sources):
