build: Add a Union alias for all build targets

pull/10718/head
Dylan Baker 2 years ago committed by Eli Schwartz
parent f10967e3f4
commit 394f734b1d
  1. 2
      mesonbuild/backend/backends.py
  2. 16
      mesonbuild/build.py

@ -1044,7 +1044,7 @@ class Backend:
tests.
"""
result: T.Set[str] = set()
prospectives: T.Set[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]] = set()
prospectives: T.Set[build.BuildTargetTypes] = set()
if isinstance(target, build.BuildTarget):
prospectives.update(target.get_transitive_link_deps())
# External deps

@ -58,6 +58,7 @@ if T.TYPE_CHECKING:
GeneratedTypes = T.Union['CustomTarget', 'CustomTargetIndex', 'GeneratedList']
LibTypes = T.Union['SharedLibrary', 'StaticLibrary', 'CustomTarget', 'CustomTargetIndex']
BuildTargetTypes = T.Union['BuildTarget', 'CustomTarget', 'CustomTargetIndex']
pch_kwargs = {'c_pch', 'cpp_pch'}
@ -1066,11 +1067,11 @@ class BuildTarget(Target):
return ExtractedObjects(self, self.sources, self.generated, self.objects,
recursive)
def get_all_link_deps(self) -> 'ImmutableListProtocol[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]':
def get_all_link_deps(self) -> ImmutableListProtocol[BuildTargetTypes]:
return self.get_transitive_link_deps()
@lru_cache(maxsize=None)
def get_transitive_link_deps(self) -> 'ImmutableListProtocol[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]':
def get_transitive_link_deps(self) -> ImmutableListProtocol[BuildTargetTypes]:
result: T.List[Target] = []
for i in self.link_targets:
result += i.get_all_link_deps()
@ -2402,7 +2403,7 @@ class CommandBase:
dependencies: T.List[T.Union[BuildTarget, 'CustomTarget']]
subproject: str
def flatten_command(self, cmd: T.Sequence[T.Union[str, File, programs.ExternalProgram, 'BuildTarget', 'CustomTarget', 'CustomTargetIndex']]) -> \
def flatten_command(self, cmd: T.Sequence[T.Union[str, File, programs.ExternalProgram, BuildTargetTypes]]) -> \
T.List[T.Union[str, File, BuildTarget, 'CustomTarget']]:
cmd = listify(cmd)
final_cmd: T.List[T.Union[str, File, BuildTarget, 'CustomTarget']] = []
@ -2444,10 +2445,11 @@ class CustomTarget(Target, CommandBase):
subproject: str,
environment: environment.Environment,
command: T.Sequence[T.Union[
str, BuildTarget, CustomTarget, CustomTargetIndex, GeneratedList, programs.ExternalProgram, File]],
str, BuildTargetTypes, GeneratedList,
programs.ExternalProgram, File]],
sources: T.Sequence[T.Union[
str, File, BuildTarget, CustomTarget, CustomTargetIndex,
ExtractedObjects, GeneratedList, programs.ExternalProgram]],
str, File, BuildTargetTypes, ExtractedObjects,
GeneratedList, programs.ExternalProgram]],
outputs: T.List[str],
*,
build_always_stale: bool = False,
@ -2633,7 +2635,7 @@ class RunTarget(Target, CommandBase):
typename = 'run'
def __init__(self, name: str,
command: T.Sequence[T.Union[str, File, BuildTarget, 'CustomTarget', 'CustomTargetIndex', programs.ExternalProgram]],
command: T.Sequence[T.Union[str, File, BuildTargetTypes, programs.ExternalProgram]],
dependencies: T.Sequence[Target],
subdir: str,
subproject: str,

Loading…
Cancel
Save