blob: 0f7d2527af44a0d0ede26161934236a251f382f5 [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
borenet2481b8b2015-07-29 11:43:07 -070023import dm_flags
24import nanobench_flags
borenetb76c1f72015-07-29 07:38:49 -070025
26
borenetdbf9f012015-07-30 07:09:20 -070027CONFIG_DEBUG = 'Debug'
28CONFIG_RELEASE = 'Release'
29
30
borenetb76c1f72015-07-29 07:38:49 -070031def lineno():
32 caller = inspect.stack()[1] # Up one level to our caller.
33 return inspect.getframeinfo(caller[0]).lineno
34
35# Since we don't actually start coverage until we're in the self-test,
36# some function def lines aren't reported as covered. Add them to this
37# list so that we can ignore them.
38cov_skip = []
39
40cov_start = lineno()+1 # We care about coverage starting just past this def.
41def gyp_defines(builder_dict):
42 gyp_defs = {}
43
44 # skia_arch_type.
45 if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_BUILD:
46 arch = builder_dict['target_arch']
47 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
48 arch = None
49 else:
50 arch = builder_dict['arch']
51
52 arch_types = {
53 'x86': 'x86',
54 'x86_64': 'x86_64',
55 'Arm7': 'arm',
56 'Arm64': 'arm64',
57 'Mips': 'mips32',
58 'Mips64': 'mips64',
59 'MipsDSP2': 'mips32',
60 }
61 if arch in arch_types:
62 gyp_defs['skia_arch_type'] = arch_types[arch]
63
64 # housekeeper: build shared lib.
65 if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
66 gyp_defs['skia_shared_lib'] = '1'
67
68 # skia_gpu.
69 if builder_dict.get('cpu_or_gpu') == 'CPU':
70 gyp_defs['skia_gpu'] = '0'
71
72 # skia_warnings_as_errors.
73 werr = False
74 if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_BUILD:
75 if 'Win' in builder_dict.get('os', ''):
76 if not ('GDI' in builder_dict.get('extra_config', '') or
77 'Exceptions' in builder_dict.get('extra_config', '')):
78 werr = True
79 elif ('Mac' in builder_dict.get('os', '') and
80 'Android' in builder_dict.get('extra_config', '')):
81 werr = False
82 else:
83 werr = True
84 gyp_defs['skia_warnings_as_errors'] = str(int(werr)) # True/False -> '1'/'0'
85
86 # Win debugger.
87 if 'Win' in builder_dict.get('os', ''):
88 gyp_defs['skia_win_debuggers_path'] = 'c:/DbgHelp'
89
90 # Qt SDK (Win).
91 if 'Win' in builder_dict.get('os', ''):
92 if builder_dict.get('os') == 'Win8':
93 gyp_defs['qt_sdk'] = 'C:/Qt/Qt5.1.0/5.1.0/msvc2012_64/'
94 else:
95 gyp_defs['qt_sdk'] = 'C:/Qt/4.8.5/'
96
97 # ANGLE.
98 if builder_dict.get('extra_config') == 'ANGLE':
99 gyp_defs['skia_angle'] = '1'
borenet08d77472015-09-21 08:20:24 -0700100 if builder_dict.get('os', '') in ('Ubuntu', 'Linux'):
101 gyp_defs['use_x11'] = '1'
102 gyp_defs['chromeos'] = '0'
borenetb76c1f72015-07-29 07:38:49 -0700103
104 # GDI.
105 if builder_dict.get('extra_config') == 'GDI':
106 gyp_defs['skia_gdi'] = '1'
107
108 # Build with Exceptions on Windows.
109 if ('Win' in builder_dict.get('os', '') and
110 builder_dict.get('extra_config') == 'Exceptions'):
111 gyp_defs['skia_win_exceptions'] = '1'
112
113 # iOS.
114 if (builder_dict.get('os') == 'iOS' or
115 builder_dict.get('extra_config') == 'iOS'):
116 gyp_defs['skia_os'] = 'ios'
117
118 # Shared library build.
119 if builder_dict.get('extra_config') == 'Shared':
120 gyp_defs['skia_shared_lib'] = '1'
121
122 # PDF viewer in GM.
123 if (builder_dict.get('os') == 'Mac10.8' and
124 builder_dict.get('arch') == 'x86_64' and
125 builder_dict.get('configuration') == 'Release'):
126 gyp_defs['skia_run_pdfviewer_in_gm'] = '1'
127
128 # Clang.
129 if builder_dict.get('compiler') == 'Clang':
130 gyp_defs['skia_clang_build'] = '1'
131
132 # Valgrind.
133 if 'Valgrind' in builder_dict.get('extra_config', ''):
134 gyp_defs['skia_release_optimization_level'] = '1'
135
136 # Link-time code generation just wastes time on compile-only bots.
137 if (builder_dict.get('role') == builder_name_schema.BUILDER_ROLE_BUILD and
138 builder_dict.get('compiler') == 'MSVC'):
139 gyp_defs['skia_win_ltcg'] = '0'
140
141 # Mesa.
142 if (builder_dict.get('extra_config') == 'Mesa' or
143 builder_dict.get('cpu_or_gpu_value') == 'Mesa'):
144 gyp_defs['skia_mesa'] = '1'
145
borenetb76c1f72015-07-29 07:38:49 -0700146 # skia_use_android_framework_defines.
147 if builder_dict.get('extra_config') == 'Android_FrameworkDefs':
148 gyp_defs['skia_use_android_framework_defines'] = '1'
149
150 return gyp_defs
151
152
153cov_skip.extend([lineno(), lineno() + 1])
154def get_extra_env_vars(builder_dict):
155 env = {}
borenetdbf9f012015-07-30 07:09:20 -0700156 if builder_dict.get('configuration') == 'Coverage':
157 # We have to use Clang 3.6 because earlier versions do not support the
158 # compile flags we use and 3.7 and 3.8 hit asserts during compilation.
159 env['CC'] = '/usr/bin/clang-3.6'
160 env['CXX'] = '/usr/bin/clang++-3.6'
161 elif builder_dict.get('compiler') == 'Clang':
borenetb76c1f72015-07-29 07:38:49 -0700162 env['CC'] = '/usr/bin/clang'
163 env['CXX'] = '/usr/bin/clang++'
borenet98f7e332015-08-24 12:50:59 -0700164
mtkleind0fff5b2015-09-18 06:15:55 -0700165 # SKNX_NO_SIMD, SK_USE_DISCARDABLE_SCALEDIMAGECACHE, etc.
166 extra_config = builder_dict.get('extra_config', '')
167 if extra_config.startswith('SK') and extra_config.isupper():
168 env['CPPFLAGS'] = '-D' + extra_config
169
borenetb76c1f72015-07-29 07:38:49 -0700170 return env
171
172
173cov_skip.extend([lineno(), lineno() + 1])
174def build_targets_from_builder_dict(builder_dict):
175 """Return a list of targets to build, depending on the builder type."""
176 if builder_dict['role'] in ('Test', 'Perf') and builder_dict['os'] == 'iOS':
177 return ['iOSShell']
178 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_TEST:
179 t = ['dm']
180 if builder_dict.get('configuration') == 'Debug':
181 t.append('nanobench')
182 return t
183 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_PERF:
borenet98f7e332015-08-24 12:50:59 -0700184 if builder_dict.get('extra_config') == 'Appurify':
185 return ['VisualBenchTest_APK']
186 else:
187 return ['nanobench']
borenetb76c1f72015-07-29 07:38:49 -0700188 else:
189 return ['most']
190
191
192cov_skip.extend([lineno(), lineno() + 1])
borenet7bccca12015-07-29 11:15:42 -0700193def device_cfg(builder_dict):
194 # Android.
195 if 'Android' in builder_dict.get('extra_config', ''):
196 if 'NoNeon' in builder_dict['extra_config']:
197 return 'arm_v7'
198 return {
199 'Arm64': 'arm64',
200 'x86': 'x86',
201 'x86_64': 'x86_64',
202 'Mips': 'mips',
203 'Mips64': 'mips64',
204 'MipsDSP2': 'mips_dsp2',
205 }.get(builder_dict['target_arch'], 'arm_v7_neon')
206 elif builder_dict.get('os') == 'Android':
207 return {
208 'GalaxyS3': 'arm_v7_neon',
209 'GalaxyS4': 'arm_v7_neon',
210 'Nexus5': 'arm_v7', # This'd be 'nexus_5', but we simulate no-NEON Clank.
211 'Nexus6': 'arm_v7_neon',
212 'Nexus7': 'nexus_7',
213 'Nexus9': 'nexus_9',
214 'Nexus10': 'nexus_10',
215 'NexusPlayer': 'x86',
216 'NVIDIA_Shield': 'arm64',
217 }[builder_dict['model']]
218
219 # ChromeOS.
220 if 'CrOS' in builder_dict.get('extra_config', ''):
221 if 'Link' in builder_dict['extra_config']:
222 return 'link'
223 if 'Daisy' in builder_dict['extra_config']:
224 return 'daisy'
225 elif builder_dict.get('os') == 'ChromeOS':
226 return {
227 'Link': 'link',
228 'Daisy': 'daisy',
229 }[builder_dict['model']]
230
231 return None
232
233
234cov_skip.extend([lineno(), lineno() + 1])
borenetb76c1f72015-07-29 07:38:49 -0700235def get_builder_spec(builder_name):
236 builder_dict = builder_name_schema.DictForBuilderName(builder_name)
237 env = get_extra_env_vars(builder_dict)
238 gyp_defs = gyp_defines(builder_dict)
239 gyp_defs_list = ['%s=%s' % (k, v) for k, v in gyp_defs.iteritems()]
240 gyp_defs_list.sort()
241 env['GYP_DEFINES'] = ' '.join(gyp_defs_list)
borenet7bccca12015-07-29 11:15:42 -0700242 rv = {
borenetb76c1f72015-07-29 07:38:49 -0700243 'build_targets': build_targets_from_builder_dict(builder_dict),
borenet7bccca12015-07-29 11:15:42 -0700244 'builder_cfg': builder_dict,
borenet2481b8b2015-07-29 11:43:07 -0700245 'dm_flags': dm_flags.get_args(builder_name),
borenetb76c1f72015-07-29 07:38:49 -0700246 'env': env,
borenet2481b8b2015-07-29 11:43:07 -0700247 'nanobench_flags': nanobench_flags.get_args(builder_name),
borenetb76c1f72015-07-29 07:38:49 -0700248 }
borenet7bccca12015-07-29 11:15:42 -0700249 device = device_cfg(builder_dict)
250 if device:
251 rv['device_cfg'] = device
borenetdbf9f012015-07-30 07:09:20 -0700252
253 role = builder_dict['role']
254 if role == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
255 configuration = CONFIG_RELEASE
256 else:
257 configuration = builder_dict.get(
258 'configuration', CONFIG_DEBUG)
259 arch = (builder_dict.get('arch') or builder_dict.get('target_arch'))
260 if ('Win' in builder_dict.get('os', '') and arch == 'x86_64'):
261 configuration += '_x64'
262 rv['configuration'] = configuration
263 rv['do_test_steps'] = role == builder_name_schema.BUILDER_ROLE_TEST
264 rv['do_perf_steps'] = (role == builder_name_schema.BUILDER_ROLE_PERF or
265 (role == builder_name_schema.BUILDER_ROLE_TEST and
266 configuration == CONFIG_DEBUG) or
267 'Valgrind' in builder_name)
268
269 # Do we upload perf results?
270 upload_perf_results = False
271 if role == builder_name_schema.BUILDER_ROLE_PERF:
272 upload_perf_results = True
273 rv['upload_perf_results'] = upload_perf_results
274
275 # Do we upload correctness results?
276 skip_upload_bots = [
277 'ASAN',
278 'Coverage',
279 'TSAN',
280 'UBSAN',
281 'Valgrind',
282 ]
283 upload_dm_results = True
284 for s in skip_upload_bots:
285 if s in builder_name:
286 upload_dm_results = False
287 break
288 rv['upload_dm_results'] = upload_dm_results
289
borenet7bccca12015-07-29 11:15:42 -0700290 return rv
borenetb76c1f72015-07-29 07:38:49 -0700291
292
293cov_end = lineno() # Don't care about code coverage past here.
294
295
296def self_test():
297 import coverage # This way the bots don't need coverage.py to be installed.
298 args = {}
299 cases = [
300 'Build-Mac10.8-Clang-Arm7-Debug-Android',
301 'Build-Win-MSVC-x86-Debug',
302 'Build-Win-MSVC-x86-Debug-GDI',
303 'Build-Win-MSVC-x86-Debug-Exceptions',
304 'Build-Ubuntu-GCC-Arm7-Debug-Android_FrameworkDefs',
borenet7bccca12015-07-29 11:15:42 -0700305 'Build-Ubuntu-GCC-Arm7-Debug-Android_NoNeon',
306 'Build-Ubuntu-GCC-Arm7-Debug-CrOS_Daisy',
307 'Build-Ubuntu-GCC-x86_64-Debug-CrOS_Link',
borenetb76c1f72015-07-29 07:38:49 -0700308 'Build-Ubuntu-GCC-x86_64-Release-Mesa',
borenet08d77472015-09-21 08:20:24 -0700309 'Build-Ubuntu-GCC-x86_64-Release-ANGLE',
borenetb76c1f72015-07-29 07:38:49 -0700310 'Housekeeper-PerCommit',
311 'Perf-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Release-Trybot',
borenet98f7e332015-08-24 12:50:59 -0700312 'Perf-Android-GCC-Nexus5-GPU-Adreno330-Arm7-Release-Appurify',
borenet7bccca12015-07-29 11:15:42 -0700313 'Test-Android-GCC-Nexus6-GPU-Adreno420-Arm7-Debug',
314 'Test-ChromeOS-GCC-Link-CPU-AVX-x86_64-Debug',
borenetb76c1f72015-07-29 07:38:49 -0700315 'Test-iOS-Clang-iPad4-GPU-SGX554-Arm7-Debug',
316 'Test-Mac10.8-Clang-MacMini4.1-GPU-GeForce320M-x86_64-Release',
borenet98f7e332015-08-24 12:50:59 -0700317 'Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Coverage',
borenet9063e422015-09-18 06:37:14 -0700318 ('Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-'
319 'SK_USE_DISCARDABLE_SCALEDIMAGECACHE'),
borenetb76c1f72015-07-29 07:38:49 -0700320 'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD',
321 'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-Shared',
322 'Test-Ubuntu-GCC-ShuttleA-GPU-GTX550Ti-x86_64-Release-Valgrind',
323 'Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86-Release-ANGLE',
324 'Test-Win8-MSVC-ShuttleA-CPU-AVX-x86_64-Debug',
325 ]
326
327 cov = coverage.coverage()
328 cov.start()
329 for case in cases:
330 args[case] = get_builder_spec(case)
331 cov.stop()
332
333 this_file = os.path.basename(__file__)
334 _, _, not_run, _ = cov.analysis(this_file)
335 filtered = [line for line in not_run if
336 line > cov_start and line < cov_end and line not in cov_skip]
337 if filtered:
338 print 'Lines not covered by test cases: ', filtered
339 sys.exit(1)
340
341 golden = this_file.replace('.py', '.json')
342 with open(os.path.join(os.path.dirname(__file__), golden), 'w') as f:
343 json.dump(args, f, indent=2, sort_keys=True)
344
345
346if __name__ == '__main__':
347 if len(sys.argv) == 2 and sys.argv[1] == 'test':
348 self_test()
349 sys.exit(0)
350
351 if len(sys.argv) != 3:
352 print usage
353 sys.exit(1)
354
355 with open(sys.argv[1], 'w') as out:
356 json.dump(get_builder_spec(sys.argv[2]), out)