@@ -244,6 +244,69 @@ def gcvs(*args, _orig=sysconfig.get_config_vars):
244
244
sysconfig .customize_compiler (self .cc )
245
245
assert self .cc .linker_so [0 ] == 'my_cc'
246
246
247
+ @pytest .mark .skipif ('platform.system == "Windows"' )
248
+ def test_cxx_commands_used_are_correct (self ):
249
+ def gcv (v ):
250
+ if v == 'LDSHARED' :
251
+ return 'ccache gcc-4.2 -bundle -undefined dynamic_lookup'
252
+ elif v == 'LDCXXSHARED' :
253
+ return 'ccache g++-4.2 -bundle -undefined dynamic_lookup'
254
+ elif v == 'CXX' :
255
+ return 'ccache g++-4.2'
256
+ elif v == 'CC' :
257
+ return 'ccache gcc-4.2'
258
+ return ''
259
+
260
+ def gcvs (* args , _orig = sysconfig .get_config_vars ):
261
+ if args :
262
+ return list (map (sysconfig .get_config_var , args ))
263
+ return _orig () # pragma: no cover
264
+
265
+ sysconfig .get_config_var = gcv
266
+ sysconfig .get_config_vars = gcvs
267
+ with (
268
+ mock .patch .object (self .cc , 'spawn' , return_value = None ) as mock_spawn ,
269
+ mock .patch .object (self .cc , '_need_link' , return_value = True ),
270
+ mock .patch .object (self .cc , 'mkpath' , return_value = None ),
271
+ EnvironmentVarGuard () as env ,
272
+ ):
273
+ # override environment overrides in case they're specified by CI
274
+ del env ['CXX' ]
275
+ del env ['LDCXXSHARED' ]
276
+
277
+ sysconfig .customize_compiler (self .cc )
278
+ assert self .cc .linker_so_cxx [0 :2 ] == ['ccache' , 'g++-4.2' ]
279
+ assert self .cc .linker_exe_cxx [0 :2 ] == ['ccache' , 'g++-4.2' ]
280
+ self .cc .link (None , [], 'a.out' , target_lang = 'c++' )
281
+ call_args = mock_spawn .call_args [0 ][0 ]
282
+ expected = ['ccache' , 'g++-4.2' , '-bundle' , '-undefined' , 'dynamic_lookup' ]
283
+ assert call_args [:5 ] == expected
284
+
285
+ self .cc .link_executable ([], 'a.out' , target_lang = 'c++' )
286
+ call_args = mock_spawn .call_args [0 ][0 ]
287
+ expected = ['ccache' , 'g++-4.2' , '-o' , self .cc .executable_filename ('a.out' )]
288
+ assert call_args [:4 ] == expected
289
+
290
+ env ['LDCXXSHARED' ] = 'wrapper g++-4.2 -bundle -undefined dynamic_lookup'
291
+ env ['CXX' ] = 'wrapper g++-4.2'
292
+ sysconfig .customize_compiler (self .cc )
293
+ assert self .cc .linker_so_cxx [0 :2 ] == ['wrapper' , 'g++-4.2' ]
294
+ assert self .cc .linker_exe_cxx [0 :2 ] == ['wrapper' , 'g++-4.2' ]
295
+ self .cc .link (None , [], 'a.out' , target_lang = 'c++' )
296
+ call_args = mock_spawn .call_args [0 ][0 ]
297
+ expected = ['wrapper' , 'g++-4.2' , '-bundle' , '-undefined' , 'dynamic_lookup' ]
298
+ assert call_args [:5 ] == expected
299
+
300
+ self .cc .link_executable ([], 'a.out' , target_lang = 'c++' )
301
+ call_args = mock_spawn .call_args [0 ][0 ]
302
+ expected = [
303
+ 'wrapper' ,
304
+ 'g++-4.2' ,
305
+ '-o' ,
306
+ self .cc .executable_filename ('a.out' ),
307
+ ]
308
+ assert call_args [:4 ] == expected
309
+
247
310
@pytest .mark .skipif ('platform.system == "Windows"' )
248
311
@pytest .mark .usefixtures ('disable_macos_customization' )
249
312
def test_cc_overrides_ldshared_for_cxx_correctly (self ):
0 commit comments