diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index dabc4c10d695..a5995e6b18ac 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -46,7 +46,7 @@ from typing_extensions import TypedDict, NotRequired - _ALL_SOURCES_TYPE = T.List[T.Union[File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]] + _ALL_SOURCES_TYPE = T.List[T.Union[File, build.GeneratedTypes]] class TargetIntrospectionData(TypedDict): @@ -295,7 +295,7 @@ def __init__(self, build: T.Optional[build.Build], interpreter: T.Optional['Inte def generate(self, capture: bool = False, vslite_ctx: T.Optional[T.Dict] = None) -> T.Optional[T.Dict]: raise RuntimeError(f'generate is not implemented in {type(self).__name__}') - def get_target_filename(self, t: T.Union[build.Target, build.CustomTargetIndex], *, warn_multi_output: bool = True) -> str: + def get_target_filename(self, t: build.AnyTargetType, *, warn_multi_output: bool = True) -> str: if isinstance(t, build.CustomTarget): if warn_multi_output and len(t.get_outputs()) != 1: mlog.warning(f'custom_target {t.name!r} has more than one output! ' @@ -308,7 +308,7 @@ def get_target_filename(self, t: T.Union[build.Target, build.CustomTargetIndex], filename = t.get_filename() return os.path.join(self.get_target_dir(t), filename) - def get_target_filename_abs(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str: + def get_target_filename_abs(self, target: build.AnyTargetType) -> str: return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target)) def get_target_debug_filename(self, target: build.BuildTarget) -> T.Optional[str]: @@ -343,7 +343,7 @@ def get_build_dir_include_args(self, target: build.BuildTarget, compiler: 'Compi curdir = '.' return compiler.get_include_args(curdir, False) - def get_target_filename_for_linking(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> T.Optional[str]: + def get_target_filename_for_linking(self, target: build.AnyTargetType) -> T.Optional[str]: # On some platforms (msvc for instance), the file that is used for # dynamic linking is not the same as the dynamic library itself. This # file is called an import library, and we want to link against that. @@ -368,7 +368,7 @@ def get_target_filename_for_linking(self, target: T.Union[build.Target, build.Cu raise AssertionError(f'BUG: Tried to link to {target!r} which is not linkable') @lru_cache(maxsize=None) - def get_target_dir(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str: + def get_target_dir(self, target: build.AnyTargetType) -> str: if isinstance(target, build.RunTarget): # this produces no output, only a dummy top-level name dirname = '' @@ -394,16 +394,16 @@ def get_target_source_dir(self, target: build.Target) -> str: return os.path.join(self.build_to_src, target_dir) return self.build_to_src - def get_target_private_dir(self, target: T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]) -> str: + def get_target_private_dir(self, target: build.BuildTargetTypes) -> str: return os.path.join(self.get_target_filename(target, warn_multi_output=False) + '.p') - def get_target_private_dir_abs(self, target: T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]) -> str: + def get_target_private_dir_abs(self, target: build.BuildTargetTypes) -> str: return os.path.join(self.environment.get_build_dir(), self.get_target_private_dir(target)) @lru_cache(maxsize=None) def get_target_generated_dir( - self, target: T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex], - gensrc: T.Union[build.CustomTarget, build.CustomTargetIndex, build.GeneratedList], + self, target: build.BuildTargetTypes, + gensrc: build.GeneratedTypes, src: str) -> str: """ Takes a BuildTarget, a generator source (CustomTarget or GeneratedList), @@ -417,7 +417,7 @@ def get_target_generated_dir( # target that the GeneratedList is used in return os.path.join(self.get_target_private_dir(target), src) - def get_unity_source_file(self, target: T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex], + def get_unity_source_file(self, target: build.BuildTargetTypes, suffix: str, number: int) -> mesonlib.File: # There is a potential conflict here, but it is unlikely that # anyone both enables unity builds and has a file called foo-unity.cpp. @@ -1117,8 +1117,8 @@ def extract_dll_paths(cls, target: build.BuildTarget) -> T.Set[str]: return results def determine_windows_extra_paths( - self, target: T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, programs.ExternalProgram, mesonlib.File, str], - extra_bdeps: T.Sequence[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]]) -> T.List[str]: + self, target: T.Union[build.BuildTargetTypes, programs.ExternalProgram, mesonlib.File, str], + extra_bdeps: T.Sequence[build.BuildTargetTypes]) -> T.List[str]: """On Windows there is no such thing as an rpath. We must determine all locations of DLLs that this exe @@ -1184,7 +1184,7 @@ def create_test_serialisation(self, tests: T.List['Test']) -> T.List[TestSeriali exe_wrapper = self.environment.get_exe_wrapper() machine = self.environment.machines[exe.for_machine] if machine.is_windows() or machine.is_cygwin(): - extra_bdeps: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]] = [] + extra_bdeps: T.List[build.BuildTargetTypes] = [] if isinstance(exe, build.CustomTarget): extra_bdeps = list(exe.get_transitive_build_target_deps()) extra_bdeps.extend(t.depends) @@ -1252,7 +1252,7 @@ def create_test_serialisation(self, tests: T.List['Test']) -> T.List[TestSeriali def write_test_serialisation(self, tests: T.List['Test'], datafile: T.BinaryIO) -> None: pickle.dump(self.create_test_serialisation(tests), datafile) - def construct_target_rel_paths(self, t: T.Union[build.Target, build.CustomTargetIndex], workdir: T.Optional[str]) -> T.List[str]: + def construct_target_rel_paths(self, t: build.AnyTargetType, workdir: T.Optional[str]) -> T.List[str]: target_dir = self.get_target_dir(t) # ensure that test executables can be run when passed as arguments if isinstance(t, build.Executable) and workdir is None: @@ -1452,7 +1452,7 @@ def get_target_depend_files(self, target: T.Union[build.CustomTarget, build.Buil deps.append(os.path.join(self.build_to_src, target.subdir, i)) return deps - def get_custom_target_output_dir(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str: + def get_custom_target_output_dir(self, target: build.AnyTargetType) -> str: # The XCode backend is special. A target foo/bar does # not go to ${BUILDDIR}/foo/bar but instead to # ${BUILDDIR}/${BUILDTYPE}/foo/bar. @@ -2025,7 +2025,7 @@ def compiler_to_generator(self, target: build.BuildTarget, compiler: 'Compiler', sources: _ALL_SOURCES_TYPE, output_templ: str, - depends: T.Optional[T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]]] = None, + depends: T.Optional[T.List[build.BuildTargetTypes]] = None, ) -> build.GeneratedList: ''' Some backends don't support custom compilers. This is a convenience diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 8804b8daa894..45710a2b56d9 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -153,7 +153,7 @@ def detect_toolset(self) -> None: def get_target_private_dir(self, target): return os.path.join(self.get_target_dir(target), target.get_id()) - def generate_genlist_for_target(self, genlist: T.Union[build.GeneratedList, build.CustomTarget, build.CustomTargetIndex], target: build.BuildTarget, parent_node: ET.Element, generator_output_files: T.List[str], custom_target_include_dirs: T.List[str], custom_target_output_files: T.List[str]) -> None: + def generate_genlist_for_target(self, genlist: build.GeneratedTypes, target: build.BuildTarget, parent_node: ET.Element, generator_output_files: T.List[str], custom_target_include_dirs: T.List[str], custom_target_output_files: T.List[str]) -> None: if isinstance(genlist, build.GeneratedList): for x in genlist.depends: self.generate_genlist_for_target(x, target, parent_node, [], [], []) @@ -330,7 +330,7 @@ def get_obj_target_deps(self, obj_list): result[o.target.get_id()] = o.target return result.items() - def get_target_deps(self, t: T.Dict[T.Any, T.Union[build.Target, build.CustomTargetIndex]], recursive=False): + def get_target_deps(self, t: T.Dict[T.Any, build.AnyTargetType], recursive=False): all_deps: T.Dict[str, build.Target] = {} for target in t.values(): if isinstance(target, build.CustomTargetIndex): @@ -1577,7 +1577,7 @@ def add_non_makefile_vcxproj_elements( # once a build/compile has generated these sources. # # This modifies the paths in 'gen_files' in place, as opposed to returning a new list of modified paths. - def relocate_generated_file_paths_to_concrete_build_dir(self, gen_files: T.List[str], target: T.Union[build.Target, build.CustomTargetIndex]) -> None: + def relocate_generated_file_paths_to_concrete_build_dir(self, gen_files: T.List[str], target: build.AnyTargetType) -> None: (_, build_dir_tail) = os.path.split(self.src_to_build) meson_build_dir_for_buildtype = build_dir_tail[:-2] + coredata.get_genvs_default_buildtype_list()[0] # Get the first buildtype suffixed dir (i.e. '[builddir]_debug') from '[builddir]_vs' # Relative path from this .vcxproj to the directory containing the set of '..._[debug/debugoptimized/release]' setup meson build dirs. diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py index a0476ca85536..ac2126025398 100644 --- a/mesonbuild/backend/xcodebackend.py +++ b/mesonbuild/backend/xcodebackend.py @@ -280,12 +280,12 @@ def gen_id(self) -> str: return str(uuid.uuid4()).upper().replace('-', '')[:24] @functools.lru_cache(maxsize=None) - def get_target_dir(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str: + def get_target_dir(self, target: build.AnyTargetType) -> str: dirname = os.path.join(target.get_subdir(), T.cast('str', self.environment.coredata.optstore.get_value_for(OptionKey('buildtype')))) #os.makedirs(os.path.join(self.environment.get_build_dir(), dirname), exist_ok=True) return dirname - def get_custom_target_output_dir(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str: + def get_custom_target_output_dir(self, target: build.AnyTargetType) -> str: dirname = target.get_subdir() os.makedirs(os.path.join(self.environment.get_build_dir(), dirname), exist_ok=True) return dirname @@ -525,7 +525,7 @@ def generate_generator_target_map(self) -> None: generator_id += 1 def gen_single_target_map(self, genlist: build.GeneratedList, tname: str, - t: T.Union[build.BuildTarget, build.CustomTarget], generator_id: int) -> None: + t: build.AnyTargetType, generator_id: int) -> None: k = (tname, generator_id) assert k not in self.shell_targets self.shell_targets[k] = self.gen_id() @@ -1439,7 +1439,7 @@ def generate_generator_target_shell_build_phases(self, objects_dict: PbxDict) -> self.generate_single_generator_phase(tname, t, genlist, generator_id, objects_dict) generator_id += 1 - def generate_single_generator_phase(self, tname: str, t: T.Union[build.BuildTarget, build.CustomTarget], + def generate_single_generator_phase(self, tname: str, t: build.AnyTargetType, genlist: build.GeneratedList, generator_id: int, objects_dict: PbxDict) -> None: # TODO: this should be rewritten to use the meson wrapper, like the other generators do # Currently it doesn't handle a host binary that requires an exe wrapper correctly. diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0b6400732af7..832e077112b8 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -36,7 +36,7 @@ from .interpreterbase import FeatureNew, FeatureDeprecated if T.TYPE_CHECKING: - from typing_extensions import Literal, TypedDict + from typing_extensions import Literal, TypeAlias, TypedDict from . import environment from ._typing import ImmutableListProtocol @@ -50,10 +50,11 @@ from .modules import ModuleState from .mparser import BaseNode - GeneratedTypes = T.Union['CustomTarget', 'CustomTargetIndex', 'GeneratedList'] - LibTypes = T.Union['SharedLibrary', 'StaticLibrary', 'CustomTarget', 'CustomTargetIndex'] - BuildTargetTypes = T.Union['BuildTarget', 'CustomTarget', 'CustomTargetIndex'] - ObjectTypes = T.Union[str, 'File', 'ExtractedObjects', 'GeneratedTypes'] + GeneratedTypes: TypeAlias = T.Union['CustomTarget', 'CustomTargetIndex', 'GeneratedList'] + LibTypes: TypeAlias = T.Union['SharedLibrary', 'StaticLibrary', 'CustomTarget', 'CustomTargetIndex'] + BuildTargetTypes: TypeAlias = T.Union['BuildTarget', 'CustomTarget', 'CustomTargetIndex'] + ObjectTypes: TypeAlias = T.Union[str, 'File', 'ExtractedObjects', 'GeneratedTypes'] + AnyTargetType: TypeAlias = T.Union['Target', 'CustomTargetIndex'] class DFeatures(TypedDict): @@ -493,7 +494,7 @@ class StructuredSources(HoldableObject): represent the required filesystem layout. """ - sources: T.DefaultDict[str, T.List[T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]]] = field( + sources: T.DefaultDict[str, T.List[T.Union[File, GeneratedTypes]]] = field( default_factory=lambda: defaultdict(list)) def __add__(self, other: StructuredSources) -> StructuredSources: @@ -505,14 +506,14 @@ def __add__(self, other: StructuredSources) -> StructuredSources: def __bool__(self) -> bool: return bool(self.sources) - def first_file(self) -> T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]: + def first_file(self) -> T.Union[File, GeneratedTypes]: """Get the first source in the root :return: The first source in the root """ return self.sources[''][0] - def as_list(self) -> T.List[T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]]: + def as_list(self) -> T.List[T.Union[File, GeneratedTypes]]: return list(itertools.chain.from_iterable(self.sources.values())) def needs_copy(self) -> bool: @@ -723,7 +724,7 @@ def __init__( self.link_targets: T.List[LibTypes] = [] self.link_whole_targets: T.List[T.Union[StaticLibrary, CustomTarget, CustomTargetIndex]] = [] self.depend_files: T.List[File] = [] - self.link_depends: T.List[T.Union[File, CustomTarget, CustomTargetIndex, BuildTarget]] = [] + self.link_depends: T.List[T.Union[File, BuildTargetTypes]] = [] self.added_deps = set() self.name_prefix_set = False self.name_suffix_set = False @@ -1027,7 +1028,7 @@ def validate_sources(self): langs = ', '.join(self.compilers.keys()) raise InvalidArguments(f'Cannot mix those languages into a target: {langs}') - def process_link_depends(self, sources: T.Iterable[T.Union[str, File, CustomTarget, CustomTargetIndex, BuildTarget]]) -> None: + def process_link_depends(self, sources: T.Iterable[T.Union[str, File, BuildTargetTypes]]) -> None: """Process the link_depends keyword argument. This is designed to handle strings, Files, and the output of Custom @@ -1988,12 +1989,12 @@ def __init__(self, exe: T.Union['Executable', programs.ExternalProgram], *, depfile: T.Optional[str] = None, capture: bool = False, - depends: T.Optional[T.List[T.Union[BuildTarget, 'CustomTarget', 'CustomTargetIndex']]] = None, + depends: T.Optional[T.List[BuildTargetTypes]] = None, name: str = 'Generator'): self.exe = exe self.depfile = depfile self.capture = capture - self.depends: T.List[T.Union[BuildTarget, 'CustomTarget', 'CustomTargetIndex']] = depends or [] + self.depends: T.List[BuildTargetTypes] = depends or [] self.arglist = arguments self.outputs = output self.name = name @@ -2023,7 +2024,7 @@ def get_arglist(self, inname: str) -> T.List[str]: basename = os.path.splitext(plainname)[0] return [x.replace('@BASENAME@', basename).replace('@PLAINNAME@', plainname) for x in self.arglist] - def process_files(self, files: T.Iterable[T.Union[str, File, 'CustomTarget', 'CustomTargetIndex', 'GeneratedList']], + def process_files(self, files: T.Iterable[T.Union[str, File, GeneratedTypes]], state: T.Union['Interpreter', 'ModuleState'], preserve_path_from: T.Optional[str] = None, extra_args: T.Optional[T.List[str]] = None, @@ -3077,7 +3078,7 @@ def __init__(self, compile_args: T.List[str], include_directories: T.List[IncludeDirs], dependencies: T.List[dependencies.Dependency], - depends: T.List[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]): + depends: T.List[BuildTargetTypes]): compilers = {compiler.get_language(): compiler} kwargs = { 'build_by_default': False, @@ -3122,7 +3123,7 @@ class RunTarget(Target, CommandBase): def __init__(self, name: str, command: T.Sequence[T.Union[str, File, BuildTargetTypes, programs.ExternalProgram]], - dependencies: T.Sequence[T.Union[Target, CustomTargetIndex]], + dependencies: T.Sequence[AnyTargetType], subdir: str, subproject: str, environment: environment.Environment, @@ -3141,7 +3142,7 @@ def __repr__(self) -> str: repr_str = "<{0} {1}: {2}>" return repr_str.format(self.__class__.__name__, self.get_id(), self.command[0]) - def get_dependencies(self) -> T.List[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]: + def get_dependencies(self) -> T.List[BuildTargetTypes]: return self.dependencies def get_generated_sources(self) -> T.List[GeneratedTypes]: diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py index 57e9499614ae..99204be10df5 100644 --- a/mesonbuild/interpreter/compiler.py +++ b/mesonbuild/interpreter/compiler.py @@ -96,7 +96,7 @@ class PreprocessKW(TypedDict): compile_args: T.List[str] include_directories: T.List[build.IncludeDirs] dependencies: T.List[dependencies.Dependency] - depends: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]] + depends: T.List[build.BuildTargetTypes] class _TestMode(enum.Enum): @@ -148,7 +148,7 @@ def stderr_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str: listify=True, default=[], ) -_DEPENDS_KW: KwargInfo[T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]]] = KwargInfo( +_DEPENDS_KW: KwargInfo[T.List[build.BuildTargetTypes]] = KwargInfo( 'depends', ContainerTypeInfo(list, (build.BuildTarget, build.CustomTarget, build.CustomTargetIndex)), listify=True, diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index a682bc82273c..dabd0372744f 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -121,13 +121,11 @@ from .type_checking import SourcesVarargsType # Input source types passed to Targets - SourceInputs = T.Union[mesonlib.File, build.GeneratedList, build.BuildTarget, build.BothLibraries, - build.CustomTargetIndex, build.CustomTarget, build.GeneratedList, - build.ExtractedObjects, str] + SourceInputs = T.Union[mesonlib.FileOrString, build.GeneratedTypes, build.BuildTarget, + build.BothLibraries, build.ExtractedObjects] # 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.StructuredSources] + SourceOutputs = T.Union[mesonlib.File, build.GeneratedTypes, build.BuildTarget, + build.ExtractedObjects, build.StructuredSources] BuildTargetSource = T.Union[mesonlib.FileOrString, build.GeneratedTypes, build.StructuredSources] diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 7dd49a1db663..43e3cb30bcd8 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -182,16 +182,15 @@ class CustomTarget(TypedDict): build_always_stale: T.Optional[bool] build_by_default: T.Optional[bool] capture: bool - command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, - build.CustomTargetIndex, ExternalProgram, File]] + command: T.List[T.Union[str, build.BuildTargetTypes, ExternalProgram, File]] console: bool depend_files: T.List[FileOrString] depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]] depfile: T.Optional[str] env: EnvironmentVariables feed: bool - input: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, - build.ExtractedObjects, build.GeneratedList, ExternalProgram, File]] + input: T.List[T.Union[str, build.BuildTarget, build.GeneratedTypes, + build.ExtractedObjects, ExternalProgram, File]] install: bool install_dir: T.List[T.Union[str, T.Literal[False]]] install_mode: FileMode @@ -282,11 +281,10 @@ class ConfigurationDataSet(TypedDict): class VcsTag(TypedDict): - command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, - build.CustomTargetIndex, ExternalProgram, File]] + command: T.List[T.Union[str, build.GeneratedTypes, ExternalProgram, File]] fallback: T.Optional[str] - input: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, - build.ExtractedObjects, build.GeneratedList, ExternalProgram, File]] + input: T.List[T.Union[str, build.BuildTarget, build.GeneratedTypes, + build.ExtractedObjects, ExternalProgram, File]] output: T.List[str] replace_string: str install: bool @@ -343,7 +341,7 @@ class _BaseBuildTarget(TypedDict): install_mode: FileMode install_rpath: str implicit_include_directories: bool - link_depends: T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.BuildTarget]] + link_depends: T.List[T.Union[str, File, build.GeneratedTypes]] link_language: T.Optional[str] name_prefix: T.Optional[str] name_suffix: T.Optional[str] @@ -469,7 +467,7 @@ class Jar(_BaseBuildTarget): main_class: str java_resources: T.Optional[build.StructuredSources] - sources: T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList, build.ExtractedObjects, build.BuildTarget] + sources: T.Union[str, File, build.GeneratedTypes, build.ExtractedObjects, build.BuildTarget] java_args: T.List[str] @@ -492,4 +490,4 @@ class FuncDeclareDependency(TypedDict): class FuncDependency(TypedDict): - default_options: T.Dict[OptionKey, T.Union[str, int, bool, T.List[str]]] + default_options: T.Dict[OptionKey, options.ElementaryOptionValues] diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py index 602575c57d03..d22d36bf0613 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -129,7 +129,7 @@ def _process_script_args( def add_install_script_method( self, args: T.Tuple[T.Union[str, mesonlib.File, build.Executable, ExternalProgram], - T.List[T.Union[str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, ExternalProgram]]], + T.List[T.Union[str, mesonlib.File, build.BuildTargetTypes, ExternalProgram]]], kwargs: 'AddInstallScriptKW') -> None: script_args = self._process_script_args('add_install_script', args[1]) script = self._find_source_script('add_install_script', args[0], script_args) diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index a551d0f7c47f..567cd1e5980d 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -24,14 +24,14 @@ if T.TYPE_CHECKING: from typing_extensions import Literal - from ..build import ObjectTypes + from ..build import ObjectTypes, GeneratedTypes, BuildTargetTypes from ..interpreterbase import TYPE_var from ..options import ElementaryOptionValues from ..mesonlib import EnvInitValueType _FullEnvInitValueType = T.Union[EnvironmentVariables, T.List[str], T.List[T.List[str]], EnvInitValueType, str, None] PkgConfigDefineType = T.Optional[T.Tuple[T.Tuple[str, str], ...]] - SourcesVarargsType = T.List[T.Union[str, File, CustomTarget, CustomTargetIndex, GeneratedList, StructuredSources, ExtractedObjects, BuildTarget]] + SourcesVarargsType = T.List[T.Union[str, File, GeneratedTypes, StructuredSources, ExtractedObjects, BuildTarget]] def in_set_validator(choices: T.Set[str]) -> T.Callable[[str], T.Optional[str]]: @@ -269,7 +269,7 @@ def _env_convertor(value: _FullEnvInitValueType) -> EnvironmentVariables: validator=lambda x: 'Depfile must be a plain filename with a subdirectory' if has_path_sep(x) else None ) -DEPENDS_KW: KwargInfo[T.List[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]] = KwargInfo( +DEPENDS_KW: KwargInfo[T.List[BuildTargetTypes]] = KwargInfo( 'depends', ContainerTypeInfo(list, (BuildTarget, CustomTarget, CustomTargetIndex)), listify=True, @@ -284,7 +284,7 @@ def _env_convertor(value: _FullEnvInitValueType) -> EnvironmentVariables: default=[], ) -COMMAND_KW: KwargInfo[T.List[T.Union[str, BuildTarget, CustomTarget, CustomTargetIndex, ExternalProgram, File]]] = KwargInfo( +COMMAND_KW: KwargInfo[T.List[T.Union[str, BuildTargetTypes, ExternalProgram, File]]] = KwargInfo( 'command', ContainerTypeInfo(list, (str, BuildTarget, CustomTarget, CustomTargetIndex, ExternalProgram, File), allow_empty=False), required=True, @@ -349,7 +349,7 @@ def _output_validator(outputs: T.List[str]) -> T.Optional[str]: validator=lambda x: _output_validator([x]) ) -CT_INPUT_KW: KwargInfo[T.List[T.Union[str, File, ExternalProgram, BuildTarget, CustomTarget, CustomTargetIndex, ExtractedObjects, GeneratedList]]] = KwargInfo( +CT_INPUT_KW: KwargInfo[T.List[T.Union[str, File, ExternalProgram, BuildTarget, GeneratedTypes, ExtractedObjects]]] = KwargInfo( 'input', ContainerTypeInfo(list, (str, File, ExternalProgram, BuildTarget, CustomTarget, CustomTargetIndex, ExtractedObjects, GeneratedList)), listify=True, @@ -461,7 +461,7 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus validator=link_whole_validator, ) -DEPENDENCY_SOURCES_KW: KwargInfo[T.List[T.Union[str, File, CustomTarget, CustomTargetIndex, GeneratedList]]] = KwargInfo( +DEPENDENCY_SOURCES_KW: KwargInfo[T.List[T.Union[str, File, GeneratedTypes]]] = KwargInfo( 'sources', ContainerTypeInfo(list, (str, File, CustomTarget, CustomTargetIndex, GeneratedList)), listify=True, diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index b4505fdb94b8..aeda4837ef64 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -378,7 +378,7 @@ def list_deps_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[str, def list_deps(coredata: cdata.CoreData, backend: backends.Backend) -> T.List[T.Dict[str, T.Union[str, T.List[str]]]]: result: T.Dict[str, T.Dict[str, T.Union[str, T.List[str]]]] = {} - def _src_to_str(src_file: T.Union[mesonlib.FileOrString, build.CustomTarget, build.StructuredSources, build.CustomTargetIndex, build.GeneratedList]) -> T.List[str]: + def _src_to_str(src_file: T.Union[mesonlib.FileOrString, build.GeneratedTypes, build.StructuredSources]) -> T.List[str]: if isinstance(src_file, str): return [src_file] if isinstance(src_file, mesonlib.File): diff --git a/mesonbuild/modules/_qt.py b/mesonbuild/modules/_qt.py index 7d52842f9dd4..675c174a7b92 100644 --- a/mesonbuild/modules/_qt.py +++ b/mesonbuild/modules/_qt.py @@ -39,7 +39,7 @@ class ResourceCompilerKwArgs(TypedDict): """Keyword arguments for the Resource Compiler method.""" name: T.Optional[str] - sources: T.Sequence[T.Union[FileOrString, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]] + sources: T.Sequence[T.Union[FileOrString, build.GeneratedTypes]] extra_args: T.List[str] method: str @@ -47,7 +47,7 @@ class UICompilerKwArgs(TypedDict): """Keyword arguments for the Ui Compiler method.""" - sources: T.Sequence[T.Union[FileOrString, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]] + sources: T.Sequence[T.Union[FileOrString, build.GeneratedTypes]] extra_args: T.List[str] method: str preserve_paths: bool @@ -56,8 +56,8 @@ class MocCompilerKwArgs(TypedDict): """Keyword arguments for the Moc Compiler method.""" - sources: T.Sequence[T.Union[FileOrString, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]] - headers: T.Sequence[T.Union[FileOrString, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]] + sources: T.Sequence[T.Union[FileOrString, build.GeneratedTypes]] + headers: T.Sequence[T.Union[FileOrString, build.GeneratedTypes]] extra_args: T.List[str] method: str include_directories: T.List[T.Union[str, build.IncludeDirs]] @@ -94,7 +94,7 @@ class CompileTranslationsKwArgs(TypedDict): method: str qresource: T.Optional[str] rcc_extra_arguments: T.List[str] - ts_files: T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]] + ts_files: T.List[T.Union[str, File, build.GeneratedTypes]] class GenQrcKwArgs(TypedDict): @@ -325,7 +325,7 @@ def _qrc_nodes(state: ModuleState, rcc_file: FileOrString) -> T.Tuple[str, T.Lis raise MesonException(f'Unable to parse resource file {abspath}') def _parse_qrc_deps(self, state: ModuleState, - rcc_file_: T.Union[FileOrString, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]) -> T.List[File]: + rcc_file_: T.Union[FileOrString, build.GeneratedTypes]) -> T.List[File]: result: T.List[File] = [] inputs: T.Sequence['FileOrString'] = [] if isinstance(rcc_file_, (str, File)): diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 70b1165a2fd0..4874e6158069 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -648,7 +648,7 @@ def _get_link_args(self, state: 'ModuleState', return link_command, new_depends def _get_dependencies_flags_raw( - self, deps: T.Sequence[T.Union['Dependency', build.BuildTarget, CustomTarget, CustomTargetIndex]], + self, deps: T.Sequence[T.Union['Dependency', build.BuildTargetTypes]], state: 'ModuleState', depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString', build.StructuredSources]], include_rpath: bool, @@ -741,7 +741,7 @@ def fix_ldflags(ldflags: T.Iterable[T.Union[str, T.Tuple[str, str]]]) -> Ordered return cflags, internal_ldflags, external_ldflags, gi_includes, depends def _get_dependencies_flags( - self, deps: T.Sequence[T.Union['Dependency', build.BuildTarget, CustomTarget, CustomTargetIndex]], + self, deps: T.Sequence[T.Union['Dependency', build.BuildTargetTypes]], state: 'ModuleState', depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString', build.StructuredSources]], include_rpath: bool = False, @@ -895,8 +895,8 @@ def _get_girtargets_langs_compilers(girtargets: T.Sequence[build.BuildTarget]) - @staticmethod def _get_gir_targets_deps(girtargets: T.Sequence[build.BuildTarget] - ) -> T.List[T.Union[build.BuildTarget, CustomTarget, CustomTargetIndex, Dependency]]: - ret: T.List[T.Union[build.BuildTarget, CustomTarget, CustomTargetIndex, Dependency]] = [] + ) -> T.List[T.Union[build.BuildTargetTypes, Dependency]]: + ret: T.List[T.Union[build.BuildTargetTypes, Dependency]] = [] for girtarget in girtargets: ret += girtarget.get_all_link_deps() ret += girtarget.get_external_deps() @@ -972,7 +972,7 @@ def _make_gir_target( state: 'ModuleState', girfile: str, scan_command: T.Sequence[T.Union['FileOrString', Executable, ExternalProgram, OverrideProgram]], - generated_files: T.Sequence[T.Union[str, mesonlib.File, CustomTarget, CustomTargetIndex, GeneratedList]], + generated_files: T.Sequence[T.Union[str, mesonlib.File, build.GeneratedTypes]], depends: T.Sequence[T.Union['FileOrString', build.BuildTarget, 'build.GeneratedTypes', build.StructuredSources]], env_flags: T.Sequence[str], kwargs: T.Dict[str, T.Any]) -> GirTarget: @@ -1021,7 +1021,7 @@ def _make_gir_target( @staticmethod def _make_typelib_target(state: 'ModuleState', typelib_output: str, typelib_cmd: T.Sequence[T.Union[str, Executable, ExternalProgram, CustomTarget]], - generated_files: T.Sequence[T.Union[str, mesonlib.File, CustomTarget, CustomTargetIndex, GeneratedList]], + generated_files: T.Sequence[T.Union[str, mesonlib.File, build.GeneratedTypes]], kwargs: T.Dict[str, T.Any]) -> TypelibTarget: install = kwargs['install_typelib'] if install is None: @@ -1051,7 +1051,7 @@ def _make_typelib_target(state: 'ModuleState', typelib_output: str, @staticmethod def _gather_typelib_includes_and_update_depends( state: 'ModuleState', - deps: T.Sequence[T.Union[Dependency, build.BuildTarget, CustomTarget, CustomTargetIndex]], + deps: T.Sequence[T.Union[Dependency, build.BuildTargetTypes]], depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString', build.StructuredSources]] ) -> T.Tuple[T.List[str], T.List[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString', build.StructuredSources]]]: # Need to recursively add deps on GirTarget sources from our @@ -2041,13 +2041,13 @@ def mkenums_simple(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'MkEn def _make_mkenum_impl( self, state: 'ModuleState', - sources: T.Sequence[T.Union[str, mesonlib.File, CustomTarget, CustomTargetIndex, GeneratedList]], + sources: T.Sequence[T.Union[str, mesonlib.File, build.GeneratedTypes]], output: str, cmd: T.List[str], *, install: bool = False, install_dir: T.Optional[T.Sequence[T.Union[str, bool]]] = None, - depends: T.Optional[T.Sequence[T.Union[CustomTarget, CustomTargetIndex, BuildTarget]]] = None + depends: T.Optional[T.Sequence[build.BuildTargetTypes]] = None ) -> build.CustomTarget: real_cmd: T.List[T.Union[str, 'ToolType']] = [self._find_tool(state, 'glib-mkenums')] real_cmd.extend(cmd) diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py index 8b830658483b..2d8d04d3ec30 100644 --- a/mesonbuild/modules/i18n.py +++ b/mesonbuild/modules/i18n.py @@ -56,16 +56,15 @@ class Gettext(TypedDict): class ItsJoinFile(TypedDict): input: T.List[T.Union[ - str, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, - build.ExtractedObjects, build.GeneratedList, ExternalProgram, - mesonlib.File]] + str, build.BuildTarget, build.GeneratedTypes, + build.ExtractedObjects, ExternalProgram, mesonlib.File]] output: str build_by_default: bool install: bool install_dir: T.Optional[str] install_tag: T.Optional[str] its_files: T.List[str] - mo_targets: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]] + mo_targets: T.List[build.BuildTargetTypes] class XgettextProgramT(TypedDict): @@ -75,7 +74,7 @@ class XgettextProgramT(TypedDict): install_dir: T.Optional[str] install_tag: T.Optional[str] - SourcesType = T.Union[str, mesonlib.File, build.BuildTarget, build.BothLibraries, build.CustomTarget, build.CustomTargetIndex] + SourcesType = T.Union[str, mesonlib.File, build.BuildTargetTypes, build.BothLibraries] _ARGS: KwargInfo[T.List[str]] = KwargInfo( @@ -239,7 +238,7 @@ def _get_rsp_file(self, return mesonlib.File.from_built_file(self.interpreter.subdir, rsp_file.name) @staticmethod - def _get_source_id(sources: T.Iterable[T.Union[SourcesType, build.CustomTargetIndex]]) -> T.Iterable[str]: + def _get_source_id(sources: T.Iterable[SourcesType]) -> T.Iterable[str]: for source in sources: if isinstance(source, build.Target): yield source.get_id() @@ -309,8 +308,7 @@ def merge_file(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: 'Me ddirs = self._get_data_dirs(state, kwargs['data_dirs']) datadirs = '--datadirs=' + ':'.join(ddirs) if ddirs else None - command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, - build.CustomTargetIndex, 'ExternalProgram', mesonlib.File]] = [] + command: T.List[T.Union[str, build.BuildTargetTypes, ExternalProgram, mesonlib.File]] = [] command.extend(state.environment.get_build_command()) command.extend([ '--internal', 'msgfmthelper', @@ -489,8 +487,7 @@ def itstool_join(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: ' for target in mo_targets: mo_fnames.append(path.join(target.get_subdir(), target.get_outputs()[0])) - command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, - build.CustomTargetIndex, 'ExternalProgram', mesonlib.File]] = [] + command: T.List[T.Union[str, build.BuildTargetTypes, ExternalProgram, mesonlib.File]] = [] command.extend(state.environment.get_build_command()) itstool_cmd = self.tools['itstool'].get_command()