Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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! '
Expand All @@ -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]:
Expand Down Expand Up @@ -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.
Expand All @@ -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 = ''
Expand All @@ -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),
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [], [], [])
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/backend/xcodebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
33 changes: 17 additions & 16 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/interpreter/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading