blob: 106a928e9290ef88e1b85df1ed3abb7b42fbf304 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001#!/usr/bin/env python
2
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
5# found in the LICENSE file.
6
7"""
8Tests things related to ARCHS.
9"""
10
11import TestGyp
12import TestMac
13
14import re
15import subprocess
16import sys
17
18if sys.platform == 'darwin':
19 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
20
21 test.run_gyp('test-no-archs.gyp', chdir='archs')
22 test.build('test-no-archs.gyp', test.ALL, chdir='archs')
23 result_file = test.built_file_path('Test', chdir='archs')
24 test.must_exist(result_file)
25
26 if TestMac.Xcode.Version() >= '0500':
27 expected_type = ['x86_64']
28 else:
29 expected_type = ['i386']
30 TestMac.CheckFileType(test, result_file, expected_type)
31
32 test.run_gyp('test-valid-archs.gyp', chdir='archs')
33 test.build('test-valid-archs.gyp', test.ALL, chdir='archs')
34 result_file = test.built_file_path('Test', chdir='archs')
35 test.must_exist(result_file)
36 TestMac.CheckFileType(test, result_file, ['x86_64'])
37
38 test.run_gyp('test-archs-x86_64.gyp', chdir='archs')
39 test.build('test-archs-x86_64.gyp', test.ALL, chdir='archs')
40 result_file = test.built_file_path('Test64', chdir='archs')
41 test.must_exist(result_file)
42 TestMac.CheckFileType(test, result_file, ['x86_64'])
43
44 test.run_gyp('test-dependencies.gyp', chdir='archs')
45 test.build('test-dependencies.gyp', target=test.ALL, chdir='archs')
46 products = ['c_standalone', 'd_standalone']
47 for product in products:
48 result_file = test.built_file_path(
49 product, chdir='archs', type=test.STATIC_LIB)
50 test.must_exist(result_file)
51
52 if test.format != 'make':
53 # Build all targets except 'exe_32_64_no_sources' that does build
54 # but should not cause error when generating ninja files
55 targets = [
56 'static_32_64', 'shared_32_64', 'shared_32_64_bundle',
57 'module_32_64', 'module_32_64_bundle',
58 'exe_32_64', 'exe_32_64_bundle', 'precompiled_prefix_header_mm_32_64',
59 ]
60
61 test.run_gyp('test-archs-multiarch.gyp', chdir='archs')
62
63 for target in targets:
64 test.build('test-archs-multiarch.gyp', target=target, chdir='archs')
65
66 result_file = test.built_file_path(
67 'static_32_64', chdir='archs', type=test.STATIC_LIB)
68 test.must_exist(result_file)
69 TestMac.CheckFileType(test, result_file, ['i386', 'x86_64'])
70
71 result_file = test.built_file_path(
72 'shared_32_64', chdir='archs', type=test.SHARED_LIB)
73 test.must_exist(result_file)
74 TestMac.CheckFileType(test, result_file, ['i386', 'x86_64'])
75
76 result_file = test.built_file_path('My Framework.framework/My Framework',
77 chdir='archs')
78 test.must_exist(result_file)
79 TestMac.CheckFileType(test, result_file, ['i386', 'x86_64'])
80 # Check that symbol "_x" made it into both versions of the binary:
81 if not all(['D _x' in subprocess.check_output(
82 ['nm', '-arch', arch, result_file]) for arch in ['i386', 'x86_64']]):
83 # This can only flakily fail, due to process ordering issues. If this
84 # does fail flakily, then something's broken, it's not the test at fault.
85 test.fail_test()
86
87 result_file = test.built_file_path(
88 'exe_32_64', chdir='archs', type=test.EXECUTABLE)
89 test.must_exist(result_file)
90 TestMac.CheckFileType(test, result_file, ['i386', 'x86_64'])
91
92 result_file = test.built_file_path('Test App.app/Contents/MacOS/Test App',
93 chdir='archs')
94 test.must_exist(result_file)
95 TestMac.CheckFileType(test, result_file, ['i386', 'x86_64'])