61
61
LibTypes = T .Union ['SharedLibrary' , 'StaticLibrary' , 'CustomTarget' , 'CustomTargetIndex' ]
62
62
BuildTargetTypes = T .Union ['BuildTarget' , 'CustomTarget' , 'CustomTargetIndex' ]
63
63
64
- pch_kwargs = {'c_pch' , 'cpp_pch' }
65
-
66
- lang_arg_kwargs = {f'{ lang } _args' for lang in all_languages }
67
- lang_arg_kwargs |= {
68
- 'd_import_dirs' ,
69
- 'd_unittest' ,
70
- 'd_module_versions' ,
71
- 'd_debug' ,
72
- }
73
-
74
- vala_kwargs = {'vala_header' , 'vala_gir' , 'vala_vapi' }
75
- rust_kwargs = {'rust_crate_type' }
76
- cs_kwargs = {'resources' , 'cs_args' }
77
-
78
- buildtarget_kwargs = {
79
- 'build_by_default' ,
80
- 'build_rpath' ,
81
- 'dependencies' ,
82
- 'extra_files' ,
83
- 'gui_app' ,
84
- 'link_with' ,
85
- 'link_whole' ,
86
- 'link_args' ,
87
- 'link_depends' ,
88
- 'implicit_include_directories' ,
89
- 'include_directories' ,
90
- 'install' ,
91
- 'install_rpath' ,
92
- 'install_dir' ,
93
- 'install_mode' ,
94
- 'install_tag' ,
95
- 'name_prefix' ,
96
- 'name_suffix' ,
97
- 'native' ,
98
- 'objects' ,
99
- 'override_options' ,
100
- 'sources' ,
101
- 'gnu_symbol_visibility' ,
102
- 'link_language' ,
103
- 'win_subsystem' ,
104
- }
105
-
106
- known_build_target_kwargs = (
107
- buildtarget_kwargs |
108
- lang_arg_kwargs |
109
- pch_kwargs |
110
- vala_kwargs |
111
- rust_kwargs |
112
- cs_kwargs )
113
-
114
- known_exe_kwargs = known_build_target_kwargs | {'implib' , 'export_dynamic' , 'pie' }
115
- known_shlib_kwargs = known_build_target_kwargs | {'version' , 'soversion' , 'vs_module_defs' , 'darwin_versions' }
116
- known_shmod_kwargs = known_build_target_kwargs | {'vs_module_defs' }
117
- known_stlib_kwargs = known_build_target_kwargs | {'pic' , 'prelink' }
118
- known_jar_kwargs = known_exe_kwargs | {'main_class' , 'java_resources' }
119
64
120
65
def _process_install_tag (install_tag : T .Optional [T .List [T .Optional [str ]]],
121
66
num_outputs : int ) -> T .List [T .Optional [str ]]:
@@ -679,7 +624,6 @@ def should_install(self) -> bool:
679
624
return False
680
625
681
626
class BuildTarget (Target ):
682
- known_kwargs = known_build_target_kwargs
683
627
684
628
install_dir : T .List [T .Union [str , Literal [False ]]]
685
629
@@ -720,7 +664,6 @@ def __init__(self, name: str, subdir: str, subproject: SubProject, for_machine:
720
664
# 2. Compiled objects created by and extracted from another target
721
665
self .process_objectlist (objects )
722
666
self .process_kwargs (kwargs )
723
- self .check_unknown_kwargs (kwargs )
724
667
if not any ([self .sources , self .generated , self .objects , self .link_whole_targets , self .structured_sources ]):
725
668
mlog .warning (f'Build target { name } has no sources. '
726
669
'This was never supposed to be allowed but did because of a bug, '
@@ -756,19 +699,6 @@ def validate_install(self):
756
699
else :
757
700
mlog .warning ('Installing target build for the build machine. This will fail in a cross build.' )
758
701
759
- def check_unknown_kwargs (self , kwargs ):
760
- # Override this method in derived classes that have more
761
- # keywords.
762
- self .check_unknown_kwargs_int (kwargs , self .known_kwargs )
763
-
764
- def check_unknown_kwargs_int (self , kwargs , known_kwargs ):
765
- unknowns = []
766
- for k in kwargs :
767
- if k not in known_kwargs :
768
- unknowns .append (k )
769
- if len (unknowns ) > 0 :
770
- mlog .warning ('Unknown keyword argument(s) in target {}: {}.' .format (self .name , ', ' .join (unknowns )))
771
-
772
702
def process_objectlist (self , objects ):
773
703
assert isinstance (objects , list )
774
704
for s in objects :
@@ -1074,8 +1004,8 @@ def process_kwargs(self, kwargs):
1074
1004
self .add_pch ('cpp' , extract_as_list (kwargs , 'cpp_pch' ))
1075
1005
1076
1006
if not isinstance (self , Executable ) or 'export_dynamic' in kwargs :
1077
- self .vala_header = kwargs .get ('vala_header' , self .name + '.h' )
1078
- self .vala_vapi = kwargs .get ('vala_vapi' , self .name + '.vapi' )
1007
+ self .vala_header = kwargs .get ('vala_header' ) or self .name + '.h'
1008
+ self .vala_vapi = kwargs .get ('vala_vapi' ) or self .name + '.vapi'
1079
1009
self .vala_gir = kwargs .get ('vala_gir' , None )
1080
1010
1081
1011
dfeatures = defaultdict (list )
@@ -1118,10 +1048,10 @@ def process_kwargs(self, kwargs):
1118
1048
self .add_deps (deplist )
1119
1049
# If an item in this list is False, the output corresponding to
1120
1050
# the list index of that item will not be installed
1121
- self .install_dir = typeslistify (kwargs .get ('install_dir' , []) ,
1051
+ self .install_dir = typeslistify (kwargs .get ('install_dir' ) or [] ,
1122
1052
(str , bool ))
1123
1053
self .install_mode = kwargs .get ('install_mode' , None )
1124
- self .install_tag = stringlistify ( kwargs .get ('install_tag' , [None ]))
1054
+ self .install_tag = [ kwargs [ 'install_tag' ]] if kwargs .get ('install_tag' ) else [None ]
1125
1055
main_class = kwargs .get ('main_class' , '' )
1126
1056
if not isinstance (main_class , str ):
1127
1057
raise InvalidArguments ('Main class must be a string' )
@@ -1130,17 +1060,13 @@ def process_kwargs(self, kwargs):
1130
1060
# This kwarg is deprecated. The value of "none" means that the kwarg
1131
1061
# was not specified and win_subsystem should be used instead.
1132
1062
self .gui_app = None
1133
- if 'gui_app' in kwargs :
1134
- if 'win_subsystem' in kwargs :
1063
+ if kwargs . get ( 'gui_app' ) is not None :
1064
+ if kwargs . get ( 'win_subsystem' ) is not None :
1135
1065
raise InvalidArguments ('Can specify only gui_app or win_subsystem for a target, not both.' )
1136
1066
self .gui_app = kwargs ['gui_app' ]
1137
1067
if not isinstance (self .gui_app , bool ):
1138
1068
raise InvalidArguments ('Argument gui_app must be boolean.' )
1139
- self .win_subsystem = self .validate_win_subsystem (kwargs .get ('win_subsystem' , 'console' ))
1140
- elif 'gui_app' in kwargs :
1141
- raise InvalidArguments ('Argument gui_app can only be used on executables.' )
1142
- elif 'win_subsystem' in kwargs :
1143
- raise InvalidArguments ('Argument win_subsystem can only be used on executables.' )
1069
+ self .win_subsystem = self .validate_win_subsystem (kwargs .get ('win_subsystem' ) or 'console' )
1144
1070
extra_files = extract_as_list (kwargs , 'extra_files' )
1145
1071
for i in extra_files :
1146
1072
assert isinstance (i , File )
@@ -1162,30 +1088,12 @@ def process_kwargs(self, kwargs):
1162
1088
if not os .path .isfile (trial ):
1163
1089
raise InvalidArguments (f'Tried to add non-existing resource { r } .' )
1164
1090
self .resources = resources
1165
- if 'name_prefix' in kwargs :
1166
- name_prefix = kwargs ['name_prefix' ]
1167
- if isinstance (name_prefix , list ):
1168
- if name_prefix :
1169
- raise InvalidArguments ('name_prefix array must be empty to signify default.' )
1170
- else :
1171
- if not isinstance (name_prefix , str ):
1172
- raise InvalidArguments ('name_prefix must be a string.' )
1173
- self .prefix = name_prefix
1174
- self .name_prefix_set = True
1175
- if 'name_suffix' in kwargs :
1176
- name_suffix = kwargs ['name_suffix' ]
1177
- if isinstance (name_suffix , list ):
1178
- if name_suffix :
1179
- raise InvalidArguments ('name_suffix array must be empty to signify default.' )
1180
- else :
1181
- if not isinstance (name_suffix , str ):
1182
- raise InvalidArguments ('name_suffix must be a string.' )
1183
- if name_suffix == '' :
1184
- raise InvalidArguments ('name_suffix should not be an empty string. '
1185
- 'If you want meson to use the default behaviour '
1186
- 'for each platform pass `[]` (empty array)' )
1187
- self .suffix = name_suffix
1188
- self .name_suffix_set = True
1091
+ if kwargs .get ('name_prefix' ) is not None :
1092
+ self .prefix = kwargs ['name_prefix' ]
1093
+ self .name_prefix_set = True
1094
+ if kwargs .get ('name_suffix' ) is not None :
1095
+ self .suffix = kwargs ['name_suffix' ]
1096
+ self .name_suffix_set = True
1189
1097
if isinstance (self , StaticLibrary ):
1190
1098
# You can't disable PIC on OS X. The compiler ignores -fno-PIC.
1191
1099
# PIC is always on for Windows (all code is position-independent
@@ -1226,7 +1134,7 @@ def _extract_pic_pie(self, kwargs, arg: str, option: str):
1226
1134
return True
1227
1135
1228
1136
k = OptionKey (option )
1229
- if arg in kwargs :
1137
+ if kwargs . get ( arg ) is not None :
1230
1138
val = kwargs [arg ]
1231
1139
elif k in self .environment .coredata .options :
1232
1140
val = self .environment .coredata .options [k ].value
@@ -1778,7 +1686,6 @@ def get_subdir(self) -> str:
1778
1686
1779
1687
1780
1688
class Executable (BuildTarget ):
1781
- known_kwargs = known_exe_kwargs
1782
1689
1783
1690
typename = 'executable'
1784
1691
@@ -1907,7 +1814,6 @@ def get_command(self) -> 'ImmutableListProtocol[str]':
1907
1814
return self .outputs
1908
1815
1909
1816
class StaticLibrary (BuildTarget ):
1910
- known_kwargs = known_stlib_kwargs
1911
1817
1912
1818
typename = 'static library'
1913
1819
@@ -1979,7 +1885,6 @@ def is_internal(self) -> bool:
1979
1885
return not self .need_install
1980
1886
1981
1887
class SharedLibrary (BuildTarget ):
1982
- known_kwargs = known_shlib_kwargs
1983
1888
1984
1889
typename = 'shared library'
1985
1890
@@ -2151,57 +2056,19 @@ def determine_filenames(self):
2151
2056
if create_debug_file :
2152
2057
self .debug_filename = os .path .splitext (self .filename )[0 ] + '.pdb'
2153
2058
2154
- @staticmethod
2155
- def _validate_darwin_versions (darwin_versions ):
2156
- try :
2157
- if isinstance (darwin_versions , int ):
2158
- darwin_versions = str (darwin_versions )
2159
- if isinstance (darwin_versions , str ):
2160
- darwin_versions = 2 * [darwin_versions ]
2161
- if not isinstance (darwin_versions , list ):
2162
- raise InvalidArguments ('Shared library darwin_versions: must be a string, integer,'
2163
- f'or a list, not { darwin_versions !r} ' )
2164
- if len (darwin_versions ) > 2 :
2165
- raise InvalidArguments ('Shared library darwin_versions: list must contain 2 or fewer elements' )
2166
- if len (darwin_versions ) == 1 :
2167
- darwin_versions = 2 * darwin_versions
2168
- for i , v in enumerate (darwin_versions [:]):
2169
- if isinstance (v , int ):
2170
- v = str (v )
2171
- if not isinstance (v , str ):
2172
- raise InvalidArguments ('Shared library darwin_versions: list elements '
2173
- f'must be strings or integers, not { v !r} ' )
2174
- if not re .fullmatch (r'[0-9]+(\.[0-9]+){0,2}' , v ):
2175
- raise InvalidArguments ('Shared library darwin_versions: must be X.Y.Z where '
2176
- 'X, Y, Z are numbers, and Y and Z are optional' )
2177
- parts = v .split ('.' )
2178
- if len (parts ) in {1 , 2 , 3 } and int (parts [0 ]) > 65535 :
2179
- raise InvalidArguments ('Shared library darwin_versions: must be X.Y.Z '
2180
- 'where X is [0, 65535] and Y, Z are optional' )
2181
- if len (parts ) in {2 , 3 } and int (parts [1 ]) > 255 :
2182
- raise InvalidArguments ('Shared library darwin_versions: must be X.Y.Z '
2183
- 'where Y is [0, 255] and Y, Z are optional' )
2184
- if len (parts ) == 3 and int (parts [2 ]) > 255 :
2185
- raise InvalidArguments ('Shared library darwin_versions: must be X.Y.Z '
2186
- 'where Z is [0, 255] and Y, Z are optional' )
2187
- darwin_versions [i ] = v
2188
- except ValueError :
2189
- raise InvalidArguments ('Shared library darwin_versions: value is invalid' )
2190
- return darwin_versions
2191
-
2192
2059
def process_kwargs (self , kwargs ):
2193
2060
super ().process_kwargs (kwargs )
2194
2061
2195
2062
if not self .environment .machines [self .for_machine ].is_android ():
2196
2063
# Shared library version
2197
- if 'version' in kwargs :
2064
+ if 'version' in kwargs and kwargs [ 'version' ] is not None :
2198
2065
self .ltversion = kwargs ['version' ]
2199
2066
if not isinstance (self .ltversion , str ):
2200
2067
raise InvalidArguments ('Shared library version needs to be a string, not ' + type (self .ltversion ).__name__ )
2201
2068
if not re .fullmatch (r'[0-9]+(\.[0-9]+){0,2}' , self .ltversion ):
2202
2069
raise InvalidArguments (f'Invalid Shared library version "{ self .ltversion } ". Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.' )
2203
2070
# Try to extract/deduce the soversion
2204
- if 'soversion' in kwargs :
2071
+ if 'soversion' in kwargs and kwargs [ 'soversion' ] is not None :
2205
2072
self .soversion = kwargs ['soversion' ]
2206
2073
if isinstance (self .soversion , int ):
2207
2074
self .soversion = str (self .soversion )
@@ -2213,14 +2080,14 @@ def process_kwargs(self, kwargs):
2213
2080
# number of the version by default.
2214
2081
self .soversion = self .ltversion .split ('.' )[0 ]
2215
2082
# macOS, iOS and tvOS dylib compatibility_version and current_version
2216
- if 'darwin_versions' in kwargs :
2217
- self .darwin_versions = self . _validate_darwin_versions ( kwargs ['darwin_versions' ])
2083
+ if 'darwin_versions' in kwargs and kwargs [ 'darwin_versions' ] is not None :
2084
+ self .darwin_versions = kwargs ['darwin_versions' ]
2218
2085
elif self .soversion :
2219
2086
# If unspecified, pick the soversion
2220
2087
self .darwin_versions = 2 * [self .soversion ]
2221
2088
2222
2089
# Visual Studio module-definitions file
2223
- if 'vs_module_defs' in kwargs :
2090
+ if kwargs . get ( 'vs_module_defs' ) is not None :
2224
2091
path = kwargs ['vs_module_defs' ]
2225
2092
if isinstance (path , str ):
2226
2093
if os .path .isabs (path ):
@@ -2239,7 +2106,7 @@ def process_kwargs(self, kwargs):
2239
2106
'a file object or a Custom Target' )
2240
2107
self .process_link_depends (path )
2241
2108
2242
- if 'rust_crate_type' in kwargs :
2109
+ if 'rust_crate_type' in kwargs and kwargs [ 'rust_crate_type' ] is not None :
2243
2110
rust_crate_type = kwargs ['rust_crate_type' ]
2244
2111
if isinstance (rust_crate_type , str ):
2245
2112
self .rust_crate_type = rust_crate_type
@@ -2313,7 +2180,6 @@ def is_linkable_target(self):
2313
2180
# A shared library that is meant to be used with dlopen rather than linking
2314
2181
# into something else.
2315
2182
class SharedModule (SharedLibrary ):
2316
- known_kwargs = known_shmod_kwargs
2317
2183
2318
2184
typename = 'shared module'
2319
2185
@@ -2683,7 +2549,6 @@ def __repr__(self):
2683
2549
return repr_str .format (self .__class__ .__name__ , self .get_id ())
2684
2550
2685
2551
class Jar (BuildTarget ):
2686
- known_kwargs = known_jar_kwargs
2687
2552
2688
2553
typename = 'jar'
2689
2554
0 commit comments