From 7ffc678514e6d86ba7072d726f0ccc99a0ccdbc5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 16 Oct 2020 14:02:53 -0700 Subject: build/interpreter: split representation of Headers This was all layering violations before. Now we have Headers in the build module, and a holder in the interpreter. All of the type validation is done in interpreter method for `install_headers`. --- mesonbuild/build.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'mesonbuild/build.py') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5b7a679..ca1d86f 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 pch_kwargs = set(['c_pch', 'cpp_pch']) @@ -122,6 +123,34 @@ 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 Build: """A class that holds the status of one build including all dependencies and so on. @@ -140,7 +169,7 @@ class Build: 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.headers: T.List[Headers] = [] self.man = [] self.data = [] self.static_linker = PerMachine(None, None) # type: PerMachine[StaticLinker] -- cgit v1.1 From 94b9e7b04ea4905a34dac2185ea58e561c3bf594 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 16 Oct 2020 14:14:05 -0700 Subject: build/interpreter: fix layering violations for ManPages Like `install_headers`, `install_man` used the same objects for both the interpreter and the build, this is bad. Let's have two separate objects. --- mesonbuild/build.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'mesonbuild/build.py') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index ca1d86f..0f698b6 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -151,6 +151,24 @@ class Headers: 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. @@ -170,7 +188,7 @@ class Build: self.tests = [] # type: T.List['Test'] self.benchmarks = [] # type: T.List['Test'] self.headers: T.List[Headers] = [] - self.man = [] + self.man: T.List[Man] = [] self.data = [] self.static_linker = PerMachine(None, None) # type: PerMachine[StaticLinker] self.subprojects = {} -- cgit v1.1 From 2f66d9f2eb24059d9979d2d6aa1aab5a74461272 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 16 Dec 2020 12:22:20 -0800 Subject: build: Add annotation for Build.data --- mesonbuild/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mesonbuild/build.py') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0f698b6..5adc25e 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -189,7 +189,7 @@ class Build: self.benchmarks = [] # type: T.List['Test'] self.headers: T.List[Headers] = [] self.man: T.List[Man] = [] - self.data = [] + self.data: T.List[Data] = [] self.static_linker = PerMachine(None, None) # type: PerMachine[StaticLinker] self.subprojects = {} self.subproject_dir = '' -- cgit v1.1 From 47c560f3f7bcdb9615ecf0b8336ed8d2bd5c5337 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 16 Dec 2020 12:26:11 -0800 Subject: build: Use python 3.6 annotation syntax for Build initializer --- mesonbuild/build.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'mesonbuild/build.py') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5adc25e..09b11e0 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -179,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.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(None, None) # type: PerMachine[StaticLinker] + self.static_linker: PerMachine[StaticLinker] = PerMachine(None, None) self.subprojects = {} self.subproject_dir = '' self.install_scripts = [] @@ -200,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. -- cgit v1.1 From 7ddb7a48f514926f3f6027819037d2ab31e7b88b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 21 Oct 2020 16:00:17 -0700 Subject: build/interpreter: Add some type annotations --- mesonbuild/build.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'mesonbuild/build.py') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 09b11e0..091bfc8 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -39,7 +39,7 @@ from .interpreterbase import FeatureNew if T.TYPE_CHECKING: from .interpreter import Test - from .mesonlib import FileMode + from .mesonlib import FileMode, FileOrString pch_kwargs = set(['c_pch', 'cpp_pch']) @@ -541,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 != '') @@ -564,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 @@ -1286,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)): @@ -1388,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): ''' @@ -1591,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 -- cgit v1.1