@@ -158,23 +158,25 @@ def compile_test_executable(self):
158
158
for start in ("-fvisibility" , "-g" , "-O" ))]
159
159
160
160
# Reduce optimisation a bit to ensure that the debugging experience is good
161
- extra_compile_args += ["-O1" , "-g" ]
162
- debug = True
161
+ if "--coverage" in extra_compile_args :
162
+ extra_compile_args += ["-O0" , "-g" ]
163
+ else :
164
+ extra_compile_args += ["-O1" , "-g" ]
163
165
164
166
# Bring forward stuff from libadcc
165
167
compiler = new_compiler (verbose = self .verbose )
166
168
customize_compiler (compiler )
167
169
objects = compiler .compile (
168
170
sources , output_dir , libadcc .define_macros , include_dirs ,
169
- debug , extra_postargs = extra_compile_args
171
+ debug = True , extra_postargs = extra_compile_args
170
172
)
171
173
172
174
if libadcc .extra_objects :
173
175
objects .extend (libadcc .extra_objects )
174
176
175
177
compiler .link_executable (
176
178
objects , "libadcc_tests" , output_dir , libadcc .libraries ,
177
- libadcc .library_dirs , libadcc .runtime_library_dirs , debug ,
179
+ libadcc .library_dirs , libadcc .runtime_library_dirs , debug = True ,
178
180
extra_postargs = libadcc .extra_link_args , target_lang = libadcc .language
179
181
)
180
182
return test_executable
@@ -332,29 +334,33 @@ def libadcc_extension():
332
334
thisdir = os .path .dirname (__file__ )
333
335
334
336
# Initial lot of flags
335
- libraries = []
336
- library_dirs = []
337
- include_dirs = [os .path .join (thisdir , "libadcc" )]
338
- extra_link_args = []
339
- extra_compile_args = ["-Wall" , "-Wextra" , "-Werror" , "-O3" ]
340
- runtime_library_dirs = []
341
- extra_objects = []
342
- define_macros = []
343
- search_system = True
337
+ flags = dict (
338
+ libraries = [],
339
+ library_dirs = [],
340
+ include_dirs = [os .path .join (thisdir , "libadcc" )],
341
+ extra_link_args = [],
342
+ extra_compile_args = ["-Wall" , "-Wextra" , "-Werror" , "-O3" ],
343
+ runtime_library_dirs = [],
344
+ extra_objects = [],
345
+ define_macros = [],
346
+ search_system = True ,
347
+ coverage = False ,
348
+ libtensor_autoinstall = "~/.local" ,
349
+ )
344
350
345
351
if sys .platform == "darwin" and is_conda_build ():
346
- extra_compile_args += ["-Wno-unused-command-line-argument" ,
347
- "-Wno-undefined-var-template" ]
352
+ flags [ " extra_compile_args" ] += ["-Wno-unused-command-line-argument" ,
353
+ "-Wno-undefined-var-template" ]
348
354
349
355
platform_autoinstall = (
350
356
sys .platform .startswith ("linux" ) or sys .platform .startswith ("darwin" )
351
357
)
352
358
if platform_autoinstall and not is_conda_build ():
353
- libtensor_autoinstall = "~/.local"
359
+ flags [ " libtensor_autoinstall" ] = "~/.local"
354
360
else :
355
361
# Not yet supported on other platforms and disabled
356
362
# for conda builds
357
- libtensor_autoinstall = None
363
+ flags [ " libtensor_autoinstall" ] = None
358
364
359
365
# User-provided config
360
366
adcc_config = os .environ .get ('ADCC_CONFIG' )
@@ -365,20 +371,21 @@ def libadcc_extension():
365
371
siteconfig = os .path .expanduser (siteconfig )
366
372
if os .path .isfile (siteconfig ):
367
373
log .info ("Reading siteconfig file:" , siteconfig )
368
- exec (open (siteconfig , "r" ).read ())
374
+ exec (open (siteconfig , "r" ).read (), flags )
375
+ flags .pop ("__builtins__" )
369
376
break
370
377
371
378
# Keep track whether libtensor has been found
372
- found_libtensor = "tensorlight" in libraries
379
+ found_libtensor = "tensorlight" in flags [ " libraries" ]
373
380
lt_min_version = "2.9.9"
374
381
375
382
if not found_libtensor :
376
- if search_system : # Try to find libtensor on the OS using pkg-config
383
+ if flags [ " search_system" ] : # Find libtensor on the OS using pkg-config
377
384
log .info ("Searching OS for libtensorlight using pkg-config" )
378
385
cflags , libs = search_with_pkg_config ("libtensorlight" , lt_min_version )
379
386
380
387
# Try to download libtensor if not on the OS
381
- if (cflags is None or libs is None ) and libtensor_autoinstall :
388
+ if (cflags is None or libs is None ) and flags [ " libtensor_autoinstall" ] :
382
389
assets = assets_most_recent_release ("adc-connect/libtensor" )
383
390
url = []
384
391
if sys .platform == "linux" :
@@ -397,45 +404,43 @@ def libadcc_extension():
397
404
"(https://adc-connect.org/latest/installation.html)."
398
405
)
399
406
400
- destdir = os .path .expanduser (libtensor_autoinstall )
407
+ destdir = os .path .expanduser (flags [ " libtensor_autoinstall" ] )
401
408
install_libtensor (url [0 ], destdir )
402
409
os .environ ['PKG_CONFIG_PATH' ] += f":{ destdir } /lib/pkgconfig"
403
410
cflags , libs = search_with_pkg_config ("libtensorlight" , lt_min_version )
404
411
assert cflags is not None and libs is not None
405
412
406
413
if cflags is not None and libs is not None :
407
414
found_libtensor = True
408
- extra_compile_args .extend (cflags )
409
- extra_link_args .extend (libs )
415
+ flags [ " extra_compile_args" ] .extend (cflags )
416
+ flags [ " extra_link_args" ] .extend (libs )
410
417
log .info (f"Using libtensorlight libraries: { libs } ." )
411
418
if sys .platform == "darwin" :
412
- extra_link_args .append ("-Wl,-rpath,@loader_path" )
419
+ flags [ " extra_link_args" ] .append ("-Wl,-rpath,@loader_path" )
413
420
for path in extract_library_dirs (libs ):
414
- extra_link_args .append (f"-Wl,-rpath,{ path } " )
421
+ flags [ " extra_link_args" ] .append (f"-Wl,-rpath,{ path } " )
415
422
else :
416
- runtime_library_dirs .extend (extract_library_dirs (libs ))
423
+ flags [ " runtime_library_dirs" ] .extend (extract_library_dirs (libs ))
417
424
418
425
if not found_libtensor :
419
426
raise RuntimeError ("Did not find the libtensorlight library." )
420
427
421
- # This is needed on the first pass where pybind11 is not yet installed
422
- cxx_stdargs = dict ()
428
+ # Filter out the arguments to pass to Pybind11Extension
429
+ extargs = {k : v for k , v in flags .items ()
430
+ if k in ("libraries" , "library_dirs" , "include_dirs" ,
431
+ "extra_link_args" , "extra_compile_args" ,
432
+ "runtime_library_dirs" , "extra_objects" ,
433
+ "define_macros" )}
423
434
if have_pybind11 :
424
- cxx_stdargs ["cxx_std" ] = 14
425
- return Pybind11Extension (
426
- "libadcc" ,
427
- libadcc_sources ("extension" ),
428
- libraries = libraries ,
429
- library_dirs = library_dirs ,
430
- include_dirs = include_dirs ,
431
- extra_link_args = extra_link_args ,
432
- extra_compile_args = extra_compile_args ,
433
- runtime_library_dirs = runtime_library_dirs ,
434
- extra_objects = extra_objects ,
435
- define_macros = define_macros ,
436
- language = "c++" ,
437
- ** cxx_stdargs ,
438
- )
435
+ # This is needed on the first pass where pybind11 is not yet installed
436
+ extargs ["cxx_std" ] = 14
437
+
438
+ ext = Pybind11Extension ("libadcc" , libadcc_sources ("extension" ),
439
+ language = "c++" , ** extargs )
440
+ if flags ["coverage" ]:
441
+ ext .extra_compile_args += ["--coverage" , "-O0" , "-g" ]
442
+ ext .extra_link_args += ["--coverage" ]
443
+ return ext
439
444
440
445
441
446
#
0 commit comments