OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2013 Google Inc. All rights reserved. | 3 # Copyright (c) 2013 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 device and simulator bundles are built correctly. | 8 Verifies that device and simulator bundles are built correctly. |
9 """ | 9 """ |
10 | 10 |
11 import plistlib | 11 import plistlib |
12 import TestGyp | 12 import TestGyp |
13 import os | 13 import os |
| 14 import re |
14 import struct | 15 import struct |
15 import subprocess | 16 import subprocess |
16 import sys | 17 import sys |
17 import tempfile | 18 import tempfile |
18 | 19 |
19 | 20 |
20 def CheckFileType(file, expected): | 21 def BuildExpected(file, archs): |
| 22 if len(archs) == 1: |
| 23 return 'Non-fat file: %s is architecture: %s' % (file, archs[0]) |
| 24 return 'Architectures in the fat file: %s are: %s' % (file, ' '.join(archs)) |
| 25 |
| 26 |
| 27 def CheckFileType(test, file, archs): |
21 proc = subprocess.Popen(['lipo', '-info', file], stdout=subprocess.PIPE) | 28 proc = subprocess.Popen(['lipo', '-info', file], stdout=subprocess.PIPE) |
22 o = proc.communicate()[0].strip() | 29 o = proc.communicate()[0].strip() |
23 assert not proc.returncode | 30 assert not proc.returncode |
24 if not expected in o: | 31 if len(archs) == 1: |
25 print 'File: Expected %s, got %s' % (expected, o) | 32 pattern = re.compile('^Non-fat file: (.*) is architecture: (.*)$') |
| 33 else: |
| 34 pattern = re.compile('^Architectures in the fat file: (.*) are: (.*)$') |
| 35 match = pattern.match(o) |
| 36 if match is None: |
| 37 print 'Ouput does not match expected pattern: %s' % (pattern.pattern) |
26 test.fail_test() | 38 test.fail_test() |
| 39 else: |
| 40 found_file, found_archs = match.groups() |
| 41 if found_file != file or set(found_archs.split()) != set(archs): |
| 42 print 'Expected file %s with arch %s, got %s with arch %s' % ( |
| 43 file, ' '.join(archs), found_file, ' '.join(found_archs)) |
| 44 test.fail_test() |
27 | 45 |
28 | 46 |
29 def XcodeVersion(): | 47 def XcodeVersion(): |
30 xcode, build = GetStdout(['xcodebuild', '-version']).splitlines() | 48 xcode, build = GetStdout(['xcodebuild', '-version']).splitlines() |
31 xcode = xcode.split()[-1].replace('.', '') | 49 xcode = xcode.split()[-1].replace('.', '') |
32 xcode = (xcode + '0' * (3 - len(xcode))).zfill(4) | 50 xcode = (xcode + '0' * (3 - len(xcode))).zfill(4) |
33 return xcode | 51 return xcode |
34 | 52 |
35 | 53 |
36 def GetStdout(cmdlist): | 54 def GetStdout(cmdlist): |
37 proc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE) | 55 proc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE) |
38 o = proc.communicate()[0].strip() | 56 o = proc.communicate()[0].strip() |
39 assert not proc.returncode | 57 assert not proc.returncode |
40 return o | 58 return o |
41 | 59 |
42 | 60 |
43 if sys.platform == 'darwin': | 61 if sys.platform == 'darwin': |
44 test = TestGyp.TestGyp() | 62 test = TestGyp.TestGyp() |
| 63 if test.format == 'ninja' or test.format == 'xcode': |
| 64 test_cases = [ |
| 65 ('Default', 'Test No Archs', ['i386']), |
| 66 ('Default', 'Test Arch 32-bits', ['i386']), |
| 67 ('Default', 'Test Arch 64-bits', ['x86_64']), |
| 68 ('Default', 'Test Multi Archs', ['i386', 'x86_64']), |
| 69 ('Default-iphoneos', 'Test No Archs', ['armv7']), |
| 70 ('Default-iphoneos', 'Test Arch 32-bits', ['armv7']), |
| 71 ('Default-iphoneos', 'Test Arch 64-bits', ['arm64']), |
| 72 ('Default-iphoneos', 'Test Multi Archs', ['armv7', 'arm64']), |
| 73 ] |
45 | 74 |
46 test.run_gyp('test-archs.gyp', chdir='app-bundle') | 75 xcode_version = XcodeVersion() |
47 test.set_configuration('Default') | 76 test.run_gyp('test-archs.gyp', chdir='app-bundle') |
| 77 for configuration, name, archs in test_cases: |
| 78 is_64_bit_build = ('arm64' in archs or 'x86_64' in archs) |
| 79 is_device_build = configuration.endswith('-iphoneos') |
48 | 80 |
49 # TODO(sdefresne): add 'Test Archs x86_64' once bots have been updated to | 81 # TODO(sdefresne): remove this test once the bots have been updated to |
50 # a SDK version that supports "x86_64" architecture. | 82 # a SDK version that supports 64-bit architectures. |
51 filenames = ['Test No Archs', 'Test Archs i386'] | 83 if xcode_version < '0500' and is_64_bit_build: |
52 if XcodeVersion() >= '0500': | 84 continue |
53 filenames.append('Test Archs x86_64') | |
54 | 85 |
55 for filename in filenames: | 86 kwds = {} |
56 target = filename.replace(' ', '_').lower() | 87 if test.format == 'xcode' and is_device_build: |
57 test.build('test-archs.gyp', target, chdir='app-bundle') | 88 configuration, sdk = configuration.split('-') |
58 result_file = test.built_file_path( | 89 kwds['arguments'] = ['-sdk', sdk] |
59 '%s.bundle/%s' % (filename, filename), chdir='app-bundle') | |
60 test.must_exist(result_file) | |
61 | 90 |
62 expected = 'i386' | 91 test.set_configuration(configuration) |
63 if 'x86_64' in filename: | 92 product = name.replace(' ', '') |
64 expected = 'x86_64' | 93 filename = '%s.bundle/%s' % (product, product) |
65 CheckFileType(result_file, expected) | 94 target = name.replace(' ', '_').replace('-', '_').lower() |
| 95 test.build('test-archs.gyp', target, chdir='app-bundle', **kwds) |
| 96 result_file = test.built_file_path(filename, chdir='app-bundle') |
66 | 97 |
67 test.pass_test() | 98 test.must_exist(result_file) |
| 99 CheckFileType(test, result_file, archs) |
| 100 |
| 101 test.pass_test() |
OLD | NEW |