@@ -131,7 +131,7 @@ class OutputTargetMap:
131
131
rm_so_version = re .compile (r'(\.[0-9]+)+$' )
132
132
133
133
def __init__ (self , build_dir : Path ):
134
- self .tgt_map = {} # type : T.Dict[str, T.Union['ConverterTarget', 'ConverterCustomTarget']]
134
+ self .tgt_map : T .Dict [str , T .Union ['ConverterTarget' , 'ConverterCustomTarget' ]] = {}
135
135
self .build_dir = build_dir
136
136
137
137
def add (self , tgt : T .Union ['ConverterTarget' , 'ConverterCustomTarget' ]) -> None :
@@ -220,38 +220,38 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
220
220
self .full_name = target .full_name
221
221
self .type = target .type
222
222
self .install = target .install
223
- self .install_dir = None # type : T.Optional[Path]
223
+ self .install_dir : T .Optional [Path ] = None
224
224
self .link_libraries = target .link_libraries
225
225
self .link_flags = target .link_flags + target .link_lang_flags
226
- self .depends_raw = [] # type : T.List[str]
227
- self .depends = [] # type : T.List[T.Union[ConverterTarget, ConverterCustomTarget]]
226
+ self .depends_raw : T .List [str ] = [ ]
227
+ self .depends : T .List [T .Union [ConverterTarget , ConverterCustomTarget ]] = [ ]
228
228
229
229
if target .install_paths :
230
230
self .install_dir = target .install_paths [0 ]
231
231
232
- self .languages = set () # type : T.Set[str]
233
- self .sources = [] # type : T.List[Path]
234
- self .generated = [] # type : T.List[Path]
235
- self .generated_ctgt = [] # type : T.List[CustomTargetReference]
236
- self .includes = [] # type : T.List[Path]
237
- self .sys_includes = [] # type : T.List[Path]
238
- self .link_with = [] # type : T.List[T.Union[ConverterTarget, ConverterCustomTarget]]
239
- self .object_libs = [] # type : T.List[ConverterTarget]
240
- self .compile_opts = {} # type : T.Dict[str, T.List[str]]
241
- self .public_compile_opts = [] # type : T.List[str]
232
+ self .languages : T .Set [str ] = set ()
233
+ self .sources : T .List [Path ] = [ ]
234
+ self .generated : T .List [Path ] = [ ]
235
+ self .generated_ctgt : T .List [CustomTargetReference ] = [ ]
236
+ self .includes : T .List [Path ] = [ ]
237
+ self .sys_includes : T .List [Path ] = [ ]
238
+ self .link_with : T .List [T .Union [ConverterTarget , ConverterCustomTarget ]] = [ ]
239
+ self .object_libs : T .List [ConverterTarget ] = [ ]
240
+ self .compile_opts : T .Dict [str , T .List [str ]] = {}
241
+ self .public_compile_opts : T .List [str ] = [ ]
242
242
self .pie = False
243
243
244
244
# Project default override options (c_std, cpp_std, etc.)
245
- self .override_options = [] # type : T.List[str]
245
+ self .override_options : T .List [str ] = [ ]
246
246
247
247
# Convert the target name to a valid meson target name
248
248
self .name = _sanitize_cmake_name (self .name )
249
249
250
- self .generated_raw = [] # type : T.List[Path]
250
+ self .generated_raw : T .List [Path ] = [ ]
251
251
252
252
for i in target .files :
253
- languages = set () # type : T.Set[str]
254
- src_suffixes = set () # type : T.Set[str]
253
+ languages : T .Set [str ] = set ()
254
+ src_suffixes : T .Set [str ] = set ()
255
255
256
256
# Insert suffixes
257
257
for j in i .sources :
@@ -517,7 +517,7 @@ def _append_objlib_sources(self, tgt: 'ConverterTarget') -> None:
517
517
518
518
@lru_cache (maxsize = None )
519
519
def _all_source_suffixes (self ) -> 'ImmutableListProtocol[str]' :
520
- suffixes = [] # type : T.List[str]
520
+ suffixes : T .List [str ] = [ ]
521
521
for exts in lang_suffixes .values ():
522
522
suffixes .extend (exts )
523
523
return suffixes
@@ -612,12 +612,12 @@ def __init__(self, target: CMakeGeneratorTarget, env: 'Environment', for_machine
612
612
self .cmake_name = str (self .name )
613
613
self .original_outputs = list (target .outputs )
614
614
self .outputs = [x .name for x in self .original_outputs ]
615
- self .conflict_map = {} # type : T.Dict[str, str]
616
- self .command = [] # type : T.List[T.List[T.Union[str, ConverterTarget]]]
615
+ self .conflict_map : T .Dict [str , str ] = {}
616
+ self .command : T .List [T .List [T .Union [str , ConverterTarget ]]] = [ ]
617
617
self .working_dir = target .working_dir
618
618
self .depends_raw = target .depends
619
- self .inputs = [] # type : T.List[T.Union[str, CustomTargetReference]]
620
- self .depends = [] # type : T.List[T.Union[ConverterTarget, ConverterCustomTarget]]
619
+ self .inputs : T .List [T .Union [str , CustomTargetReference ]] = [ ]
620
+ self .depends : T .List [T .Union [ConverterTarget , ConverterCustomTarget ]] = [ ]
621
621
self .current_bin_dir = target .current_bin_dir
622
622
self .current_src_dir = target .current_src_dir
623
623
self .env = env
@@ -652,7 +652,7 @@ def ensure_absolute(x: Path) -> Path:
652
652
# Ensure that there is no duplicate output in the project so
653
653
# that meson can handle cases where the same filename is
654
654
# generated in multiple directories
655
- temp_outputs = [] # type : T.List[str]
655
+ temp_outputs : T .List [str ] = [ ]
656
656
for i in self .outputs :
657
657
if i in all_outputs :
658
658
old = str (i )
@@ -664,11 +664,11 @@ def ensure_absolute(x: Path) -> Path:
664
664
self .outputs = temp_outputs
665
665
666
666
# Check if the command is a build target
667
- commands = [] # type : T.List[T.List[T.Union[str, ConverterTarget]]]
667
+ commands : T .List [T .List [T .Union [str , ConverterTarget ]]] = [ ]
668
668
for curr_cmd in self ._raw_target .command :
669
669
assert isinstance (curr_cmd , list )
670
670
assert curr_cmd [0 ] != '' , "An empty string is not a valid executable"
671
- cmd = [] # type : T.List[T.Union[str, ConverterTarget]]
671
+ cmd : T .List [T .Union [str , ConverterTarget ]] = [ ]
672
672
673
673
for j in curr_cmd :
674
674
if not j :
@@ -775,25 +775,25 @@ def __init__(self, build: 'Build', subdir: Path, src_dir: Path, install_prefix:
775
775
self .env = env
776
776
self .for_machine = MachineChoice .HOST # TODO make parameter
777
777
self .backend_name = backend .name
778
- self .linkers = set () # type : T.Set[str]
778
+ self .linkers : T .Set [str ] = set ()
779
779
self .fileapi = CMakeFileAPI (self .build_dir )
780
780
781
781
# Raw CMake results
782
- self .bs_files = [] # type : T.List[Path]
783
- self .codemodel_configs = None # type : T.Optional[T.List[CMakeConfiguration]]
784
- self .cmake_stderr = None # type : T.Optional[str]
782
+ self .bs_files : T .List [Path ] = [ ]
783
+ self .codemodel_configs : T .Optional [T .List [CMakeConfiguration ]] = None
784
+ self .cmake_stderr : T .Optional [str ] = None
785
785
786
786
# Analysed data
787
787
self .project_name = ''
788
- self .languages = [] # type : T.List[str]
789
- self .targets = [] # type : T.List[ConverterTarget]
790
- self .custom_targets = [] # type : T.List[ConverterCustomTarget]
788
+ self .languages : T .List [str ] = [ ]
789
+ self .targets : T .List [ConverterTarget ] = [ ]
790
+ self .custom_targets : T .List [ConverterCustomTarget ] = [ ]
791
791
self .trace : CMakeTraceParser
792
792
self .output_target_map = OutputTargetMap (self .build_dir )
793
793
794
794
# Generated meson data
795
- self .generated_targets = {} # type : T.Dict[str, T.Dict[str, T.Optional[str]]]
796
- self .internal_name_map = {} # type : T.Dict[str, str]
795
+ self .generated_targets : T .Dict [str , T .Dict [str , T .Optional [str ]]] = {}
796
+ self .internal_name_map : T .Dict [str , str ] = {}
797
797
798
798
# Do some special handling for object libraries for certain configurations
799
799
self ._object_lib_workaround = False
@@ -890,7 +890,7 @@ def analyse(self) -> None:
890
890
self .trace .parse (self .cmake_stderr )
891
891
892
892
# Find all targets
893
- added_target_names = [] # type : T.List[str]
893
+ added_target_names : T .List [str ] = [ ]
894
894
for i_0 in self .codemodel_configs :
895
895
for j_0 in i_0 .projects :
896
896
if not self .project_name :
@@ -927,7 +927,7 @@ def analyse(self) -> None:
927
927
928
928
# First pass: Basic target cleanup
929
929
object_libs = []
930
- custom_target_outputs = [] # type : T.List[str]
930
+ custom_target_outputs : T .List [str ] = [ ]
931
931
for ctgt in self .custom_targets :
932
932
ctgt .postprocess (self .output_target_map , self .src_dir , custom_target_outputs , self .trace )
933
933
for tgt in self .targets :
@@ -1026,9 +1026,9 @@ def assign(var_name: str, value: BaseNode) -> AssignmentNode:
1026
1026
# Add the run script for custom commands
1027
1027
1028
1028
# Add the targets
1029
- processing = [] # type : T.List[str]
1030
- processed = {} # type : T.Dict[str, T.Dict[str, T.Optional[str]]]
1031
- name_map = {} # type : T.Dict[str, str]
1029
+ processing : T .List [str ] = [ ]
1030
+ processed : T .Dict [str , T .Dict [str , T .Optional [str ]]] = {}
1031
+ name_map : T .Dict [str , str ] = {}
1032
1032
1033
1033
def extract_tgt (tgt : T .Union [ConverterTarget , ConverterCustomTarget , CustomTargetReference ]) -> IdNode :
1034
1034
tgt_name = None
@@ -1056,13 +1056,13 @@ def process_target(tgt: ConverterTarget) -> None:
1056
1056
detect_cycle (tgt )
1057
1057
1058
1058
# First handle inter target dependencies
1059
- link_with = [] # type : T.List[IdNode]
1060
- objec_libs = [] # type : T.List[IdNode]
1061
- sources = [] # type : T.List[Path]
1062
- generated = [] # type : T.List[T.Union[IdNode, IndexNode]]
1063
- generated_filenames = [] # type : T.List[str]
1064
- custom_targets = [] # type : T.List[ConverterCustomTarget]
1065
- dependencies = [] # type : T.List[IdNode]
1059
+ link_with : T .List [IdNode ] = [ ]
1060
+ objec_libs : T .List [IdNode ] = [ ]
1061
+ sources : T .List [Path ] = [ ]
1062
+ generated : T .List [T .Union [IdNode , IndexNode ]] = [ ]
1063
+ generated_filenames : T .List [str ] = [ ]
1064
+ custom_targets : T .List [ConverterCustomTarget ] = [ ]
1065
+ dependencies : T .List [IdNode ] = [ ]
1066
1066
for i in tgt .link_with :
1067
1067
assert isinstance (i , ConverterTarget )
1068
1068
if i .name not in processed :
@@ -1123,15 +1123,15 @@ def process_target(tgt: ConverterTarget) -> None:
1123
1123
install_tgt = options .get_install (tgt .cmake_name , tgt .install )
1124
1124
1125
1125
# Generate target kwargs
1126
- tgt_kwargs = {
1126
+ tgt_kwargs : TYPE_mixed_kwargs = {
1127
1127
'build_by_default' : install_tgt ,
1128
1128
'link_args' : options .get_link_args (tgt .cmake_name , tgt .link_flags + tgt .link_libraries ),
1129
1129
'link_with' : link_with ,
1130
1130
'include_directories' : id_node (inc_var ),
1131
1131
'install' : install_tgt ,
1132
1132
'override_options' : options .get_override_options (tgt .cmake_name , tgt .override_options ),
1133
1133
'objects' : [method (x , 'extract_all_objects' ) for x in objec_libs ],
1134
- } # type: TYPE_mixed_kwargs
1134
+ }
1135
1135
1136
1136
# Only set if installed and only override if it is set
1137
1137
if install_tgt and tgt .install_dir :
@@ -1148,12 +1148,12 @@ def process_target(tgt: ConverterTarget) -> None:
1148
1148
tgt_kwargs ['pic' ] = tgt .pie
1149
1149
1150
1150
# declare_dependency kwargs
1151
- dep_kwargs = {
1151
+ dep_kwargs : TYPE_mixed_kwargs = {
1152
1152
'link_args' : tgt .link_flags + tgt .link_libraries ,
1153
1153
'link_with' : id_node (tgt_var ),
1154
1154
'compile_args' : tgt .public_compile_opts ,
1155
1155
'include_directories' : id_node (inc_var ),
1156
- } # type: TYPE_mixed_kwargs
1156
+ }
1157
1157
1158
1158
if dependencies :
1159
1159
generated += dependencies
@@ -1214,7 +1214,7 @@ def resolve_source(x: T.Union[str, ConverterTarget, ConverterCustomTarget, Custo
1214
1214
return x
1215
1215
1216
1216
# Generate the command list
1217
- command = [] # type : T.List[T.Union[str, IdNode, IndexNode]]
1217
+ command : T .List [T .Union [str , IdNode , IndexNode ]] = [ ]
1218
1218
command += mesonlib .get_meson_command ()
1219
1219
command += ['--internal' , 'cmake_run_ctgt' ]
1220
1220
command += ['-o' , '@OUTPUT@' ]
@@ -1226,12 +1226,12 @@ def resolve_source(x: T.Union[str, ConverterTarget, ConverterCustomTarget, Custo
1226
1226
for cmd in tgt .command :
1227
1227
command += [resolve_source (x ) for x in cmd ] + [';;;' ]
1228
1228
1229
- tgt_kwargs = {
1229
+ tgt_kwargs : TYPE_mixed_kwargs = {
1230
1230
'input' : [resolve_source (x ) for x in tgt .inputs ],
1231
1231
'output' : tgt .outputs ,
1232
1232
'command' : command ,
1233
1233
'depends' : [resolve_source (x ) for x in tgt .depends ],
1234
- } # type: TYPE_mixed_kwargs
1234
+ }
1235
1235
1236
1236
root_cb .lines += [assign (tgt_var , function ('custom_target' , [tgt .name ], tgt_kwargs ))]
1237
1237
processed [tgt .name ] = {'inc' : None , 'src' : None , 'dep' : None , 'tgt' : tgt_var , 'func' : 'custom_target' }
0 commit comments