aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2021-01-14 15:17:49 +0000
committerGitHub <noreply@github.com>2021-01-14 15:17:49 +0000
commit4b3d48a8c94e28e12dc928fb343f52f3b669510d (patch)
tree5f0072f487f652df96b1a6266b1499220c08c485 /mesonbuild/build.py
parente3bd45c7c35e56987836b4d675c306bbe035fb78 (diff)
parent1849a9e9b7218ecb695a8414eba9e15ebdc3fe1e (diff)
downloadmeson-4b3d48a8c94e28e12dc928fb343f52f3b669510d.zip
meson-4b3d48a8c94e28e12dc928fb343f52f3b669510d.tar.gz
meson-4b3d48a8c94e28e12dc928fb343f52f3b669510d.tar.bz2
Merge pull request #8192 from dcbaker/submit/minstall-type-annotations
Add type annotations to minstall (and some related cleanups)
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r--mesonbuild/build.py57
1 files changed, 37 insertions, 20 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index dacf68b..017b0f0 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -171,6 +171,21 @@ class Man:
return self.sources
+class InstallDir:
+
+ def __init__(self, src_subdir: str, inst_subdir: str, install_dir: str,
+ install_mode: T.Optional['FileMode'],
+ exclude: T.Tuple[T.Set[str], T.Set[str]],
+ strip_directory: bool, from_source_dir: bool = True):
+ self.source_subdir = src_subdir
+ self.installable_subdir = inst_subdir
+ self.install_dir = install_dir
+ self.install_mode = install_mode
+ self.exclude = exclude
+ self.strip_directory = strip_directory
+ self.from_source_dir = from_source_dir
+
+
class Build:
"""A class that holds the status of one build including
all dependencies and so on.
@@ -198,7 +213,7 @@ class Build:
self.install_scripts = []
self.postconf_scripts = []
self.dist_scripts = []
- self.install_dirs = []
+ self.install_dirs: T.List[InstallDir] = []
self.dep_manifest_name = None
self.dep_manifest = {}
self.stdlibs = PerMachine({}, {})
@@ -404,6 +419,9 @@ class EnvironmentVariables:
return env
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):
if has_path_sep(name):
# Fix failing test 53 when this becomes an error.
@@ -443,7 +461,10 @@ a hard error in the future.'''.format(name))
return NotImplemented
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.
default_install_dir = self.get_default_install_dir(environment)
outdirs = self.get_custom_install_dir()
@@ -554,7 +575,7 @@ class BuildTarget(Target):
self.external_deps = []
self.include_dirs = []
self.link_language = kwargs.get('link_language')
- self.link_targets = []
+ self.link_targets: T.List[BuildTarget] = []
self.link_whole_targets = []
self.link_depends = []
self.added_deps = set()
@@ -572,7 +593,7 @@ class BuildTarget(Target):
self.pic = False
self.pie = False
# 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:
# 1. Pre-existing source files in the source tree
# 2. Pre-existing sources generated by configure_file in the build tree
@@ -884,7 +905,7 @@ class BuildTarget(Target):
result.update(i.get_link_dep_subdirs())
return result
- def get_default_install_dir(self, environment):
+ def get_default_install_dir(self, environment: environment.Environment) -> str:
return environment.get_libdir()
def get_custom_install_dir(self):
@@ -995,7 +1016,7 @@ This will become a hard error in a future Meson release.''')
if not(os.path.isfile(trial)):
raise InvalidArguments('Tried to add non-existing extra file {}.'.format(i))
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):
raise InvalidArguments('Install_rpath is not a string.')
self.build_rpath = kwargs.get('build_rpath', '')
@@ -1299,7 +1320,7 @@ You probably should put it in link_with instead.''')
else:
self.extra_args[language] = args
- def get_aliases(self):
+ def get_aliases(self) -> T.Dict[str, str]:
return {}
def get_langs_used_by_deps(self) -> T.List[str]:
@@ -1673,7 +1694,7 @@ class Executable(BuildTarget):
# Only linkwithable if using 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()
def description(self):
@@ -1802,8 +1823,8 @@ class SharedLibrary(BuildTarget):
self.basic_filename_tpl = '{0.prefix}{0.name}.{0.suffix}'
self.determine_filenames(environment)
- def get_link_deps_mapping(self, prefix, environment):
- result = {}
+ def get_link_deps_mapping(self, prefix, environment) -> T.Dict[str, str]:
+ result: T.Dict[str, str] = {}
mappings = self.get_transitive_link_deps_mapping(prefix, environment)
old = get_target_macos_dylib_install_name(self)
if old not in mappings:
@@ -2053,7 +2074,7 @@ class SharedLibrary(BuildTarget):
def get_all_link_deps(self):
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:
* libfoo.so.0 (soversion) -> libfoo.so.0.100.0
@@ -2061,11 +2082,11 @@ class SharedLibrary(BuildTarget):
Same for 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
# there's no self.soversion (no versioning), we don't need aliases.
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
# filename. If ltversion != soversion we create an soversion alias:
# libfoo.so.0 -> libfoo.so.0.100.0
@@ -2567,19 +2588,15 @@ class ConfigurationData:
# A bit poorly named, but this represents plain data files to copy
# during install.
class Data:
- def __init__(self, sources, install_dir, install_mode=None, rename=None):
+ def __init__(self, sources: T.List[File], install_dir: str,
+ install_mode: T.Optional['FileMode'] = None, rename: T.List[str] = None):
self.sources = sources
self.install_dir = install_dir
self.install_mode = install_mode
- self.sources = listify(self.sources)
- for s in self.sources:
- assert(isinstance(s, File))
if rename is None:
self.rename = [os.path.basename(f.fname) for f in self.sources]
else:
- self.rename = stringlistify(rename)
- if len(self.rename) != len(self.sources):
- raise MesonException('Size of rename argument is different from number of sources')
+ self.rename = rename
class RunScript(dict):
def __init__(self, script, args):