1 """Tests for distutils.unixccompiler.""" 2 import sys 3 import unittest 4 from test.test_support import run_unittest 5 6 from distutils import sysconfig 7 from distutils.unixccompiler import UnixCCompiler 8 9 class UnixCCompilerTestCase(unittest.TestCase): 10 11 def setUp(self): 12 self._backup_platform = sys.platform 13 self._backup_get_config_var = sysconfig.get_config_var 14 class CompilerWrapper(UnixCCompiler): 15 def rpath_foo(self): 16 return self.runtime_library_dir_option('/foo') 17 self.cc = CompilerWrapper() 18 19 def tearDown(self): 20 sys.platform = self._backup_platform 21 sysconfig.get_config_var = self._backup_get_config_var 22 23 def test_runtime_libdir_option(self): 24 25 # not tested under windows 26 if sys.platform == 'win32': 27 return 28 29 # Issue#5900 30 # 31 # Ensure RUNPATH is added to extension modules with RPATH if 32 # GNU ld is used 33 34 # darwin 35 sys.platform = 'darwin' 36 self.assertEqual(self.cc.rpath_foo(), '-L/foo') 37 38 # hp-ux 39 sys.platform = 'hp-ux' 40 old_gcv = sysconfig.get_config_var 41 def gcv(v): 42 return 'xxx' 43 sysconfig.get_config_var = gcv 44 self.assertEqual(self.cc.rpath_foo(), ['+s', '-L/foo']) 45 46 def gcv(v): 47 return 'gcc' 48 sysconfig.get_config_var = gcv 49 self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo']) 50 51 def gcv(v): 52 return 'g++' 53 sysconfig.get_config_var = gcv 54 self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo']) 55 56 sysconfig.get_config_var = old_gcv 57 58 # irix646 59 sys.platform = 'irix646' 60 self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo']) 61 62 # osf1V5 63 sys.platform = 'osf1V5' 64 self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo']) 65 66 # GCC GNULD 67 sys.platform = 'bar' 68 def gcv(v): 69 if v == 'CC': 70 return 'gcc' 71 elif v == 'GNULD': 72 return 'yes' 73 sysconfig.get_config_var = gcv 74 self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo') 75 76 # GCC non-GNULD 77 sys.platform = 'bar' 78 def gcv(v): 79 if v == 'CC': 80 return 'gcc' 81 elif v == 'GNULD': 82 return 'no' 83 sysconfig.get_config_var = gcv 84 self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo') 85 86 # GCC GNULD with fully qualified configuration prefix 87 # see #7617 88 sys.platform = 'bar' 89 def gcv(v): 90 if v == 'CC': 91 return 'x86_64-pc-linux-gnu-gcc-4.4.2' 92 elif v == 'GNULD': 93 return 'yes' 94 sysconfig.get_config_var = gcv 95 self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo') 96 97 98 # non-GCC GNULD 99 sys.platform = 'bar' 100 def gcv(v): 101 if v == 'CC': 102 return 'cc' 103 elif v == 'GNULD': 104 return 'yes' 105 sysconfig.get_config_var = gcv 106 self.assertEqual(self.cc.rpath_foo(), '-R/foo') 107 108 # non-GCC non-GNULD 109 sys.platform = 'bar' 110 def gcv(v): 111 if v == 'CC': 112 return 'cc' 113 elif v == 'GNULD': 114 return 'no' 115 sysconfig.get_config_var = gcv 116 self.assertEqual(self.cc.rpath_foo(), '-R/foo') 117 118 # AIX C/C++ linker 119 sys.platform = 'aix' 120 def gcv(v): 121 return 'xxx' 122 sysconfig.get_config_var = gcv 123 self.assertEqual(self.cc.rpath_foo(), '-blibpath:/foo') 124 125 126 def test_suite(): 127 return unittest.makeSuite(UnixCCompilerTestCase) 128 129 if __name__ == "__main__": 130 run_unittest(test_suite()) 131