@@ -244,6 +244,60 @@ 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 ()
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
+ sysconfig .customize_compiler (self .cc )
274
+ assert self .cc .linker_so_cxx [0 :2 ] == ['ccache' , 'g++-4.2' ]
275
+ assert self .cc .linker_exe_cxx [0 :2 ] == ['ccache' , 'g++-4.2' ]
276
+ self .cc .link (None , [], 'a.out' , target_lang = 'c++' )
277
+ call_args = mock_spawn .call_args [0 ][0 ]
278
+ expected = ['ccache' , 'g++-4.2' , '-bundle' , '-undefined' , 'dynamic_lookup' ]
279
+ assert call_args [:5 ] == expected
280
+
281
+ self .cc .link_executable ([], 'a.out' , target_lang = 'c++' )
282
+ call_args = mock_spawn .call_args [0 ][0 ]
283
+ expected = ['ccache' , 'g++-4.2' , '-o' , 'a.out' ]
284
+ assert call_args [:4 ] == expected
285
+
286
+ env ['LDCXXSHARED' ] = 'wrapper g++-4.2 -bundle -undefined dynamic_lookup'
287
+ env ['CXX' ] = 'wrapper g++-4.2'
288
+ sysconfig .customize_compiler (self .cc )
289
+ assert self .cc .linker_so_cxx [0 :2 ] == ['wrapper' , 'g++-4.2' ]
290
+ assert self .cc .linker_exe_cxx [0 :2 ] == ['wrapper' , 'g++-4.2' ]
291
+ self .cc .link (None , [], 'a.out' , target_lang = 'c++' )
292
+ call_args = mock_spawn .call_args [0 ][0 ]
293
+ expected = ['wrapper' , 'g++-4.2' , '-bundle' , '-undefined' , 'dynamic_lookup' ]
294
+ assert call_args [:5 ] == expected
295
+
296
+ self .cc .link_executable ([], 'a.out' , target_lang = 'c++' )
297
+ call_args = mock_spawn .call_args [0 ][0 ]
298
+ expected = ['wrapper' , 'g++-4.2' , '-o' , 'a.out' ]
299
+ assert call_args [:4 ] == expected
300
+
247
301
@pytest .mark .skipif ('platform.system == "Windows"' )
248
302
@pytest .mark .usefixtures ('disable_macos_customization' )
249
303
def test_cc_overrides_ldshared_for_cxx_correctly (self ):
0 commit comments