aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r--mesonbuild/build.py89
1 files changed, 69 insertions, 20 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 5b7a679..091bfc8 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -39,6 +39,7 @@ from .interpreterbase import FeatureNew
if T.TYPE_CHECKING:
from .interpreter import Test
+ from .mesonlib import FileMode, FileOrString
pch_kwargs = set(['c_pch', 'cpp_pch'])
@@ -122,6 +123,52 @@ class DependencyOverride:
self.node = node
self.explicit = explicit
+class Headers:
+
+ def __init__(self, sources: T.List[File], install_subdir: T.Optional[str],
+ install_dir: T.Optional[str], install_mode: T.Optional['FileMode']):
+ self.sources = sources
+ self.install_subdir = install_subdir
+ self.custom_install_dir = install_dir
+ self.custom_install_mode = install_mode
+
+ # TODO: we really don't need any of these methods, but they're preserved to
+ # keep APIs relying on them working.
+
+ def set_install_subdir(self, subdir: str) -> None:
+ self.install_subdir = subdir
+
+ def get_install_subdir(self) -> str:
+ return self.install_subdir
+
+ def get_sources(self) -> T.List[File]:
+ return self.sources
+
+ def get_custom_install_dir(self) -> T.Optional[str]:
+ return self.custom_install_dir
+
+ def get_custom_install_mode(self) -> T.Optional['FileMode']:
+ return self.custom_install_mode
+
+
+class Man:
+
+ def __init__(self, sources: T.List[File], install_dir: T.Optional[str],
+ install_mode: T.Optional['FileMode']):
+ self.sources = sources
+ self.custom_install_dir = install_dir
+ self.custom_install_mode = install_mode
+
+ def get_custom_install_dir(self) -> T.Optional[str]:
+ return self.custom_install_dir
+
+ def get_custom_install_mode(self) -> T.Optional['FileMode']:
+ return self.custom_install_mode
+
+ def get_sources(self) -> T.List['File']:
+ return self.sources
+
+
class Build:
"""A class that holds the status of one build including
all dependencies and so on.
@@ -132,18 +179,18 @@ class Build:
self.project_version = None
self.environment = environment
self.projects = {}
- self.targets = OrderedDict() # type: T.Dict[str, 'Target']
- self.run_target_names = set() # type: T.Set[T.Tuple[str, str]]
- self.global_args = PerMachine({}, {}) # type: PerMachine[T.Dict[str, T.List[str]]]
- self.projects_args = PerMachine({}, {}) # type: PerMachine[T.Dict[str, T.List[str]]]
- self.global_link_args = PerMachine({}, {}) # type: PerMachine[T.Dict[str, T.List[str]]]
- self.projects_link_args = PerMachine({}, {}) # type: PerMachine[T.Dict[str, T.List[str]]]
- self.tests = [] # type: T.List['Test']
- self.benchmarks = [] # type: T.List['Test']
- self.headers = []
- self.man = []
- self.data = []
- self.static_linker = PerMachine(None, None) # type: PerMachine[StaticLinker]
+ self.targets: T.MutableMapping[str, 'Target'] = OrderedDict()
+ self.run_target_names: T.Set[T.Tuple[str, str]] = set()
+ self.global_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {})
+ self.projects_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {})
+ self.global_link_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {})
+ self.projects_link_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {})
+ self.tests: T.List['Test'] = []
+ self.benchmarks: T.List['Test'] = []
+ self.headers: T.List[Headers] = []
+ self.man: T.List[Man] = []
+ self.data: T.List[Data] = []
+ self.static_linker: PerMachine[StaticLinker] = PerMachine(None, None)
self.subprojects = {}
self.subproject_dir = ''
self.install_scripts = []
@@ -153,7 +200,7 @@ class Build:
self.dep_manifest_name = None
self.dep_manifest = {}
self.stdlibs = PerMachine({}, {})
- self.test_setups = {} # type: T.Dict[str, TestSetup]
+ self.test_setups: T.Dict[str, TestSetup] = {}
self.test_setup_default_name = None
self.find_overrides = {}
self.searched_programs = set() # The list of all programs that have been searched for.
@@ -494,7 +541,8 @@ a hard error in the future.'''.format(name))
class BuildTarget(Target):
known_kwargs = known_build_target_kwargs
- def __init__(self, name, subdir, subproject, for_machine: MachineChoice, sources, objects, environment, kwargs):
+ def __init__(self, name: str, subdir: str, subproject: str, for_machine: MachineChoice,
+ sources: T.List[File], objects, environment: environment.Environment, kwargs):
super().__init__(name, subdir, subproject, True, for_machine)
unity_opt = environment.coredata.get_builtin_option('unity')
self.is_unity = unity_opt == 'on' or (unity_opt == 'subprojects' and subproject != '')
@@ -517,7 +565,7 @@ class BuildTarget(Target):
self.outputs = [self.filename]
self.need_install = False
self.pch = {}
- self.extra_args = {}
+ self.extra_args: T.Dict[str, T.List['FileOrString']] = {}
self.generated = []
self.d_features = {}
self.pic = False
@@ -1239,7 +1287,7 @@ You probably should put it in link_with instead.''')
ids = [IncludeDirs(x.get_curdir(), x.get_incdirs(), is_system, x.get_extra_build_dirs()) for x in ids]
self.include_dirs += ids
- def add_compiler_args(self, language, args):
+ def add_compiler_args(self, language: str, args: T.List['FileOrString']) -> None:
args = listify(args)
for a in args:
if not isinstance(a, (str, File)):
@@ -1341,9 +1389,9 @@ You probably should put it in link_with instead.''')
m = 'Could not get a dynamic linker for build target {!r}'
raise AssertionError(m.format(self.name))
- def get_using_rustc(self):
- if len(self.sources) > 0 and self.sources[0].fname.endswith('.rs'):
- return True
+ def get_using_rustc(self) -> bool:
+ """Is this target a rust target."""
+ return self.sources and self.sources[0].fname.endswith('.rs')
def get_using_msvc(self):
'''
@@ -1544,7 +1592,8 @@ class GeneratedList:
class Executable(BuildTarget):
known_kwargs = known_exe_kwargs
- def __init__(self, name, subdir, subproject, for_machine: MachineChoice, sources, objects, environment, kwargs):
+ def __init__(self, name: str, subdir: str, subproject: str, for_machine: MachineChoice,
+ sources: T.List[File], objects, environment: environment.Environment, kwargs):
self.typename = 'executable'
if 'pie' not in kwargs and 'b_pie' in environment.coredata.base_options:
kwargs['pie'] = environment.coredata.base_options['b_pie'].value