aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/cmake
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-08-10 21:19:29 -0400
committerEli Schwartz <eschwartz@archlinux.org>2023-08-11 13:41:03 -0400
commit90ce0841441506e3f409ab59ded1df8f2e6e7363 (patch)
tree3478769eef2620e9d7b5a41b73dd94c75b003465 /mesonbuild/cmake
parentde1cc0b02bcb1bab6977f0ab8bb3fef0cd0646dd (diff)
downloadmeson-90ce0841441506e3f409ab59ded1df8f2e6e7363.zip
meson-90ce0841441506e3f409ab59ded1df8f2e6e7363.tar.gz
meson-90ce0841441506e3f409ab59ded1df8f2e6e7363.tar.bz2
treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann This has no actual effect on the codebase as type checkers (still) support both and negligible effect on runtime performance since __future__ annotations ameliorates that. Technically, the bytecode would be bigger for non function-local annotations, of which we have many either way. So if it doesn't really matter, why do a large-scale refactor? Simple: because people keep wanting to, but it's getting nickle-and-dimed. If we're going to do this we might as well do it consistently in one shot, using tooling that guarantees repeatability and correctness. Repeat with: ``` com2ann mesonbuild/ ```
Diffstat (limited to 'mesonbuild/cmake')
-rw-r--r--mesonbuild/cmake/common.py42
-rw-r--r--mesonbuild/cmake/executor.py10
-rw-r--r--mesonbuild/cmake/fileapi.py4
-rw-r--r--mesonbuild/cmake/generator.py4
-rw-r--r--mesonbuild/cmake/toolchain.py6
-rw-r--r--mesonbuild/cmake/traceparser.py36
6 files changed, 51 insertions, 51 deletions
diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py
index 002cda7..415937e 100644
--- a/mesonbuild/cmake/common.py
+++ b/mesonbuild/cmake/common.py
@@ -123,7 +123,7 @@ def cmake_get_generator_args(env: 'Environment') -> T.List[str]:
return ['-G', backend_generator_map[backend_name]]
def cmake_defines_to_args(raw: T.List[T.Dict[str, TYPE_var]], permissive: bool = False) -> T.List[str]:
- res = [] # type: T.List[str]
+ res: T.List[str] = []
for i in raw:
for key, val in i.items():
@@ -144,7 +144,7 @@ def cmake_defines_to_args(raw: T.List[T.Dict[str, TYPE_var]], permissive: bool =
# TODO: this function will become obsolete once the `cmake_args` kwarg is dropped
def check_cmake_args(args: T.List[str]) -> T.List[str]:
- res = [] # type: T.List[str]
+ res: T.List[str] = []
dis = ['-D' + x for x in blacklist_cmake_defs]
assert dis # Ensure that dis is not empty.
for i in args:
@@ -166,14 +166,14 @@ class CMakeInclude:
class CMakeFileGroup:
def __init__(self, data: T.Dict[str, T.Any]) -> None:
- self.defines = data.get('defines', '') # type: str
+ self.defines: str = data.get('defines', '')
self.flags = _flags_to_list(data.get('compileFlags', ''))
- self.is_generated = data.get('isGenerated', False) # type: bool
- self.language = data.get('language', 'C') # type: str
+ self.is_generated: bool = data.get('isGenerated', False)
+ self.language: str = data.get('language', 'C')
self.sources = [Path(x) for x in data.get('sources', [])]
# Fix the include directories
- self.includes = [] # type: T.List[CMakeInclude]
+ self.includes: T.List[CMakeInclude] = []
for i in data.get('includePath', []):
if isinstance(i, dict) and 'path' in i:
isSystem = i.get('isSystem', False)
@@ -199,18 +199,18 @@ class CMakeTarget:
self.artifacts = [Path(x) for x in data.get('artifacts', [])]
self.src_dir = Path(data.get('sourceDirectory', ''))
self.build_dir = Path(data.get('buildDirectory', ''))
- self.name = data.get('name', '') # type: str
- self.full_name = data.get('fullName', '') # type: str
- self.install = data.get('hasInstallRule', False) # type: bool
+ self.name: str = data.get('name', '')
+ self.full_name: str = data.get('fullName', '')
+ self.install: bool = data.get('hasInstallRule', False)
self.install_paths = [Path(x) for x in set(data.get('installPaths', []))]
- self.link_lang = data.get('linkerLanguage', '') # type: str
+ self.link_lang: str = data.get('linkerLanguage', '')
self.link_libraries = _flags_to_list(data.get('linkLibraries', ''))
self.link_flags = _flags_to_list(data.get('linkFlags', ''))
self.link_lang_flags = _flags_to_list(data.get('linkLanguageFlags', ''))
# self.link_path = Path(data.get('linkPath', ''))
- self.type = data.get('type', 'EXECUTABLE') # type: str
+ self.type: str = data.get('type', 'EXECUTABLE')
# self.is_generator_provided = data.get('isGeneratorProvided', False) # type: bool
- self.files = [] # type: T.List[CMakeFileGroup]
+ self.files: T.List[CMakeFileGroup] = []
for i in data.get('fileGroups', []):
self.files += [CMakeFileGroup(i)]
@@ -239,8 +239,8 @@ class CMakeProject:
def __init__(self, data: T.Dict[str, T.Any]) -> None:
self.src_dir = Path(data.get('sourceDirectory', ''))
self.build_dir = Path(data.get('buildDirectory', ''))
- self.name = data.get('name', '') # type: str
- self.targets = [] # type: T.List[CMakeTarget]
+ self.name: str = data.get('name', '')
+ self.targets: T.List[CMakeTarget] = []
for i in data.get('targets', []):
self.targets += [CMakeTarget(i)]
@@ -256,8 +256,8 @@ class CMakeProject:
class CMakeConfiguration:
def __init__(self, data: T.Dict[str, T.Any]) -> None:
- self.name = data.get('name', '') # type: str
- self.projects = [] # type: T.List[CMakeProject]
+ self.name: str = data.get('name', '')
+ self.projects: T.List[CMakeProject] = []
for i in data.get('projects', []):
self.projects += [CMakeProject(i)]
@@ -270,9 +270,9 @@ class CMakeConfiguration:
class SingleTargetOptions:
def __init__(self) -> None:
- self.opts = {} # type: T.Dict[str, str]
- self.lang_args = {} # type: T.Dict[str, T.List[str]]
- self.link_args = [] # type: T.List[str]
+ self.opts: T.Dict[str, str] = {}
+ self.lang_args: T.Dict[str, T.List[str]] = {}
+ self.link_args: T.List[str] = []
self.install = 'preserve'
def set_opt(self, opt: str, val: str) -> None:
@@ -290,7 +290,7 @@ class SingleTargetOptions:
self.install = 'true' if install else 'false'
def get_override_options(self, initial: T.List[str]) -> T.List[str]:
- res = [] # type: T.List[str]
+ res: T.List[str] = []
for i in initial:
opt = i[:i.find('=')]
if opt not in self.opts:
@@ -312,7 +312,7 @@ class SingleTargetOptions:
class TargetOptions:
def __init__(self) -> None:
self.global_options = SingleTargetOptions()
- self.target_options = {} # type: T.Dict[str, SingleTargetOptions]
+ self.target_options: T.Dict[str, SingleTargetOptions] = {}
def __getitem__(self, tgt: str) -> SingleTargetOptions:
if tgt not in self.target_options:
diff --git a/mesonbuild/cmake/executor.py b/mesonbuild/cmake/executor.py
index c22c0ca..7958baf 100644
--- a/mesonbuild/cmake/executor.py
+++ b/mesonbuild/cmake/executor.py
@@ -39,9 +39,9 @@ if T.TYPE_CHECKING:
class CMakeExecutor:
# The class's copy of the CMake path. Avoids having to search for it
# multiple times in the same Meson invocation.
- class_cmakebin = PerMachine(None, None) # type: PerMachine[T.Optional[ExternalProgram]]
- class_cmakevers = PerMachine(None, None) # type: PerMachine[T.Optional[str]]
- class_cmake_cache = {} # type: T.Dict[T.Any, TYPE_result]
+ class_cmakebin: PerMachine[T.Optional[ExternalProgram]] = PerMachine(None, None)
+ class_cmakevers: PerMachine[T.Optional[str]] = PerMachine(None, None)
+ class_cmake_cache: T.Dict[T.Any, TYPE_result] = {}
def __init__(self, environment: 'Environment', version: str, for_machine: MachineChoice, silent: bool = False):
self.min_version = version
@@ -50,8 +50,8 @@ class CMakeExecutor:
self.cmakebin, self.cmakevers = self.find_cmake_binary(self.environment, silent=silent)
self.always_capture_stderr = True
self.print_cmout = False
- self.prefix_paths = [] # type: T.List[str]
- self.extra_cmake_args = [] # type: T.List[str]
+ self.prefix_paths: T.List[str] = []
+ self.extra_cmake_args: T.List[str] = []
if self.cmakebin is None:
return
diff --git a/mesonbuild/cmake/fileapi.py b/mesonbuild/cmake/fileapi.py
index 9605f92..baf499f 100644
--- a/mesonbuild/cmake/fileapi.py
+++ b/mesonbuild/cmake/fileapi.py
@@ -28,8 +28,8 @@ class CMakeFileAPI:
self.api_base_dir = self.build_dir / '.cmake' / 'api' / 'v1'
self.request_dir = self.api_base_dir / 'query' / 'client-meson'
self.reply_dir = self.api_base_dir / 'reply'
- self.cmake_sources = [] # type: T.List[CMakeBuildFile]
- self.cmake_configurations = [] # type: T.List[CMakeConfiguration]
+ self.cmake_sources: T.List[CMakeBuildFile] = []
+ self.cmake_configurations: T.List[CMakeConfiguration] = []
self.kind_resolver_map = {
'codemodel': self._parse_codemodel,
'cmakeFiles': self._parse_cmakeFiles,
diff --git a/mesonbuild/cmake/generator.py b/mesonbuild/cmake/generator.py
index f47625c..750e4c2 100644
--- a/mesonbuild/cmake/generator.py
+++ b/mesonbuild/cmake/generator.py
@@ -98,7 +98,7 @@ def parse_generator_expressions(
return ';'.join([x for x in tgt.properties['IMPORTED_LOCATION'] if x])
return ''
- supported = {
+ supported: T.Dict[str, T.Callable[[str], str]] = {
# Boolean functions
'BOOL': lambda x: '0' if x.upper() in {'', '0', 'FALSE', 'OFF', 'N', 'NO', 'IGNORE', 'NOTFOUND'} or x.endswith('-NOTFOUND') else '1',
'AND': lambda x: '1' if all(y == '1' for y in x.split(',')) else '0',
@@ -140,7 +140,7 @@ def parse_generator_expressions(
'TARGET_NAME_IF_EXISTS': lambda x: x if x in trace.targets else '',
'TARGET_PROPERTY': target_property,
'TARGET_FILE': target_file,
- } # type: T.Dict[str, T.Callable[[str], str]]
+ }
# Recursively evaluate generator expressions
def eval_generator_expressions() -> str:
diff --git a/mesonbuild/cmake/toolchain.py b/mesonbuild/cmake/toolchain.py
index 477629e..be5bd66 100644
--- a/mesonbuild/cmake/toolchain.py
+++ b/mesonbuild/cmake/toolchain.py
@@ -144,7 +144,7 @@ class CMakeToolchain:
return res
def get_defaults(self) -> T.Dict[str, T.List[str]]:
- defaults = {} # type: T.Dict[str, T.List[str]]
+ defaults: T.Dict[str, T.List[str]] = {}
# Do nothing if the user does not want automatic defaults
if not self.properties.get_cmake_defaults():
@@ -153,13 +153,13 @@ class CMakeToolchain:
# Best effort to map the meson system name to CMAKE_SYSTEM_NAME, which
# is not trivial since CMake lacks a list of all supported
# CMAKE_SYSTEM_NAME values.
- SYSTEM_MAP = {
+ SYSTEM_MAP: T.Dict[str, str] = {
'android': 'Android',
'linux': 'Linux',
'windows': 'Windows',
'freebsd': 'FreeBSD',
'darwin': 'Darwin',
- } # type: T.Dict[str, str]
+ }
# Only set these in a cross build. Otherwise CMake will trip up in native
# builds and thing they are cross (which causes TRY_RUN() to break)
diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py
index 92ff780..dd0dfb5 100644
--- a/mesonbuild/cmake/traceparser.py
+++ b/mesonbuild/cmake/traceparser.py
@@ -67,9 +67,9 @@ class CMakeTarget:
self.properties = properties
self.imported = imported
self.tline = tline
- self.depends = [] # type: T.List[str]
- self.current_bin_dir = None # type: T.Optional[Path]
- self.current_src_dir = None # type: T.Optional[Path]
+ self.depends: T.List[str] = []
+ self.current_bin_dir: T.Optional[Path] = None
+ self.current_src_dir: T.Optional[Path] = None
def __repr__(self) -> str:
s = 'CMake TARGET:\n -- name: {}\n -- type: {}\n -- imported: {}\n -- properties: {{\n{} }}\n -- tline: {}'
@@ -89,10 +89,10 @@ class CMakeTarget:
class CMakeGeneratorTarget(CMakeTarget):
def __init__(self, name: str) -> None:
super().__init__(name, 'CUSTOM', {})
- self.outputs = [] # type: T.List[Path]
- self._outputs_str = [] # type: T.List[str]
- self.command = [] # type: T.List[T.List[str]]
- self.working_dir = None # type: T.Optional[Path]
+ self.outputs: T.List[Path] = []
+ self._outputs_str: T.List[str] = []
+ self.command: T.List[T.List[str]] = []
+ self.working_dir: T.Optional[Path] = None
class CMakeTraceParser:
def __init__(self, cmake_version: str, build_dir: Path, env: 'Environment', permissive: bool = True) -> None:
@@ -101,10 +101,10 @@ class CMakeTraceParser:
self.targets: T.Dict[str, CMakeTarget] = {}
self.cache: T.Dict[str, CMakeCacheEntry] = {}
- self.explicit_headers = set() # type: T.Set[Path]
+ self.explicit_headers: T.Set[Path] = set()
# T.List of targes that were added with add_custom_command to generate files
- self.custom_targets = [] # type: T.List[CMakeGeneratorTarget]
+ self.custom_targets: T.List[CMakeGeneratorTarget] = []
self.env = env
self.permissive = permissive
@@ -118,11 +118,11 @@ class CMakeTraceParser:
# State for delayed command execution. Delayed command execution is realised
# with a custom CMake file that overrides some functions and adds some
# introspection information to the trace.
- self.delayed_commands = [] # type: T.List[str]
- self.stored_commands = [] # type: T.List[CMakeTraceLine]
+ self.delayed_commands: T.List[str] = []
+ self.stored_commands: T.List[CMakeTraceLine] = []
# All supported functions
- self.functions = {
+ self.functions: T.Dict[str, T.Callable[[CMakeTraceLine], None]] = {
'set': self._cmake_set,
'unset': self._cmake_unset,
'add_executable': self._cmake_add_executable,
@@ -145,7 +145,7 @@ class CMakeTraceParser:
'meson_ps_execute_delayed_calls': self._meson_ps_execute_delayed_calls,
'meson_ps_reload_vars': self._meson_ps_reload_vars,
'meson_ps_disabled_function': self._meson_ps_disabled_function,
- } # type: T.Dict[str, T.Callable[[CMakeTraceLine], None]]
+ }
if version_compare(self.cmake_version, '<3.17.0'):
mlog.deprecation(textwrap.dedent(f'''\
@@ -591,10 +591,10 @@ class CMakeTraceParser:
# With the JSON output format, introduced in CMake 3.17, spaces are
# handled properly and we don't have to do either options
- arglist = [] # type: T.List[T.Tuple[str, T.List[str]]]
+ arglist: T.List[T.Tuple[str, T.List[str]]] = []
if self.trace_format == 'human':
name = args.pop(0)
- values = [] # type: T.List[str]
+ values: T.List[str] = []
prop_regex = re.compile(r'^[A-Z_]+$')
for a in args:
if prop_regex.match(a):
@@ -768,7 +768,7 @@ class CMakeTraceParser:
def _flatten_args(self, args: T.List[str]) -> T.List[str]:
# Split lists in arguments
- res = [] # type: T.List[str]
+ res: T.List[str] = []
for i in args:
res += i.split(';')
return res
@@ -783,8 +783,8 @@ class CMakeTraceParser:
reg_start = re.compile(r'^([A-Za-z]:)?/(.*/)*[^./]+$')
reg_end = re.compile(r'^.*\.[a-zA-Z]+$')
- fixed_list = [] # type: T.List[str]
- curr_str = None # type: T.Optional[str]
+ fixed_list: T.List[str] = []
+ curr_str: T.Optional[str] = None
path_found = False
for i in broken_list: