blob: 7e5658f6bb0a139ee70821c65223bff3a0de9958 [file] [log] [blame]
borenetb76c1f72015-07-29 07:38:49 -07001#
2# Copyright 2015 Google Inc.
3#
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7
8#!/usr/bin/env python
9
10usage = '''
11Write buildbot spec to outfile based on the bot name:
12 $ python buildbot_spec.py outfile Test-Ubuntu-GCC-GCE-CPU-AVX2-x86-Debug
13Or run self-tests:
14 $ python buildbot_spec.py test
15'''
16
17import inspect
18import json
19import os
20import sys
21
22import builder_name_schema
23
24
25def lineno():
26 caller = inspect.stack()[1] # Up one level to our caller.
27 return inspect.getframeinfo(caller[0]).lineno
28
29# Since we don't actually start coverage until we're in the self-test,
30# some function def lines aren't reported as covered. Add them to this
31# list so that we can ignore them.
32cov_skip = []
33
34cov_start = lineno()+1 # We care about coverage starting just past this def.
35def gyp_defines(builder_dict):
36 gyp_defs = {}
37
38 # skia_arch_type.
39 if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_BUILD:
40 arch = builder_dict['target_arch']
41 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
42 arch = None
43 else:
44 arch = builder_dict['arch']
45
46 arch_types = {
47 'x86': 'x86',
48 'x86_64': 'x86_64',
49 'Arm7': 'arm',
50 'Arm64': 'arm64',
51 'Mips': 'mips32',
52 'Mips64': 'mips64',
53 'MipsDSP2': 'mips32',
54 }
55 if arch in arch_types:
56 gyp_defs['skia_arch_type'] = arch_types[arch]
57
58 # housekeeper: build shared lib.
59 if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
60 gyp_defs['skia_shared_lib'] = '1'
61
62 # skia_gpu.
63 if builder_dict.get('cpu_or_gpu') == 'CPU':
64 gyp_defs['skia_gpu'] = '0'
65
66 # skia_warnings_as_errors.
67 werr = False
68 if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_BUILD:
69 if 'Win' in builder_dict.get('os', ''):
70 if not ('GDI' in builder_dict.get('extra_config', '') or
71 'Exceptions' in builder_dict.get('extra_config', '')):
72 werr = True
73 elif ('Mac' in builder_dict.get('os', '') and
74 'Android' in builder_dict.get('extra_config', '')):
75 werr = False
76 else:
77 werr = True
78 gyp_defs['skia_warnings_as_errors'] = str(int(werr)) # True/False -> '1'/'0'
79
80 # Win debugger.
81 if 'Win' in builder_dict.get('os', ''):
82 gyp_defs['skia_win_debuggers_path'] = 'c:/DbgHelp'
83
84 # Qt SDK (Win).
85 if 'Win' in builder_dict.get('os', ''):
86 if builder_dict.get('os') == 'Win8':
87 gyp_defs['qt_sdk'] = 'C:/Qt/Qt5.1.0/5.1.0/msvc2012_64/'
88 else:
89 gyp_defs['qt_sdk'] = 'C:/Qt/4.8.5/'
90
91 # ANGLE.
92 if builder_dict.get('extra_config') == 'ANGLE':
93 gyp_defs['skia_angle'] = '1'
94
95 # GDI.
96 if builder_dict.get('extra_config') == 'GDI':
97 gyp_defs['skia_gdi'] = '1'
98
99 # Build with Exceptions on Windows.
100 if ('Win' in builder_dict.get('os', '') and
101 builder_dict.get('extra_config') == 'Exceptions'):
102 gyp_defs['skia_win_exceptions'] = '1'
103
104 # iOS.
105 if (builder_dict.get('os') == 'iOS' or
106 builder_dict.get('extra_config') == 'iOS'):
107 gyp_defs['skia_os'] = 'ios'
108
109 # Shared library build.
110 if builder_dict.get('extra_config') == 'Shared':
111 gyp_defs['skia_shared_lib'] = '1'
112
113 # PDF viewer in GM.
114 if (builder_dict.get('os') == 'Mac10.8' and
115 builder_dict.get('arch') == 'x86_64' and
116 builder_dict.get('configuration') == 'Release'):
117 gyp_defs['skia_run_pdfviewer_in_gm'] = '1'
118
119 # Clang.
120 if builder_dict.get('compiler') == 'Clang':
121 gyp_defs['skia_clang_build'] = '1'
122
123 # Valgrind.
124 if 'Valgrind' in builder_dict.get('extra_config', ''):
125 gyp_defs['skia_release_optimization_level'] = '1'
126
127 # Link-time code generation just wastes time on compile-only bots.
128 if (builder_dict.get('role') == builder_name_schema.BUILDER_ROLE_BUILD and
129 builder_dict.get('compiler') == 'MSVC'):
130 gyp_defs['skia_win_ltcg'] = '0'
131
132 # Mesa.
133 if (builder_dict.get('extra_config') == 'Mesa' or
134 builder_dict.get('cpu_or_gpu_value') == 'Mesa'):
135 gyp_defs['skia_mesa'] = '1'
136
137 # SKNX_NO_SIMD
138 if builder_dict.get('extra_config') == 'SKNX_NO_SIMD':
139 gyp_defs['sknx_no_simd'] = '1'
140
141 # skia_use_android_framework_defines.
142 if builder_dict.get('extra_config') == 'Android_FrameworkDefs':
143 gyp_defs['skia_use_android_framework_defines'] = '1'
144
145 return gyp_defs
146
147
148cov_skip.extend([lineno(), lineno() + 1])
149def get_extra_env_vars(builder_dict):
150 env = {}
151 if builder_dict.get('compiler') == 'Clang':
152 env['CC'] = '/usr/bin/clang'
153 env['CXX'] = '/usr/bin/clang++'
154 return env
155
156
157cov_skip.extend([lineno(), lineno() + 1])
158def build_targets_from_builder_dict(builder_dict):
159 """Return a list of targets to build, depending on the builder type."""
160 if builder_dict['role'] in ('Test', 'Perf') and builder_dict['os'] == 'iOS':
161 return ['iOSShell']
162 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_TEST:
163 t = ['dm']
164 if builder_dict.get('configuration') == 'Debug':
165 t.append('nanobench')
166 return t
167 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_PERF:
168 return ['nanobench']
169 else:
170 return ['most']
171
172
173cov_skip.extend([lineno(), lineno() + 1])
borenet7bccca12015-07-29 11:15:42 -0700174def device_cfg(builder_dict):
175 # Android.
176 if 'Android' in builder_dict.get('extra_config', ''):
177 if 'NoNeon' in builder_dict['extra_config']:
178 return 'arm_v7'
179 return {
180 'Arm64': 'arm64',
181 'x86': 'x86',
182 'x86_64': 'x86_64',
183 'Mips': 'mips',
184 'Mips64': 'mips64',
185 'MipsDSP2': 'mips_dsp2',
186 }.get(builder_dict['target_arch'], 'arm_v7_neon')
187 elif builder_dict.get('os') == 'Android':
188 return {
189 'GalaxyS3': 'arm_v7_neon',
190 'GalaxyS4': 'arm_v7_neon',
191 'Nexus5': 'arm_v7', # This'd be 'nexus_5', but we simulate no-NEON Clank.
192 'Nexus6': 'arm_v7_neon',
193 'Nexus7': 'nexus_7',
194 'Nexus9': 'nexus_9',
195 'Nexus10': 'nexus_10',
196 'NexusPlayer': 'x86',
197 'NVIDIA_Shield': 'arm64',
198 }[builder_dict['model']]
199
200 # ChromeOS.
201 if 'CrOS' in builder_dict.get('extra_config', ''):
202 if 'Link' in builder_dict['extra_config']:
203 return 'link'
204 if 'Daisy' in builder_dict['extra_config']:
205 return 'daisy'
206 elif builder_dict.get('os') == 'ChromeOS':
207 return {
208 'Link': 'link',
209 'Daisy': 'daisy',
210 }[builder_dict['model']]
211
212 return None
213
214
215cov_skip.extend([lineno(), lineno() + 1])
borenetb76c1f72015-07-29 07:38:49 -0700216def get_builder_spec(builder_name):
217 builder_dict = builder_name_schema.DictForBuilderName(builder_name)
218 env = get_extra_env_vars(builder_dict)
219 gyp_defs = gyp_defines(builder_dict)
220 gyp_defs_list = ['%s=%s' % (k, v) for k, v in gyp_defs.iteritems()]
221 gyp_defs_list.sort()
222 env['GYP_DEFINES'] = ' '.join(gyp_defs_list)
borenet7bccca12015-07-29 11:15:42 -0700223 rv = {
borenetb76c1f72015-07-29 07:38:49 -0700224 'build_targets': build_targets_from_builder_dict(builder_dict),
borenet7bccca12015-07-29 11:15:42 -0700225 'builder_cfg': builder_dict,
borenetb76c1f72015-07-29 07:38:49 -0700226 'env': env,
227 }
borenet7bccca12015-07-29 11:15:42 -0700228 device = device_cfg(builder_dict)
229 if device:
230 rv['device_cfg'] = device
231 return rv
borenetb76c1f72015-07-29 07:38:49 -0700232
233
234cov_end = lineno() # Don't care about code coverage past here.
235
236
237def self_test():
238 import coverage # This way the bots don't need coverage.py to be installed.
239 args = {}
240 cases = [
241 'Build-Mac10.8-Clang-Arm7-Debug-Android',
242 'Build-Win-MSVC-x86-Debug',
243 'Build-Win-MSVC-x86-Debug-GDI',
244 'Build-Win-MSVC-x86-Debug-Exceptions',
245 'Build-Ubuntu-GCC-Arm7-Debug-Android_FrameworkDefs',
borenet7bccca12015-07-29 11:15:42 -0700246 'Build-Ubuntu-GCC-Arm7-Debug-Android_NoNeon',
247 'Build-Ubuntu-GCC-Arm7-Debug-CrOS_Daisy',
248 'Build-Ubuntu-GCC-x86_64-Debug-CrOS_Link',
borenetb76c1f72015-07-29 07:38:49 -0700249 'Build-Ubuntu-GCC-x86_64-Release-Mesa',
250 'Housekeeper-PerCommit',
251 'Perf-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Release-Trybot',
borenet7bccca12015-07-29 11:15:42 -0700252 'Test-Android-GCC-Nexus6-GPU-Adreno420-Arm7-Debug',
253 'Test-ChromeOS-GCC-Link-CPU-AVX-x86_64-Debug',
borenetb76c1f72015-07-29 07:38:49 -0700254 'Test-iOS-Clang-iPad4-GPU-SGX554-Arm7-Debug',
255 'Test-Mac10.8-Clang-MacMini4.1-GPU-GeForce320M-x86_64-Release',
256 'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD',
257 'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-Shared',
258 'Test-Ubuntu-GCC-ShuttleA-GPU-GTX550Ti-x86_64-Release-Valgrind',
259 'Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86-Release-ANGLE',
260 'Test-Win8-MSVC-ShuttleA-CPU-AVX-x86_64-Debug',
261 ]
262
263 cov = coverage.coverage()
264 cov.start()
265 for case in cases:
266 args[case] = get_builder_spec(case)
267 cov.stop()
268
269 this_file = os.path.basename(__file__)
270 _, _, not_run, _ = cov.analysis(this_file)
271 filtered = [line for line in not_run if
272 line > cov_start and line < cov_end and line not in cov_skip]
273 if filtered:
274 print 'Lines not covered by test cases: ', filtered
275 sys.exit(1)
276
277 golden = this_file.replace('.py', '.json')
278 with open(os.path.join(os.path.dirname(__file__), golden), 'w') as f:
279 json.dump(args, f, indent=2, sort_keys=True)
280
281
282if __name__ == '__main__':
283 if len(sys.argv) == 2 and sys.argv[1] == 'test':
284 self_test()
285 sys.exit(0)
286
287 if len(sys.argv) != 3:
288 print usage
289 sys.exit(1)
290
291 with open(sys.argv[1], 'w') as out:
292 json.dump(get_builder_spec(sys.argv[2]), out)