@@ -66,9 +66,9 @@ def get_cmake_command(cmake_names=None): # pragma: nocover
66
66
cmake_names = ['cmake' , 'cmake3' ]
67
67
68
68
for cmake in cmake_names :
69
- cmake_cmd = [ shutil .which (cmake )]
70
- if cmake_cmd is not None and _try_calling_cmake (cmake_cmd ):
71
- return cmake_cmd
69
+ cmake_cmd = shutil .which (cmake )
70
+ if cmake_cmd is not None and _try_calling_cmake ([ cmake_cmd ] ):
71
+ return [ cmake_cmd ]
72
72
73
73
# CMake not in PATH, should have installed Python CMake module
74
74
# -> try to find out where it is
@@ -128,7 +128,8 @@ def add_cmake_arguments_to_parser(parser):
128
128
description = 'Options mirroring those of CMake and that will be passed onto CMake as-is.' ,
129
129
)
130
130
options = parser .add_argument_group (
131
- title = 'Other CMake related options' , description = 'Options used to configure how CMake is called'
131
+ title = 'Other CMake related options' ,
132
+ description = 'Options used to configure how CMake is called' ,
132
133
)
133
134
platform_specific_cmake = parser .add_argument_group (
134
135
title = 'Options to define platform-dependent CMake variables' ,
@@ -141,7 +142,11 @@ def add_cmake_arguments_to_parser(parser):
141
142
142
143
# Custom options
143
144
options .add_argument ('--clean' , action = 'store_true' , help = 'Start from a clean build directory' )
144
- options .add_argument ('--cmake' , type = _argparse .executable_path , help = 'Specify path to CMake executable.' )
145
+ options .add_argument (
146
+ '--cmake' ,
147
+ type = _argparse .executable_path ,
148
+ help = 'Specify path to CMake executable.' ,
149
+ )
145
150
options .add_argument (
146
151
'--detect-configured-files' ,
147
152
action = 'store_true' ,
@@ -171,20 +176,40 @@ def add_cmake_arguments_to_parser(parser):
171
176
help = 'Unix-only (ie. Linux and MacOS) options for CMake' ,
172
177
)
173
178
platform_specific_cmake .add_argument (
174
- '--linux' , action = _argparse .OSSpecificAction , type = str , help = 'Linux-only options for CMake'
179
+ '--linux' ,
180
+ action = _argparse .OSSpecificAction ,
181
+ type = str ,
182
+ help = 'Linux-only options for CMake' ,
175
183
)
176
184
platform_specific_cmake .add_argument (
177
- '--mac' , action = _argparse .OSSpecificAction , type = str , help = 'Mac-only options for CMake'
185
+ '--mac' ,
186
+ action = _argparse .OSSpecificAction ,
187
+ type = str ,
188
+ help = 'Mac-only options for CMake' ,
178
189
)
179
190
platform_specific_cmake .add_argument (
180
- '--win' , action = _argparse .OSSpecificAction , type = str , help = 'Windows-only options for CMake'
191
+ '--win' ,
192
+ action = _argparse .OSSpecificAction ,
193
+ type = str ,
194
+ help = 'Windows-only options for CMake' ,
181
195
)
182
196
183
197
# CMake-like options
184
198
cmake_options .add_argument ('-S' , '--source-dir' , type = str , help = 'Path to build directory' , default = '.' )
185
- cmake_options .add_argument ('-B' , '--build-dir' , action = 'append' , type = str , help = 'Path to build directory' )
186
199
cmake_options .add_argument (
187
- '-D' , dest = 'defines' , action = 'append' , type = str , help = 'Create or update a cmake cache entry.' , default = []
200
+ '-B' ,
201
+ '--build-dir' ,
202
+ action = 'append' ,
203
+ type = str ,
204
+ help = 'Path to build directory' ,
205
+ )
206
+ cmake_options .add_argument (
207
+ '-D' ,
208
+ dest = 'defines' ,
209
+ action = 'append' ,
210
+ type = str ,
211
+ help = 'Create or update a cmake cache entry.' ,
212
+ default = [],
188
213
)
189
214
cmake_options .add_argument (
190
215
'-U' ,
@@ -196,11 +221,23 @@ def add_cmake_arguments_to_parser(parser):
196
221
)
197
222
cmake_options .add_argument ('-G' , dest = 'generator' , type = str , help = 'Specify a build system generator.' )
198
223
cmake_options .add_argument (
199
- '-T' , dest = 'toolset' , type = str , help = 'Specify toolset name if supported by generator.'
224
+ '-T' ,
225
+ dest = 'toolset' ,
226
+ type = str ,
227
+ help = 'Specify toolset name if supported by generator.' ,
200
228
)
201
- cmake_options .add_argument ('-A' , dest = 'platform' , type = str , help = 'Specify platform if supported by generator.' )
202
229
cmake_options .add_argument (
203
- '-Werror' , dest = 'errors' , choices = ['dev' ], help = 'Make developer warnings errors.' , default = []
230
+ '-A' ,
231
+ dest = 'platform' ,
232
+ type = str ,
233
+ help = 'Specify platform if supported by generator.' ,
234
+ )
235
+ cmake_options .add_argument (
236
+ '-Werror' ,
237
+ dest = 'errors' ,
238
+ choices = ['dev' ],
239
+ help = 'Make developer warnings errors.' ,
240
+ default = [],
204
241
)
205
242
cmake_options .add_argument (
206
243
'-Wno-error' ,
@@ -211,9 +248,17 @@ def add_cmake_arguments_to_parser(parser):
211
248
)
212
249
cmake_options .add_argument ('--preset' , type = str , help = 'Specify a configure preset.' )
213
250
214
- cmake_options .add_argument ('-Wdev' , dest = 'dev_warnings' , action = 'store_true' , help = 'Enable developer warnings.' )
215
251
cmake_options .add_argument (
216
- '-Wno-dev' , dest = 'no_dev_warnings' , action = 'store_true' , help = 'Suppress developer warnings.'
252
+ '-Wdev' ,
253
+ dest = 'dev_warnings' ,
254
+ action = 'store_true' ,
255
+ help = 'Enable developer warnings.' ,
256
+ )
257
+ cmake_options .add_argument (
258
+ '-Wno-dev' ,
259
+ dest = 'no_dev_warnings' ,
260
+ action = 'store_true' ,
261
+ help = 'Suppress developer warnings.' ,
217
262
)
218
263
219
264
def resolve_build_directory (self , build_dir_list = None , * , automatic_discovery = True ):
@@ -222,7 +267,10 @@ def resolve_build_directory(self, build_dir_list=None, *, automatic_discovery=Tr
222
267
build_dir_list = [] if build_dir_list is None else [Path (path ) for path in build_dir_list ]
223
268
for build_dir in build_dir_list :
224
269
if build_dir .exists () and Path (build_dir , 'CMakeCache.txt' ).exists ():
225
- logging .debug ('Located valid build directory with CMakeCache.txt at: %s' , str (build_dir ))
270
+ logging .debug (
271
+ 'Located valid build directory with CMakeCache.txt at: %s' ,
272
+ str (build_dir ),
273
+ )
226
274
self .build_dir = build_dir .resolve ()
227
275
return
228
276
@@ -243,7 +291,10 @@ def resolve_build_directory(self, build_dir_list=None, *, automatic_discovery=Tr
243
291
self .build_dir = self .source_dir / self .DEFAULT_BUILD_DIR
244
292
else :
245
293
self .build_dir = Path (build_dir_list [0 ]).resolve ()
246
- logging .info ('Unable to locate a valid build directory. Will be creating one at %s' , str (self .build_dir ))
294
+ logging .info (
295
+ 'Unable to locate a valid build directory. Will be creating one at %s' ,
296
+ str (self .build_dir ),
297
+ )
247
298
248
299
def setup_cmake_args (self , cmake_args ): # noqa: C901
249
300
"""
@@ -272,7 +323,8 @@ def setup_cmake_args(self, cmake_args): # noqa: C901
272
323
self .no_cmake_configure = cmake_args .no_cmake_configure
273
324
274
325
self .resolve_build_directory (
275
- build_dir_list = cmake_args .build_dir , automatic_discovery = cmake_args .automatic_discovery
326
+ build_dir_list = cmake_args .build_dir ,
327
+ automatic_discovery = cmake_args .automatic_discovery ,
276
328
)
277
329
278
330
if cmake_args .detect_configured_files and self .build_dir :
@@ -344,13 +396,29 @@ def configure(self, command, *, clean_build=False):
344
396
try :
345
397
with cmake_configure_try_lock .acquire (blocking = False ): # noqa: SIM117
346
398
with cmake_configure_lock .write_lock ():
347
- logging .debug ('Command %s with id %s is running CMake configure' , command , os .getpid ())
399
+ logging .debug (
400
+ 'Command %s with id %s is running CMake configure' ,
401
+ command ,
402
+ os .getpid (),
403
+ )
348
404
returncode = self ._configure (
349
- lock_files = (cmake_configure_lock_file , cmake_configure_try_lock_file ), clean_build = clean_build
405
+ lock_files = (
406
+ cmake_configure_lock_file ,
407
+ cmake_configure_try_lock_file ,
408
+ ),
409
+ clean_build = clean_build ,
410
+ )
411
+ logging .debug (
412
+ 'Command %s with id %s is done running CMake configure' ,
413
+ command ,
414
+ os .getpid (),
350
415
)
351
- logging .debug ('Command %s with id %s is done running CMake configure' , command , os .getpid ())
352
416
except filelock .Timeout :
353
- logging .debug ('Command %s with id %s is not running CMake configure and waiting' , command , os .getpid ())
417
+ logging .debug (
418
+ 'Command %s with id %s is not running CMake configure and waiting' ,
419
+ command ,
420
+ os .getpid (),
421
+ )
354
422
with cmake_configure_lock .read_lock ():
355
423
logging .debug ('Command %s with id %s is done waiting' , command , os .getpid ())
356
424
returncode = 0
@@ -368,7 +436,8 @@ def _call_cmake(self, extra_args=None):
368
436
extra_args = []
369
437
370
438
result = _call_process .call_process (
371
- [* command , str (self .source_dir ), * self .cmake_args , * extra_args ], cwd = str (self .build_dir )
439
+ [* command , str (self .source_dir ), * self .cmake_args , * extra_args ],
440
+ cwd = str (self .build_dir ),
372
441
)
373
442
result .stdout = '\n ' .join ([
374
443
f'Running CMake with: { [* command , str (self .source_dir ), * self .cmake_args ]} ' ,
@@ -392,7 +461,11 @@ def _configure(self, lock_files, clean_build):
392
461
393
462
extra_args = []
394
463
if self .cmake_trace_log :
395
- extra_args .extend (['--trace-expand' , '--trace-format=json-v1' , f'--trace-redirect={ self .cmake_trace_log } ' ])
464
+ extra_args .extend ([
465
+ '--trace-expand' ,
466
+ '--trace-format=json-v1' ,
467
+ f'--trace-redirect={ self .cmake_trace_log } ' ,
468
+ ])
396
469
397
470
result = self ._call_cmake (extra_args = extra_args )
398
471
@@ -451,7 +524,11 @@ def _is_relevant_configure_file_call(json_data):
451
524
input_file , configured_file = (Path (arg ) for arg in configure_file_call ['args' ][:2 ])
452
525
if not configured_file .is_absolute ():
453
526
configured_file = self .build_dir / configured_file
454
- logging .debug ('detected call to configure_file(%s %s [...])' , str (input_file ), str (configured_file ))
527
+ logging .debug (
528
+ 'detected call to configure_file(%s %s [...])' ,
529
+ str (input_file ),
530
+ str (configured_file ),
531
+ )
455
532
self .cmake_configured_files .append (str (configured_file ))
456
533
457
534
0 commit comments