1 | n/a | """Tests for distutils.unixccompiler.""" |
---|
2 | n/a | import sys |
---|
3 | n/a | import unittest |
---|
4 | n/a | from test.support import EnvironmentVarGuard, run_unittest |
---|
5 | n/a | |
---|
6 | n/a | from distutils import sysconfig |
---|
7 | n/a | from distutils.unixccompiler import UnixCCompiler |
---|
8 | n/a | |
---|
9 | n/a | class UnixCCompilerTestCase(unittest.TestCase): |
---|
10 | n/a | |
---|
11 | n/a | def setUp(self): |
---|
12 | n/a | self._backup_platform = sys.platform |
---|
13 | n/a | self._backup_get_config_var = sysconfig.get_config_var |
---|
14 | n/a | class CompilerWrapper(UnixCCompiler): |
---|
15 | n/a | def rpath_foo(self): |
---|
16 | n/a | return self.runtime_library_dir_option('/foo') |
---|
17 | n/a | self.cc = CompilerWrapper() |
---|
18 | n/a | |
---|
19 | n/a | def tearDown(self): |
---|
20 | n/a | sys.platform = self._backup_platform |
---|
21 | n/a | sysconfig.get_config_var = self._backup_get_config_var |
---|
22 | n/a | |
---|
23 | n/a | @unittest.skipIf(sys.platform == 'win32', "can't test on Windows") |
---|
24 | n/a | def test_runtime_libdir_option(self): |
---|
25 | n/a | # Issue#5900 |
---|
26 | n/a | # |
---|
27 | n/a | # Ensure RUNPATH is added to extension modules with RPATH if |
---|
28 | n/a | # GNU ld is used |
---|
29 | n/a | |
---|
30 | n/a | # darwin |
---|
31 | n/a | sys.platform = 'darwin' |
---|
32 | n/a | self.assertEqual(self.cc.rpath_foo(), '-L/foo') |
---|
33 | n/a | |
---|
34 | n/a | # hp-ux |
---|
35 | n/a | sys.platform = 'hp-ux' |
---|
36 | n/a | old_gcv = sysconfig.get_config_var |
---|
37 | n/a | def gcv(v): |
---|
38 | n/a | return 'xxx' |
---|
39 | n/a | sysconfig.get_config_var = gcv |
---|
40 | n/a | self.assertEqual(self.cc.rpath_foo(), ['+s', '-L/foo']) |
---|
41 | n/a | |
---|
42 | n/a | def gcv(v): |
---|
43 | n/a | return 'gcc' |
---|
44 | n/a | sysconfig.get_config_var = gcv |
---|
45 | n/a | self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo']) |
---|
46 | n/a | |
---|
47 | n/a | def gcv(v): |
---|
48 | n/a | return 'g++' |
---|
49 | n/a | sysconfig.get_config_var = gcv |
---|
50 | n/a | self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo']) |
---|
51 | n/a | |
---|
52 | n/a | sysconfig.get_config_var = old_gcv |
---|
53 | n/a | |
---|
54 | n/a | # irix646 |
---|
55 | n/a | sys.platform = 'irix646' |
---|
56 | n/a | self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo']) |
---|
57 | n/a | |
---|
58 | n/a | # osf1V5 |
---|
59 | n/a | sys.platform = 'osf1V5' |
---|
60 | n/a | self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo']) |
---|
61 | n/a | |
---|
62 | n/a | # GCC GNULD |
---|
63 | n/a | sys.platform = 'bar' |
---|
64 | n/a | def gcv(v): |
---|
65 | n/a | if v == 'CC': |
---|
66 | n/a | return 'gcc' |
---|
67 | n/a | elif v == 'GNULD': |
---|
68 | n/a | return 'yes' |
---|
69 | n/a | sysconfig.get_config_var = gcv |
---|
70 | n/a | self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo') |
---|
71 | n/a | |
---|
72 | n/a | # GCC non-GNULD |
---|
73 | n/a | sys.platform = 'bar' |
---|
74 | n/a | def gcv(v): |
---|
75 | n/a | if v == 'CC': |
---|
76 | n/a | return 'gcc' |
---|
77 | n/a | elif v == 'GNULD': |
---|
78 | n/a | return 'no' |
---|
79 | n/a | sysconfig.get_config_var = gcv |
---|
80 | n/a | self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo') |
---|
81 | n/a | |
---|
82 | n/a | # GCC GNULD with fully qualified configuration prefix |
---|
83 | n/a | # see #7617 |
---|
84 | n/a | sys.platform = 'bar' |
---|
85 | n/a | def gcv(v): |
---|
86 | n/a | if v == 'CC': |
---|
87 | n/a | return 'x86_64-pc-linux-gnu-gcc-4.4.2' |
---|
88 | n/a | elif v == 'GNULD': |
---|
89 | n/a | return 'yes' |
---|
90 | n/a | sysconfig.get_config_var = gcv |
---|
91 | n/a | self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo') |
---|
92 | n/a | |
---|
93 | n/a | # non-GCC GNULD |
---|
94 | n/a | sys.platform = 'bar' |
---|
95 | n/a | def gcv(v): |
---|
96 | n/a | if v == 'CC': |
---|
97 | n/a | return 'cc' |
---|
98 | n/a | elif v == 'GNULD': |
---|
99 | n/a | return 'yes' |
---|
100 | n/a | sysconfig.get_config_var = gcv |
---|
101 | n/a | self.assertEqual(self.cc.rpath_foo(), '-R/foo') |
---|
102 | n/a | |
---|
103 | n/a | # non-GCC non-GNULD |
---|
104 | n/a | sys.platform = 'bar' |
---|
105 | n/a | def gcv(v): |
---|
106 | n/a | if v == 'CC': |
---|
107 | n/a | return 'cc' |
---|
108 | n/a | elif v == 'GNULD': |
---|
109 | n/a | return 'no' |
---|
110 | n/a | sysconfig.get_config_var = gcv |
---|
111 | n/a | self.assertEqual(self.cc.rpath_foo(), '-R/foo') |
---|
112 | n/a | |
---|
113 | n/a | @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X') |
---|
114 | n/a | def test_osx_cc_overrides_ldshared(self): |
---|
115 | n/a | # Issue #18080: |
---|
116 | n/a | # ensure that setting CC env variable also changes default linker |
---|
117 | n/a | def gcv(v): |
---|
118 | n/a | if v == 'LDSHARED': |
---|
119 | n/a | return 'gcc-4.2 -bundle -undefined dynamic_lookup ' |
---|
120 | n/a | return 'gcc-4.2' |
---|
121 | n/a | sysconfig.get_config_var = gcv |
---|
122 | n/a | with EnvironmentVarGuard() as env: |
---|
123 | n/a | env['CC'] = 'my_cc' |
---|
124 | n/a | del env['LDSHARED'] |
---|
125 | n/a | sysconfig.customize_compiler(self.cc) |
---|
126 | n/a | self.assertEqual(self.cc.linker_so[0], 'my_cc') |
---|
127 | n/a | |
---|
128 | n/a | @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X') |
---|
129 | n/a | def test_osx_explicit_ldshared(self): |
---|
130 | n/a | # Issue #18080: |
---|
131 | n/a | # ensure that setting CC env variable does not change |
---|
132 | n/a | # explicit LDSHARED setting for linker |
---|
133 | n/a | def gcv(v): |
---|
134 | n/a | if v == 'LDSHARED': |
---|
135 | n/a | return 'gcc-4.2 -bundle -undefined dynamic_lookup ' |
---|
136 | n/a | return 'gcc-4.2' |
---|
137 | n/a | sysconfig.get_config_var = gcv |
---|
138 | n/a | with EnvironmentVarGuard() as env: |
---|
139 | n/a | env['CC'] = 'my_cc' |
---|
140 | n/a | env['LDSHARED'] = 'my_ld -bundle -dynamic' |
---|
141 | n/a | sysconfig.customize_compiler(self.cc) |
---|
142 | n/a | self.assertEqual(self.cc.linker_so[0], 'my_ld') |
---|
143 | n/a | |
---|
144 | n/a | |
---|
145 | n/a | def test_suite(): |
---|
146 | n/a | return unittest.makeSuite(UnixCCompilerTestCase) |
---|
147 | n/a | |
---|
148 | n/a | if __name__ == "__main__": |
---|
149 | n/a | run_unittest(test_suite()) |
---|