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 Tests things related to ARCHS. | 8 Tests things related to ARCHS. |
9 """ | 9 """ |
10 | 10 |
11 import TestGyp | 11 import TestGyp |
12 | 12 |
13 import re | 13 import re |
14 import subprocess | 14 import subprocess |
15 import sys | 15 import sys |
16 | 16 |
17 if sys.platform == 'darwin': | 17 if sys.platform == 'darwin': |
18 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) | 18 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) |
19 | 19 |
20 def CheckFileType(file, expected): | 20 def GetStdout(cmdlist): |
21 proc = subprocess.Popen(['file', '-b', file], stdout=subprocess.PIPE) | 21 proc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE) |
22 o = proc.communicate()[0].strip() | 22 o = proc.communicate()[0].strip() |
23 assert not proc.returncode | 23 assert not proc.returncode |
| 24 return o |
| 25 |
| 26 def CheckFileType(file, expected): |
| 27 o = GetStdout(['file', '-b', file]) |
24 if not re.match(expected, o, re.DOTALL): | 28 if not re.match(expected, o, re.DOTALL): |
25 print 'File: Expected %s, got %s' % (expected, o) | 29 print 'File: Expected %s, got %s' % (expected, o) |
26 test.fail_test() | 30 test.fail_test() |
27 | 31 |
| 32 def XcodeVersion(): |
| 33 xcode, build = GetStdout(['xcodebuild', '-version']).splitlines() |
| 34 xcode = xcode.split()[-1].replace('.', '') |
| 35 xcode = (xcode + '0' * (3 - len(xcode))).zfill(4) |
| 36 return xcode |
| 37 |
28 test.run_gyp('test-no-archs.gyp', chdir='archs') | 38 test.run_gyp('test-no-archs.gyp', chdir='archs') |
29 test.build('test-no-archs.gyp', test.ALL, chdir='archs') | 39 test.build('test-no-archs.gyp', test.ALL, chdir='archs') |
30 result_file = test.built_file_path('Test', chdir='archs') | 40 result_file = test.built_file_path('Test', chdir='archs') |
31 test.must_exist(result_file) | 41 test.must_exist(result_file) |
32 # FIXME: The default setting changed from i386 to x86_64 in Xcode 5. | 42 |
33 #CheckFileType(result_file, '^Mach-O executable i386') | 43 if XcodeVersion() >= '0500': |
| 44 expected_type = '^Mach-O 64-bit executable x86_64$' |
| 45 else: |
| 46 expected_type = '^Mach-O executable i386$' |
| 47 CheckFileType(result_file, expected_type) |
34 | 48 |
35 test.run_gyp('test-archs-x86_64.gyp', chdir='archs') | 49 test.run_gyp('test-archs-x86_64.gyp', chdir='archs') |
36 test.build('test-archs-x86_64.gyp', test.ALL, chdir='archs') | 50 test.build('test-archs-x86_64.gyp', test.ALL, chdir='archs') |
37 result_file = test.built_file_path('Test64', chdir='archs') | 51 result_file = test.built_file_path('Test64', chdir='archs') |
38 test.must_exist(result_file) | 52 test.must_exist(result_file) |
39 CheckFileType(result_file, '^Mach-O 64-bit executable x86_64$') | 53 CheckFileType(result_file, '^Mach-O 64-bit executable x86_64$') |
40 | 54 |
41 if test.format != 'make': | 55 if test.format != 'make': |
42 test.run_gyp('test-archs-multiarch.gyp', chdir='archs') | 56 test.run_gyp('test-archs-multiarch.gyp', chdir='archs') |
43 test.build('test-archs-multiarch.gyp', test.ALL, chdir='archs') | 57 test.build('test-archs-multiarch.gyp', test.ALL, chdir='archs') |
(...skipping 14 matching lines...) Expand all Loading... |
58 'exe_32_64', chdir='archs', type=test.EXECUTABLE) | 72 'exe_32_64', chdir='archs', type=test.EXECUTABLE) |
59 test.must_exist(result_file) | 73 test.must_exist(result_file) |
60 CheckFileType(result_file, 'Mach-O universal binary with 2 architectures' | 74 CheckFileType(result_file, 'Mach-O universal binary with 2 architectures' |
61 '.*architecture i386.*architecture x86_64') | 75 '.*architecture i386.*architecture x86_64') |
62 | 76 |
63 result_file = test.built_file_path('Test App.app/Contents/MacOS/Test App', | 77 result_file = test.built_file_path('Test App.app/Contents/MacOS/Test App', |
64 chdir='archs') | 78 chdir='archs') |
65 test.must_exist(result_file) | 79 test.must_exist(result_file) |
66 CheckFileType(result_file, 'Mach-O universal binary with 2 architectures' | 80 CheckFileType(result_file, 'Mach-O universal binary with 2 architectures' |
67 '.*architecture i386.*architecture x86_64') | 81 '.*architecture i386.*architecture x86_64') |
OLD | NEW |