OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 Google Inc. All rights reserved. | 3 # Copyright (c) 2012 Google Inc. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ | 7 """ |
8 Verifies that stripping works. | 8 Verifies that stripping works. |
9 """ | 9 """ |
10 | 10 |
11 import TestGyp | 11 import TestGyp |
| 12 import TestMac |
12 | 13 |
13 import re | 14 import re |
14 import subprocess | 15 import subprocess |
15 import sys | 16 import sys |
16 import time | 17 import time |
17 | 18 |
18 if sys.platform == 'darwin': | 19 if sys.platform == 'darwin': |
19 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) | 20 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) |
20 | 21 |
21 test.run_gyp('test.gyp', chdir='strip') | 22 test.run_gyp('test.gyp', chdir='strip') |
22 | 23 |
23 test.build('test.gyp', test.ALL, chdir='strip') | 24 test.build('test.gyp', test.ALL, chdir='strip') |
24 | 25 |
25 # Lightweight check if stripping was done. | 26 # Lightweight check if stripping was done. |
26 def OutPath(s): | 27 def OutPath(s): |
27 return test.built_file_path(s, type=test.SHARED_LIB, chdir='strip') | 28 return test.built_file_path(s, type=test.SHARED_LIB, chdir='strip') |
28 | 29 |
29 def CheckNsyms(p, n_expected): | 30 def CheckNsyms(p, n_expected): |
30 r = re.compile(r'nsyms\s+(\d+)') | 31 r = re.compile(r'nsyms\s+(\d+)') |
31 proc = subprocess.Popen(['otool', '-l', p], stdout=subprocess.PIPE) | 32 o = subprocess.check_output(['otool', '-l', p]) |
32 o = proc.communicate()[0] | |
33 assert not proc.returncode | |
34 m = r.search(o) | 33 m = r.search(o) |
35 n = int(m.group(1)) | 34 n = int(m.group(1)) |
36 if n != n_expected: | 35 if n != n_expected: |
37 print 'Stripping: Expected %d symbols, got %d' % (n_expected, n) | 36 print 'Stripping: Expected %d symbols, got %d' % (n_expected, n) |
38 test.fail_test() | 37 test.fail_test() |
39 | 38 |
| 39 # Starting with Xcode 5.0, clang adds an additional symbols to the compiled |
| 40 # file when using a relative path to the input file. So when using ninja |
| 41 # with Xcode 5.0 or higher, take this additional symbol into consideration |
| 42 # for unstripped builds (it is stripped by all strip commands). |
| 43 expected_extra_symbol_count = 0 |
| 44 if test.format == 'ninja' and TestMac.Xcode.Version() >= '0500': |
| 45 expected_extra_symbol_count = 1 |
| 46 |
40 # The actual numbers here are not interesting, they just need to be the same | 47 # The actual numbers here are not interesting, they just need to be the same |
41 # in both the xcode and the make build. | 48 # in both the xcode and the make build. |
42 CheckNsyms(OutPath('no_postprocess'), 29) | 49 CheckNsyms(OutPath('no_postprocess'), 29 + expected_extra_symbol_count) |
43 CheckNsyms(OutPath('no_strip'), 29) | 50 CheckNsyms(OutPath('no_strip'), 29 + expected_extra_symbol_count) |
44 CheckNsyms(OutPath('strip_all'), 0) | 51 CheckNsyms(OutPath('strip_all'), 0) |
45 CheckNsyms(OutPath('strip_nonglobal'), 6) | 52 CheckNsyms(OutPath('strip_nonglobal'), 6) |
46 CheckNsyms(OutPath('strip_debugging'), 7) | 53 CheckNsyms(OutPath('strip_debugging'), 7) |
47 CheckNsyms(OutPath('strip_all_custom_flags'), 0) | 54 CheckNsyms(OutPath('strip_all_custom_flags'), 0) |
48 CheckNsyms(test.built_file_path( | 55 CheckNsyms(test.built_file_path( |
49 'strip_all_bundle.framework/Versions/A/strip_all_bundle', chdir='strip'), | 56 'strip_all_bundle.framework/Versions/A/strip_all_bundle', chdir='strip'), |
50 0) | 57 0) |
51 CheckNsyms(OutPath('strip_save'), 7) | 58 CheckNsyms(OutPath('strip_save'), 7) |
52 | 59 |
53 test.pass_test() | 60 test.pass_test() |
OLD | NEW |