1 | n/a | """ |
---|
2 | n/a | Test suite for _osx_support: shared OS X support functions. |
---|
3 | n/a | """ |
---|
4 | n/a | |
---|
5 | n/a | import os |
---|
6 | n/a | import platform |
---|
7 | n/a | import stat |
---|
8 | n/a | import sys |
---|
9 | n/a | import unittest |
---|
10 | n/a | |
---|
11 | n/a | import test.support |
---|
12 | n/a | |
---|
13 | n/a | import _osx_support |
---|
14 | n/a | |
---|
15 | n/a | @unittest.skipUnless(sys.platform.startswith("darwin"), "requires OS X") |
---|
16 | n/a | class Test_OSXSupport(unittest.TestCase): |
---|
17 | n/a | |
---|
18 | n/a | def setUp(self): |
---|
19 | n/a | self.maxDiff = None |
---|
20 | n/a | self.prog_name = 'bogus_program_xxxx' |
---|
21 | n/a | self.temp_path_dir = os.path.abspath(os.getcwd()) |
---|
22 | n/a | self.env = test.support.EnvironmentVarGuard() |
---|
23 | n/a | self.addCleanup(self.env.__exit__) |
---|
24 | n/a | for cv in ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', |
---|
25 | n/a | 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC', |
---|
26 | n/a | 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS', |
---|
27 | n/a | 'PY_CORE_CFLAGS'): |
---|
28 | n/a | if cv in self.env: |
---|
29 | n/a | self.env.unset(cv) |
---|
30 | n/a | |
---|
31 | n/a | def add_expected_saved_initial_values(self, config_vars, expected_vars): |
---|
32 | n/a | # Ensure that the initial values for all modified config vars |
---|
33 | n/a | # are also saved with modified keys. |
---|
34 | n/a | expected_vars.update(('_OSX_SUPPORT_INITIAL_'+ k, |
---|
35 | n/a | config_vars[k]) for k in config_vars |
---|
36 | n/a | if config_vars[k] != expected_vars[k]) |
---|
37 | n/a | |
---|
38 | n/a | def test__find_executable(self): |
---|
39 | n/a | if self.env['PATH']: |
---|
40 | n/a | self.env['PATH'] = self.env['PATH'] + ':' |
---|
41 | n/a | self.env['PATH'] = self.env['PATH'] + os.path.abspath(self.temp_path_dir) |
---|
42 | n/a | test.support.unlink(self.prog_name) |
---|
43 | n/a | self.assertIsNone(_osx_support._find_executable(self.prog_name)) |
---|
44 | n/a | self.addCleanup(test.support.unlink, self.prog_name) |
---|
45 | n/a | with open(self.prog_name, 'w') as f: |
---|
46 | n/a | f.write("#!/bin/sh\n/bin/echo OK\n") |
---|
47 | n/a | os.chmod(self.prog_name, stat.S_IRWXU) |
---|
48 | n/a | self.assertEqual(self.prog_name, |
---|
49 | n/a | _osx_support._find_executable(self.prog_name)) |
---|
50 | n/a | |
---|
51 | n/a | def test__read_output(self): |
---|
52 | n/a | if self.env['PATH']: |
---|
53 | n/a | self.env['PATH'] = self.env['PATH'] + ':' |
---|
54 | n/a | self.env['PATH'] = self.env['PATH'] + os.path.abspath(self.temp_path_dir) |
---|
55 | n/a | test.support.unlink(self.prog_name) |
---|
56 | n/a | self.addCleanup(test.support.unlink, self.prog_name) |
---|
57 | n/a | with open(self.prog_name, 'w') as f: |
---|
58 | n/a | f.write("#!/bin/sh\n/bin/echo ExpectedOutput\n") |
---|
59 | n/a | os.chmod(self.prog_name, stat.S_IRWXU) |
---|
60 | n/a | self.assertEqual('ExpectedOutput', |
---|
61 | n/a | _osx_support._read_output(self.prog_name)) |
---|
62 | n/a | |
---|
63 | n/a | def test__find_build_tool(self): |
---|
64 | n/a | out = _osx_support._find_build_tool('cc') |
---|
65 | n/a | self.assertTrue(os.path.isfile(out), |
---|
66 | n/a | 'cc not found - check xcode-select') |
---|
67 | n/a | |
---|
68 | n/a | def test__get_system_version(self): |
---|
69 | n/a | self.assertTrue(platform.mac_ver()[0].startswith( |
---|
70 | n/a | _osx_support._get_system_version())) |
---|
71 | n/a | |
---|
72 | n/a | def test__remove_original_values(self): |
---|
73 | n/a | config_vars = { |
---|
74 | n/a | 'CC': 'gcc-test -pthreads', |
---|
75 | n/a | } |
---|
76 | n/a | expected_vars = { |
---|
77 | n/a | 'CC': 'clang -pthreads', |
---|
78 | n/a | } |
---|
79 | n/a | cv = 'CC' |
---|
80 | n/a | newvalue = 'clang -pthreads' |
---|
81 | n/a | _osx_support._save_modified_value(config_vars, cv, newvalue) |
---|
82 | n/a | self.assertNotEqual(expected_vars, config_vars) |
---|
83 | n/a | _osx_support._remove_original_values(config_vars) |
---|
84 | n/a | self.assertEqual(expected_vars, config_vars) |
---|
85 | n/a | |
---|
86 | n/a | def test__save_modified_value(self): |
---|
87 | n/a | config_vars = { |
---|
88 | n/a | 'CC': 'gcc-test -pthreads', |
---|
89 | n/a | } |
---|
90 | n/a | expected_vars = { |
---|
91 | n/a | 'CC': 'clang -pthreads', |
---|
92 | n/a | } |
---|
93 | n/a | self.add_expected_saved_initial_values(config_vars, expected_vars) |
---|
94 | n/a | cv = 'CC' |
---|
95 | n/a | newvalue = 'clang -pthreads' |
---|
96 | n/a | _osx_support._save_modified_value(config_vars, cv, newvalue) |
---|
97 | n/a | self.assertEqual(expected_vars, config_vars) |
---|
98 | n/a | |
---|
99 | n/a | def test__save_modified_value_unchanged(self): |
---|
100 | n/a | config_vars = { |
---|
101 | n/a | 'CC': 'gcc-test -pthreads', |
---|
102 | n/a | } |
---|
103 | n/a | expected_vars = config_vars.copy() |
---|
104 | n/a | cv = 'CC' |
---|
105 | n/a | newvalue = 'gcc-test -pthreads' |
---|
106 | n/a | _osx_support._save_modified_value(config_vars, cv, newvalue) |
---|
107 | n/a | self.assertEqual(expected_vars, config_vars) |
---|
108 | n/a | |
---|
109 | n/a | def test__supports_universal_builds(self): |
---|
110 | n/a | import platform |
---|
111 | n/a | mac_ver_tuple = tuple(int(i) for i in |
---|
112 | n/a | platform.mac_ver()[0].split('.')[0:2]) |
---|
113 | n/a | self.assertEqual(mac_ver_tuple >= (10, 4), |
---|
114 | n/a | _osx_support._supports_universal_builds()) |
---|
115 | n/a | |
---|
116 | n/a | def test__find_appropriate_compiler(self): |
---|
117 | n/a | compilers = ( |
---|
118 | n/a | ('gcc-test', 'i686-apple-darwin11-llvm-gcc-4.2'), |
---|
119 | n/a | ('clang', 'clang version 3.1'), |
---|
120 | n/a | ) |
---|
121 | n/a | config_vars = { |
---|
122 | n/a | 'CC': 'gcc-test -pthreads', |
---|
123 | n/a | 'CXX': 'cc++-test', |
---|
124 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ', |
---|
125 | n/a | 'LDFLAGS': '-arch ppc -arch i386 -g', |
---|
126 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk', |
---|
127 | n/a | 'BLDSHARED': 'gcc-test -bundle -arch ppc -arch i386 -g', |
---|
128 | n/a | 'LDSHARED': 'gcc-test -bundle -arch ppc -arch i386 ' |
---|
129 | n/a | '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g', |
---|
130 | n/a | } |
---|
131 | n/a | expected_vars = { |
---|
132 | n/a | 'CC': 'clang -pthreads', |
---|
133 | n/a | 'CXX': 'clang++', |
---|
134 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ', |
---|
135 | n/a | 'LDFLAGS': '-arch ppc -arch i386 -g', |
---|
136 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk', |
---|
137 | n/a | 'BLDSHARED': 'clang -bundle -arch ppc -arch i386 -g', |
---|
138 | n/a | 'LDSHARED': 'clang -bundle -arch ppc -arch i386 ' |
---|
139 | n/a | '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g', |
---|
140 | n/a | } |
---|
141 | n/a | self.add_expected_saved_initial_values(config_vars, expected_vars) |
---|
142 | n/a | |
---|
143 | n/a | suffix = (':' + self.env['PATH']) if self.env['PATH'] else '' |
---|
144 | n/a | self.env['PATH'] = os.path.abspath(self.temp_path_dir) + suffix |
---|
145 | n/a | for c_name, c_output in compilers: |
---|
146 | n/a | test.support.unlink(c_name) |
---|
147 | n/a | self.addCleanup(test.support.unlink, c_name) |
---|
148 | n/a | with open(c_name, 'w') as f: |
---|
149 | n/a | f.write("#!/bin/sh\n/bin/echo " + c_output) |
---|
150 | n/a | os.chmod(c_name, stat.S_IRWXU) |
---|
151 | n/a | self.assertEqual(expected_vars, |
---|
152 | n/a | _osx_support._find_appropriate_compiler( |
---|
153 | n/a | config_vars)) |
---|
154 | n/a | |
---|
155 | n/a | def test__remove_universal_flags(self): |
---|
156 | n/a | config_vars = { |
---|
157 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ', |
---|
158 | n/a | 'LDFLAGS': '-arch ppc -arch i386 -g', |
---|
159 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk', |
---|
160 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g', |
---|
161 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 ' |
---|
162 | n/a | '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g', |
---|
163 | n/a | } |
---|
164 | n/a | expected_vars = { |
---|
165 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 ', |
---|
166 | n/a | 'LDFLAGS': ' -g', |
---|
167 | n/a | 'CPPFLAGS': '-I. ', |
---|
168 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -g', |
---|
169 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -g', |
---|
170 | n/a | } |
---|
171 | n/a | self.add_expected_saved_initial_values(config_vars, expected_vars) |
---|
172 | n/a | |
---|
173 | n/a | self.assertEqual(expected_vars, |
---|
174 | n/a | _osx_support._remove_universal_flags( |
---|
175 | n/a | config_vars)) |
---|
176 | n/a | |
---|
177 | n/a | def test__remove_unsupported_archs(self): |
---|
178 | n/a | config_vars = { |
---|
179 | n/a | 'CC': 'clang', |
---|
180 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ', |
---|
181 | n/a | 'LDFLAGS': '-arch ppc -arch i386 -g', |
---|
182 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk', |
---|
183 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g', |
---|
184 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 ' |
---|
185 | n/a | '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g', |
---|
186 | n/a | } |
---|
187 | n/a | expected_vars = { |
---|
188 | n/a | 'CC': 'clang', |
---|
189 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch i386 ', |
---|
190 | n/a | 'LDFLAGS': ' -arch i386 -g', |
---|
191 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk', |
---|
192 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -arch i386 -g', |
---|
193 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -arch i386 ' |
---|
194 | n/a | '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g', |
---|
195 | n/a | } |
---|
196 | n/a | self.add_expected_saved_initial_values(config_vars, expected_vars) |
---|
197 | n/a | |
---|
198 | n/a | suffix = (':' + self.env['PATH']) if self.env['PATH'] else '' |
---|
199 | n/a | self.env['PATH'] = os.path.abspath(self.temp_path_dir) + suffix |
---|
200 | n/a | c_name = 'clang' |
---|
201 | n/a | test.support.unlink(c_name) |
---|
202 | n/a | self.addCleanup(test.support.unlink, c_name) |
---|
203 | n/a | # exit status 255 means no PPC support in this compiler chain |
---|
204 | n/a | with open(c_name, 'w') as f: |
---|
205 | n/a | f.write("#!/bin/sh\nexit 255") |
---|
206 | n/a | os.chmod(c_name, stat.S_IRWXU) |
---|
207 | n/a | self.assertEqual(expected_vars, |
---|
208 | n/a | _osx_support._remove_unsupported_archs( |
---|
209 | n/a | config_vars)) |
---|
210 | n/a | |
---|
211 | n/a | def test__override_all_archs(self): |
---|
212 | n/a | self.env['ARCHFLAGS'] = '-arch x86_64' |
---|
213 | n/a | config_vars = { |
---|
214 | n/a | 'CC': 'clang', |
---|
215 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ', |
---|
216 | n/a | 'LDFLAGS': '-arch ppc -arch i386 -g', |
---|
217 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk', |
---|
218 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g', |
---|
219 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 ' |
---|
220 | n/a | '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g', |
---|
221 | n/a | } |
---|
222 | n/a | expected_vars = { |
---|
223 | n/a | 'CC': 'clang', |
---|
224 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch x86_64', |
---|
225 | n/a | 'LDFLAGS': ' -g -arch x86_64', |
---|
226 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk', |
---|
227 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -g -arch x86_64', |
---|
228 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -isysroot ' |
---|
229 | n/a | '/Developer/SDKs/MacOSX10.4u.sdk -g -arch x86_64', |
---|
230 | n/a | } |
---|
231 | n/a | self.add_expected_saved_initial_values(config_vars, expected_vars) |
---|
232 | n/a | |
---|
233 | n/a | self.assertEqual(expected_vars, |
---|
234 | n/a | _osx_support._override_all_archs( |
---|
235 | n/a | config_vars)) |
---|
236 | n/a | |
---|
237 | n/a | def test__check_for_unavailable_sdk(self): |
---|
238 | n/a | config_vars = { |
---|
239 | n/a | 'CC': 'clang', |
---|
240 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ' |
---|
241 | n/a | '-isysroot /Developer/SDKs/MacOSX10.1.sdk', |
---|
242 | n/a | 'LDFLAGS': '-arch ppc -arch i386 -g', |
---|
243 | n/a | 'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.1.sdk', |
---|
244 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g', |
---|
245 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 ' |
---|
246 | n/a | '-isysroot /Developer/SDKs/MacOSX10.1.sdk -g', |
---|
247 | n/a | } |
---|
248 | n/a | expected_vars = { |
---|
249 | n/a | 'CC': 'clang', |
---|
250 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ' |
---|
251 | n/a | ' ', |
---|
252 | n/a | 'LDFLAGS': '-arch ppc -arch i386 -g', |
---|
253 | n/a | 'CPPFLAGS': '-I. ', |
---|
254 | n/a | 'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g', |
---|
255 | n/a | 'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 ' |
---|
256 | n/a | ' -g', |
---|
257 | n/a | } |
---|
258 | n/a | self.add_expected_saved_initial_values(config_vars, expected_vars) |
---|
259 | n/a | |
---|
260 | n/a | self.assertEqual(expected_vars, |
---|
261 | n/a | _osx_support._check_for_unavailable_sdk( |
---|
262 | n/a | config_vars)) |
---|
263 | n/a | |
---|
264 | n/a | def test_get_platform_osx(self): |
---|
265 | n/a | # Note, get_platform_osx is currently tested more extensively |
---|
266 | n/a | # indirectly by test_sysconfig and test_distutils |
---|
267 | n/a | config_vars = { |
---|
268 | n/a | 'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ' |
---|
269 | n/a | '-isysroot /Developer/SDKs/MacOSX10.1.sdk', |
---|
270 | n/a | 'MACOSX_DEPLOYMENT_TARGET': '10.6', |
---|
271 | n/a | } |
---|
272 | n/a | result = _osx_support.get_platform_osx(config_vars, ' ', ' ', ' ') |
---|
273 | n/a | self.assertEqual(('macosx', '10.6', 'fat'), result) |
---|
274 | n/a | |
---|
275 | n/a | if __name__ == "__main__": |
---|
276 | n/a | unittest.main() |
---|