3 # Copyright (c) 2013 The Chromium Authors. 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.
18 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), '..'))
19 from pylib
import constants
22 CHROMIUM_COVERAGE_BUCKET
= 'chromium-code-coverage'
24 _BotConfig
= collections
.namedtuple(
25 'BotConfig', ['bot_id', 'host_obj', 'test_obj'])
27 HostConfig
= collections
.namedtuple(
29 ['script', 'host_steps', 'extra_args', 'extra_gyp_defines', 'target_arch'])
31 TestConfig
= collections
.namedtuple('Tests', ['script', 'tests', 'extra_args'])
34 def BotConfig(bot_id
, host_object
, test_object
=None):
35 return _BotConfig(bot_id
, host_object
, test_object
)
40 for key
in sorted(set(d1
.keys() + d2
.keys())):
41 if key
in d1
and d1
[key
] != d2
.get(key
):
42 diff
.append('- %s=%s' % (key
, pipes
.quote(d1
[key
])))
43 if key
in d2
and d2
[key
] != d1
.get(key
):
44 diff
.append('+ %s=%s' % (key
, pipes
.quote(d2
[key
])))
45 return '\n'.join(diff
)
48 def GetEnvironment(host_obj
, testing
, extra_env_vars
=None):
49 init_env
= dict(os
.environ
)
50 init_env
['GYP_GENERATORS'] = 'ninja'
51 init_env
['GOMA_DIR'] = bb_utils
.GOMA_DIR
53 init_env
.update(extra_env_vars
)
54 envsetup_cmd
= '. build/android/envsetup.sh'
55 if host_obj
.target_arch
:
56 envsetup_cmd
+= ' --target-arch=%s' % host_obj
.target_arch
58 # Skip envsetup to avoid presubmit dependence on android deps.
59 print 'Testing mode - skipping "%s"' % envsetup_cmd
62 print 'Running %s' % envsetup_cmd
63 proc
= subprocess
.Popen(['bash', '-exc',
64 envsetup_cmd
+ ' >&2; python build/android/buildbot/env_to_json.py'],
65 stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
,
66 cwd
=bb_utils
.CHROME_SRC
, env
=init_env
)
67 json_env
, envsetup_output
= proc
.communicate()
68 if proc
.returncode
!= 0:
69 print >> sys
.stderr
, 'FATAL Failure in envsetup.'
70 print >> sys
.stderr
, envsetup_output
72 env
= json
.loads(json_env
)
73 env
['GYP_DEFINES'] = env
.get('GYP_DEFINES', '') + ' fastbuild=1'
74 extra_gyp
= host_obj
.extra_gyp_defines
76 env
['GYP_DEFINES'] += ' %s' % extra_gyp
77 if re
.search('(asan|clang)=1', extra_gyp
):
78 env
.pop('CXX_target', None)
80 # Bots checkout chrome in /b/build/slave/<name>/build/src
81 build_internal_android
= os
.path
.abspath(os
.path
.join(
82 bb_utils
.CHROME_SRC
, '..', '..', '..', '..', '..', 'build_internal',
83 'scripts', 'slave', 'android'))
84 if os
.path
.exists(build_internal_android
):
85 env
['PATH'] = os
.pathsep
.join([build_internal_android
, env
['PATH']])
89 def GetCommands(options
, bot_config
):
90 """Get a formatted list of commands.
93 options: Options object.
94 bot_config: A BotConfig named tuple.
95 host_step_script: Host step script.
96 device_step_script: Device step script.
98 list of Command objects.
100 property_args
= bb_utils
.EncodeProperties(options
)
101 commands
= [[bot_config
.host_obj
.script
,
102 '--steps=%s' % ','.join(bot_config
.host_obj
.host_steps
)] +
103 property_args
+ (bot_config
.host_obj
.extra_args
or [])]
105 test_obj
= bot_config
.test_obj
107 run_test_cmd
= [test_obj
.script
, '--reboot'] + property_args
108 for test
in test_obj
.tests
:
109 run_test_cmd
.extend(['-f', test
])
110 if test_obj
.extra_args
:
111 run_test_cmd
.extend(test_obj
.extra_args
)
112 commands
.append(run_test_cmd
)
117 compile_step
= ['compile']
118 std_host_tests
= ['check_webview_licenses', 'findbugs']
119 std_build_steps
= ['compile', 'zip_build']
120 std_test_steps
= ['extract_build']
121 std_tests
= ['ui', 'unit']
123 '--flakiness-server=%s' % constants
.UPSTREAM_FLAKINESS_SERVER
)
124 experimental
= ['--experimental']
127 H
= (lambda steps
, extra_args
=None, extra_gyp
=None, target_arch
=None :
128 HostConfig('build/android/buildbot/bb_host_steps.py', steps
, extra_args
,
129 extra_gyp
, target_arch
))
130 T
= (lambda tests
, extra_args
=None :
131 TestConfig('build/android/buildbot/bb_device_steps.py', tests
,
136 B('main-builder-dbg', H(std_build_steps
+ std_host_tests
)),
137 B('main-builder-rel', H(std_build_steps
)),
138 B('main-clang-builder',
139 H(compile_step
, extra_gyp
='clang=1 component=shared_library')),
140 B('main-clobber', H(compile_step
)),
141 B('main-tests', H(std_test_steps
), T(std_tests
, [flakiness_server
])),
144 B('asan-builder-tests', H(compile_step
, extra_gyp
='asan=1'),
145 T(std_tests
, ['--asan'])),
146 B('blink-try-builder', H(compile_step
)),
147 B('chromedriver-fyi-tests-dbg', H(std_test_steps
),
148 T(['chromedriver'], ['--install=ChromiumTestShell'])),
149 B('fyi-x86-builder-dbg',
150 H(compile_step
+ std_host_tests
, experimental
, target_arch
='x86')),
152 H(std_build_steps
+ std_host_tests
, experimental
,
153 extra_gyp
='emma_coverage=1')),
155 H(compile_step
+ std_host_tests
, target_arch
='x86')),
156 B('fyi-builder-rel', H(std_build_steps
, experimental
)),
157 B('fyi-tests', H(std_test_steps
),
158 T(std_tests
, ['--experimental', flakiness_server
,
159 '--coverage-bucket', CHROMIUM_COVERAGE_BUCKET
])),
160 B('fyi-component-builder-tests-dbg',
161 H(compile_step
, extra_gyp
='component=shared_library'),
162 T(std_tests
, ['--experimental', flakiness_server
])),
163 B('gpu-builder-tests-dbg', H(compile_step
), T(['gpu'])),
164 B('perf-bisect-builder-tests-dbg', H(['bisect_perf_regression'])),
165 B('perf-tests-rel', H(std_test_steps
),
166 T([], ['--install=ChromiumTestShell'])),
167 B('webkit-latest-webkit-tests', H(std_test_steps
),
168 T(['webkit_layout', 'webkit'], ['--auto-reconnect'])),
169 B('webkit-latest-contentshell', H(compile_step
),
170 T(['webkit_layout'], ['--auto-reconnect'])),
171 B('builder-unit-tests', H(compile_step
), T(['unit'])),
174 extra_args
=['--build-targets=android_builder_webrtc'],
175 extra_gyp
='include_tests=1 enable_tracing=1')),
176 B('webrtc-tests', H(['download_webrtc_resources'] + std_test_steps
),
177 T(['webrtc'], [flakiness_server
])),
179 # Generic builder config (for substring match).
180 B('builder', H(std_build_steps
)),
183 bot_map
= dict((config
.bot_id
, config
) for config
in bot_configs
)
185 # These bots have identical configuration to ones defined earlier.
187 ('lkgr-clobber', 'main-clobber'),
188 ('try-builder-dbg', 'main-builder-dbg'),
189 ('try-builder-rel', 'main-builder-rel'),
190 ('try-clang-builder', 'main-clang-builder'),
191 ('try-fyi-builder-dbg', 'fyi-builder-dbg'),
192 ('try-x86-builder-dbg', 'x86-builder-dbg'),
193 ('try-tests', 'main-tests'),
194 ('try-fyi-tests', 'fyi-tests'),
195 ('webkit-latest-tests', 'main-tests'),
197 for to_id
, from_id
in copy_map
:
198 assert to_id
not in bot_map
199 # pylint: disable=W0212
200 bot_map
[to_id
] = copy
.deepcopy(bot_map
[from_id
])._replace
(bot_id
=to_id
)
202 # Trybots do not upload to flakiness dashboard. They should be otherwise
203 # identical in configuration to their trunk building counterparts.
204 test_obj
= bot_map
[to_id
].test_obj
205 if to_id
.startswith('try') and test_obj
:
206 extra_args
= test_obj
.extra_args
207 if extra_args
and flakiness_server
in extra_args
:
208 extra_args
.remove(flakiness_server
)
212 # Return an object from the map, looking first for an exact id match.
213 # If this fails, look for an id which is a substring of the specified id.
214 # Choose the longest of all substring matches.
215 # pylint: disable=W0622
216 def GetBestMatch(id_map
, id):
217 config
= id_map
.get(id)
219 substring_matches
= filter(lambda x
: x
in id, id_map
.iterkeys())
220 if substring_matches
:
221 max_id
= max(substring_matches
, key
=len)
222 print 'Using config from id="%s" (substring match).' % max_id
223 config
= id_map
[max_id
]
227 def GetRunBotOptParser():
228 parser
= bb_utils
.GetParser()
229 parser
.add_option('--bot-id', help='Specify bot id directly.')
230 parser
.add_option('--testing', action
='store_true',
231 help='For testing: print, but do not run commands')
236 def GetBotConfig(options
, bot_step_map
):
237 bot_id
= options
.bot_id
or options
.factory_properties
.get('android_bot_id')
240 'A bot id must be specified through option or factory_props.')
243 bot_config
= GetBestMatch(bot_step_map
, bot_id
)
245 print 'Error: config for id="%s" cannot be inferred.' % bot_id
249 def RunBotCommands(options
, commands
, env
):
250 print 'Environment changes:'
251 print DictDiff(dict(os
.environ
), env
)
253 for command
in commands
:
254 print bb_utils
.CommandToString(command
)
257 env
['BUILDBOT_TESTING'] = '1'
258 return_code
= subprocess
.call(command
, cwd
=bb_utils
.CHROME_SRC
, env
=env
)
264 parser
= GetRunBotOptParser()
265 options
, args
= parser
.parse_args(argv
[1:])
267 parser
.error('Unused args: %s' % args
)
269 bot_config
= GetBotConfig(options
, GetBotStepMap())
273 print 'Using config:', bot_config
275 commands
= GetCommands(options
, bot_config
)
276 for command
in commands
:
277 print 'Will run: ', bb_utils
.CommandToString(command
)
280 env
= GetEnvironment(bot_config
.host_obj
, options
.testing
)
281 return RunBotCommands(options
, commands
, env
)
284 if __name__
== '__main__':
285 sys
.exit(main(sys
.argv
))