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