blob: f360a38778a92732a025c94b97dd790894a0fcdd [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'
100
101 # GDI.
102 if builder_dict.get('extra_config') == 'GDI':
103 gyp_defs['skia_gdi'] = '1'
104
105 # Build with Exceptions on Windows.
106 if ('Win' in builder_dict.get('os', '') and
107 builder_dict.get('extra_config') == 'Exceptions'):
108 gyp_defs['skia_win_exceptions'] = '1'
109
110 # iOS.
111 if (builder_dict.get('os') == 'iOS' or
112 builder_dict.get('extra_config') == 'iOS'):
113 gyp_defs['skia_os'] = 'ios'
114
115 # Shared library build.
116 if builder_dict.get('extra_config') == 'Shared':
117 gyp_defs['skia_shared_lib'] = '1'
118
119 # PDF viewer in GM.
120 if (builder_dict.get('os') == 'Mac10.8' and
121 builder_dict.get('arch') == 'x86_64' and
122 builder_dict.get('configuration') == 'Release'):
123 gyp_defs['skia_run_pdfviewer_in_gm'] = '1'
124
125 # Clang.
126 if builder_dict.get('compiler') == 'Clang':
127 gyp_defs['skia_clang_build'] = '1'
128
129 # Valgrind.
130 if 'Valgrind' in builder_dict.get('extra_config', ''):
131 gyp_defs['skia_release_optimization_level'] = '1'
132
133 # Link-time code generation just wastes time on compile-only bots.
134 if (builder_dict.get('role') == builder_name_schema.BUILDER_ROLE_BUILD and
135 builder_dict.get('compiler') == 'MSVC'):
136 gyp_defs['skia_win_ltcg'] = '0'
137
138 # Mesa.
139 if (builder_dict.get('extra_config') == 'Mesa' or
140 builder_dict.get('cpu_or_gpu_value') == 'Mesa'):
141 gyp_defs['skia_mesa'] = '1'
142
borenetb76c1f72015-07-29 07:38:49 -0700143 # skia_use_android_framework_defines.
144 if builder_dict.get('extra_config') == 'Android_FrameworkDefs':
145 gyp_defs['skia_use_android_framework_defines'] = '1'
146
147 return gyp_defs
148
149
150cov_skip.extend([lineno(), lineno() + 1])
151def get_extra_env_vars(builder_dict):
152 env = {}
borenetdbf9f012015-07-30 07:09:20 -0700153 if builder_dict.get('configuration') == 'Coverage':
154 # We have to use Clang 3.6 because earlier versions do not support the
155 # compile flags we use and 3.7 and 3.8 hit asserts during compilation.
156 env['CC'] = '/usr/bin/clang-3.6'
157 env['CXX'] = '/usr/bin/clang++-3.6'
158 elif builder_dict.get('compiler') == 'Clang':
borenetb76c1f72015-07-29 07:38:49 -0700159 env['CC'] = '/usr/bin/clang'
160 env['CXX'] = '/usr/bin/clang++'
borenet98f7e332015-08-24 12:50:59 -0700161
mtkleind0fff5b2015-09-18 06:15:55 -0700162 # SKNX_NO_SIMD, SK_USE_DISCARDABLE_SCALEDIMAGECACHE, etc.
163 extra_config = builder_dict.get('extra_config', '')
164 if extra_config.startswith('SK') and extra_config.isupper():
165 env['CPPFLAGS'] = '-D' + extra_config
166
borenetb76c1f72015-07-29 07:38:49 -0700167 return env
168
169
170cov_skip.extend([lineno(), lineno() + 1])
171def build_targets_from_builder_dict(builder_dict):
172 """Return a list of targets to build, depending on the builder type."""
173 if builder_dict['role'] in ('Test', 'Perf') and builder_dict['os'] == 'iOS':
174 return ['iOSShell']
175 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_TEST:
176 t = ['dm']
177 if builder_dict.get('configuration') == 'Debug':
178 t.append('nanobench')
179 return t
180 elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_PERF:
borenet98f7e332015-08-24 12:50:59 -0700181 if builder_dict.get('extra_config') == 'Appurify':
182 return ['VisualBenchTest_APK']
183 else:
184 return ['nanobench']
borenetb76c1f72015-07-29 07:38:49 -0700185 else:
186 return ['most']
187
188
189cov_skip.extend([lineno(), lineno() + 1])
borenet7bccca12015-07-29 11:15:42 -0700190def device_cfg(builder_dict):
191 # Android.
192 if 'Android' in builder_dict.get('extra_config', ''):
193 if 'NoNeon' in builder_dict['extra_config']:
194 return 'arm_v7'
195 return {
196 'Arm64': 'arm64',
197 'x86': 'x86',
198 'x86_64': 'x86_64',
199 'Mips': 'mips',
200 'Mips64': 'mips64',
201 'MipsDSP2': 'mips_dsp2',
202 }.get(builder_dict['target_arch'], 'arm_v7_neon')
203 elif builder_dict.get('os') == 'Android':
204 return {
205 'GalaxyS3': 'arm_v7_neon',
206 'GalaxyS4': 'arm_v7_neon',
207 'Nexus5': 'arm_v7', # This'd be 'nexus_5', but we simulate no-NEON Clank.
208 'Nexus6': 'arm_v7_neon',
209 'Nexus7': 'nexus_7',
210 'Nexus9': 'nexus_9',
211 'Nexus10': 'nexus_10',
212 'NexusPlayer': 'x86',
213 'NVIDIA_Shield': 'arm64',
214 }[builder_dict['model']]
215
216 # ChromeOS.
217 if 'CrOS' in builder_dict.get('extra_config', ''):
218 if 'Link' in builder_dict['extra_config']:
219 return 'link'
220 if 'Daisy' in builder_dict['extra_config']:
221 return 'daisy'
222 elif builder_dict.get('os') == 'ChromeOS':
223 return {
224 'Link': 'link',
225 'Daisy': 'daisy',
226 }[builder_dict['model']]
227
228 return None
229
230
231cov_skip.extend([lineno(), lineno() + 1])
borenetb76c1f72015-07-29 07:38:49 -0700232def get_builder_spec(builder_name):
233 builder_dict = builder_name_schema.DictForBuilderName(builder_name)
234 env = get_extra_env_vars(builder_dict)
235 gyp_defs = gyp_defines(builder_dict)
236 gyp_defs_list = ['%s=%s' % (k, v) for k, v in gyp_defs.iteritems()]
237 gyp_defs_list.sort()
238 env['GYP_DEFINES'] = ' '.join(gyp_defs_list)
borenet7bccca12015-07-29 11:15:42 -0700239 rv = {
borenetb76c1f72015-07-29 07:38:49 -0700240 'build_targets': build_targets_from_builder_dict(builder_dict),
borenet7bccca12015-07-29 11:15:42 -0700241 'builder_cfg': builder_dict,
borenet2481b8b2015-07-29 11:43:07 -0700242 'dm_flags': dm_flags.get_args(builder_name),
borenetb76c1f72015-07-29 07:38:49 -0700243 'env': env,
borenet2481b8b2015-07-29 11:43:07 -0700244 'nanobench_flags': nanobench_flags.get_args(builder_name),
borenetb76c1f72015-07-29 07:38:49 -0700245 }
borenet7bccca12015-07-29 11:15:42 -0700246 device = device_cfg(builder_dict)
247 if device:
248 rv['device_cfg'] = device
borenetdbf9f012015-07-30 07:09:20 -0700249
250 role = builder_dict['role']
251 if role == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
252 configuration = CONFIG_RELEASE
253 else:
254 configuration = builder_dict.get(
255 'configuration', CONFIG_DEBUG)
256 arch = (builder_dict.get('arch') or builder_dict.get('target_arch'))
257 if ('Win' in builder_dict.get('os', '') and arch == 'x86_64'):
258 configuration += '_x64'
259 rv['configuration'] = configuration
260 rv['do_test_steps'] = role == builder_name_schema.BUILDER_ROLE_TEST
261 rv['do_perf_steps'] = (role == builder_name_schema.BUILDER_ROLE_PERF or
262 (role == builder_name_schema.BUILDER_ROLE_TEST and
263 configuration == CONFIG_DEBUG) or
264 'Valgrind' in builder_name)
265
266 # Do we upload perf results?
267 upload_perf_results = False
268 if role == builder_name_schema.BUILDER_ROLE_PERF:
269 upload_perf_results = True
270 rv['upload_perf_results'] = upload_perf_results
271
272 # Do we upload correctness results?
273 skip_upload_bots = [
274 'ASAN',
275 'Coverage',
276 'TSAN',
277 'UBSAN',
278 'Valgrind',
279 ]
280 upload_dm_results = True
281 for s in skip_upload_bots:
282 if s in builder_name:
283 upload_dm_results = False
284 break
285 rv['upload_dm_results'] = upload_dm_results
286
borenet7bccca12015-07-29 11:15:42 -0700287 return rv
borenetb76c1f72015-07-29 07:38:49 -0700288
289
290cov_end = lineno() # Don't care about code coverage past here.
291
292
293def self_test():
294 import coverage # This way the bots don't need coverage.py to be installed.
295 args = {}
296 cases = [
297 'Build-Mac10.8-Clang-Arm7-Debug-Android',
298 'Build-Win-MSVC-x86-Debug',
299 'Build-Win-MSVC-x86-Debug-GDI',
300 'Build-Win-MSVC-x86-Debug-Exceptions',
301 'Build-Ubuntu-GCC-Arm7-Debug-Android_FrameworkDefs',
borenet7bccca12015-07-29 11:15:42 -0700302 'Build-Ubuntu-GCC-Arm7-Debug-Android_NoNeon',
303 'Build-Ubuntu-GCC-Arm7-Debug-CrOS_Daisy',
304 'Build-Ubuntu-GCC-x86_64-Debug-CrOS_Link',
borenetb76c1f72015-07-29 07:38:49 -0700305 'Build-Ubuntu-GCC-x86_64-Release-Mesa',
306 'Housekeeper-PerCommit',
307 'Perf-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Release-Trybot',
borenet98f7e332015-08-24 12:50:59 -0700308 'Perf-Android-GCC-Nexus5-GPU-Adreno330-Arm7-Release-Appurify',
borenet7bccca12015-07-29 11:15:42 -0700309 'Test-Android-GCC-Nexus6-GPU-Adreno420-Arm7-Debug',
310 'Test-ChromeOS-GCC-Link-CPU-AVX-x86_64-Debug',
borenetb76c1f72015-07-29 07:38:49 -0700311 'Test-iOS-Clang-iPad4-GPU-SGX554-Arm7-Debug',
312 'Test-Mac10.8-Clang-MacMini4.1-GPU-GeForce320M-x86_64-Release',
borenet98f7e332015-08-24 12:50:59 -0700313 'Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Coverage',
borenetb76c1f72015-07-29 07:38:49 -0700314 'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD',
315 'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-Shared',
316 'Test-Ubuntu-GCC-ShuttleA-GPU-GTX550Ti-x86_64-Release-Valgrind',
317 'Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86-Release-ANGLE',
318 'Test-Win8-MSVC-ShuttleA-CPU-AVX-x86_64-Debug',
319 ]
320
321 cov = coverage.coverage()
322 cov.start()
323 for case in cases:
324 args[case] = get_builder_spec(case)
325 cov.stop()
326
327 this_file = os.path.basename(__file__)
328 _, _, not_run, _ = cov.analysis(this_file)
329 filtered = [line for line in not_run if
330 line > cov_start and line < cov_end and line not in cov_skip]
331 if filtered:
332 print 'Lines not covered by test cases: ', filtered
333 sys.exit(1)
334
335 golden = this_file.replace('.py', '.json')
336 with open(os.path.join(os.path.dirname(__file__), golden), 'w') as f:
337 json.dump(args, f, indent=2, sort_keys=True)
338
339
340if __name__ == '__main__':
341 if len(sys.argv) == 2 and sys.argv[1] == 'test':
342 self_test()
343 sys.exit(0)
344
345 if len(sys.argv) != 3:
346 print usage
347 sys.exit(1)
348
349 with open(sys.argv[1], 'w') as out:
350 json.dump(get_builder_spec(sys.argv[2]), out)