build: Add some type annotations

pull/8192/head
Dylan Baker 4 years ago
parent 022632c91b
commit 59328aba29
  1. 30
      mesonbuild/build.py
  2. 2
      mesonbuild/minstall.py

@ -404,6 +404,9 @@ class EnvironmentVariables:
return env return env
class Target: class Target:
# TODO: should Target be an abc.ABCMeta?
def __init__(self, name: str, subdir: str, subproject: str, build_by_default: bool, for_machine: MachineChoice): def __init__(self, name: str, subdir: str, subproject: str, build_by_default: bool, for_machine: MachineChoice):
if has_path_sep(name): if has_path_sep(name):
# Fix failing test 53 when this becomes an error. # Fix failing test 53 when this becomes an error.
@ -443,7 +446,10 @@ a hard error in the future.'''.format(name))
return NotImplemented return NotImplemented
return self.get_id() >= other.get_id() return self.get_id() >= other.get_id()
def get_install_dir(self, environment): def get_default_install_dir(self, env: environment.Environment) -> str:
raise NotImplementedError
def get_install_dir(self, environment: environment.Environment) -> T.Tuple[T.Any, bool]:
# Find the installation directory. # Find the installation directory.
default_install_dir = self.get_default_install_dir(environment) default_install_dir = self.get_default_install_dir(environment)
outdirs = self.get_custom_install_dir() outdirs = self.get_custom_install_dir()
@ -554,7 +560,7 @@ class BuildTarget(Target):
self.external_deps = [] self.external_deps = []
self.include_dirs = [] self.include_dirs = []
self.link_language = kwargs.get('link_language') self.link_language = kwargs.get('link_language')
self.link_targets = [] self.link_targets: T.List[BuildTarget] = []
self.link_whole_targets = [] self.link_whole_targets = []
self.link_depends = [] self.link_depends = []
self.added_deps = set() self.added_deps = set()
@ -572,7 +578,7 @@ class BuildTarget(Target):
self.pic = False self.pic = False
self.pie = False self.pie = False
# Track build_rpath entries so we can remove them at install time # Track build_rpath entries so we can remove them at install time
self.rpath_dirs_to_remove = set() self.rpath_dirs_to_remove: T.Set[bytes] = set()
# Sources can be: # Sources can be:
# 1. Pre-existing source files in the source tree # 1. Pre-existing source files in the source tree
# 2. Pre-existing sources generated by configure_file in the build tree # 2. Pre-existing sources generated by configure_file in the build tree
@ -884,7 +890,7 @@ class BuildTarget(Target):
result.update(i.get_link_dep_subdirs()) result.update(i.get_link_dep_subdirs())
return result return result
def get_default_install_dir(self, environment): def get_default_install_dir(self, environment: environment.Environment) -> str:
return environment.get_libdir() return environment.get_libdir()
def get_custom_install_dir(self): def get_custom_install_dir(self):
@ -995,7 +1001,7 @@ This will become a hard error in a future Meson release.''')
if not(os.path.isfile(trial)): if not(os.path.isfile(trial)):
raise InvalidArguments('Tried to add non-existing extra file {}.'.format(i)) raise InvalidArguments('Tried to add non-existing extra file {}.'.format(i))
self.extra_files = extra_files self.extra_files = extra_files
self.install_rpath = kwargs.get('install_rpath', '') self.install_rpath: str = kwargs.get('install_rpath', '')
if not isinstance(self.install_rpath, str): if not isinstance(self.install_rpath, str):
raise InvalidArguments('Install_rpath is not a string.') raise InvalidArguments('Install_rpath is not a string.')
self.build_rpath = kwargs.get('build_rpath', '') self.build_rpath = kwargs.get('build_rpath', '')
@ -1299,7 +1305,7 @@ You probably should put it in link_with instead.''')
else: else:
self.extra_args[language] = args self.extra_args[language] = args
def get_aliases(self): def get_aliases(self) -> T.Dict[str, str]:
return {} return {}
def get_langs_used_by_deps(self) -> T.List[str]: def get_langs_used_by_deps(self) -> T.List[str]:
@ -1673,7 +1679,7 @@ class Executable(BuildTarget):
# Only linkwithable if using export_dynamic # Only linkwithable if using export_dynamic
self.is_linkwithable = self.export_dynamic self.is_linkwithable = self.export_dynamic
def get_default_install_dir(self, environment): def get_default_install_dir(self, environment: environment.Environment) -> str:
return environment.get_bindir() return environment.get_bindir()
def description(self): def description(self):
@ -1802,8 +1808,8 @@ class SharedLibrary(BuildTarget):
self.basic_filename_tpl = '{0.prefix}{0.name}.{0.suffix}' self.basic_filename_tpl = '{0.prefix}{0.name}.{0.suffix}'
self.determine_filenames(environment) self.determine_filenames(environment)
def get_link_deps_mapping(self, prefix, environment): def get_link_deps_mapping(self, prefix, environment) -> T.Dict[str, str]:
result = {} result: T.Dict[str, str] = {}
mappings = self.get_transitive_link_deps_mapping(prefix, environment) mappings = self.get_transitive_link_deps_mapping(prefix, environment)
old = get_target_macos_dylib_install_name(self) old = get_target_macos_dylib_install_name(self)
if old not in mappings: if old not in mappings:
@ -2053,7 +2059,7 @@ class SharedLibrary(BuildTarget):
def get_all_link_deps(self): def get_all_link_deps(self):
return [self] + self.get_transitive_link_deps() return [self] + self.get_transitive_link_deps()
def get_aliases(self): def get_aliases(self) -> T.Dict[str, str]:
""" """
If the versioned library name is libfoo.so.0.100.0, aliases are: If the versioned library name is libfoo.so.0.100.0, aliases are:
* libfoo.so.0 (soversion) -> libfoo.so.0.100.0 * libfoo.so.0 (soversion) -> libfoo.so.0.100.0
@ -2061,11 +2067,11 @@ class SharedLibrary(BuildTarget):
Same for dylib: Same for dylib:
* libfoo.dylib (unversioned; for linking) -> libfoo.0.dylib * libfoo.dylib (unversioned; for linking) -> libfoo.0.dylib
""" """
aliases = {} aliases: T.Dict[str, str] = {}
# Aliases are only useful with .so and .dylib libraries. Also if # Aliases are only useful with .so and .dylib libraries. Also if
# there's no self.soversion (no versioning), we don't need aliases. # there's no self.soversion (no versioning), we don't need aliases.
if self.suffix not in ('so', 'dylib') or not self.soversion: if self.suffix not in ('so', 'dylib') or not self.soversion:
return {} return aliases
# With .so libraries, the minor and micro versions are also in the # With .so libraries, the minor and micro versions are also in the
# filename. If ltversion != soversion we create an soversion alias: # filename. If ltversion != soversion we create an soversion alias:
# libfoo.so.0 -> libfoo.so.0.100.0 # libfoo.so.0 -> libfoo.so.0.100.0

@ -538,6 +538,7 @@ class Installer:
else: else:
raise raise
def rebuild_all(wd: str) -> bool: def rebuild_all(wd: str) -> bool:
if not (Path(wd) / 'build.ninja').is_file(): if not (Path(wd) / 'build.ninja').is_file():
print('Only ninja backend is supported to rebuild the project before installation.') print('Only ninja backend is supported to rebuild the project before installation.')
@ -555,6 +556,7 @@ def rebuild_all(wd: str) -> bool:
return True return True
def run(opts): def run(opts):
datafilename = 'meson-private/install.dat' datafilename = 'meson-private/install.dat'
private_dir = os.path.dirname(datafilename) private_dir = os.path.dirname(datafilename)

Loading…
Cancel
Save