OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright (c) 2012 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. | |
6 | |
7 import collections | |
8 import json | |
9 import optparse | |
10 import os | |
11 import pipes | |
12 import subprocess | |
13 import sys | |
14 | |
15 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
16 from pylib import buildbot_report | |
17 | |
18 CHROME_SRC = os.path.abspath( | |
19 os.path.join(os.path.dirname(__file__), '..', '..', '..')) | |
20 | |
21 GLOBAL_SLAVE_PROPS = {} | |
22 | |
23 BotConfig = collections.namedtuple( | |
24 'BotConfig', ['bot_id', 'bash_funs', 'test_obj', 'slave_props']) | |
25 TestConfig = collections.namedtuple('Tests', ['tests', 'extra_args']) | |
26 Command = collections.namedtuple('Command', ['step_name', 'command']) | |
27 | |
28 def GetCommands(bot_config, options): | |
29 """Get a formatted list of commands. | |
30 | |
31 Args: | |
32 bot_config: A BotConfig named tuple. | |
33 options: Options object. | |
34 """ | |
35 slave_props = dict(GLOBAL_SLAVE_PROPS) | |
36 if bot_config.slave_props: | |
37 slave_props.update(bot_config.slave_props) | |
38 | |
39 property_args = [ | |
40 '--factory-properties=%s' % json.dumps(options.factory_properties), | |
41 '--build-properties=%s' % json.dumps(options.build_properties), | |
42 '--slave-properties=%s' % json.dumps(slave_props)] | |
43 | |
44 commands = [] | |
45 if bot_config.bash_funs: | |
46 bash_base = [ | |
47 '. build/android/buildbot/buildbot_functions.sh', | |
48 "bb_baseline_setup %s '%s'" % | |
49 (CHROME_SRC, "' '".join(property_args))] | |
50 commands.append(Command( | |
51 None, ['bash', '-exc', ' && '.join(bash_base + bot_config.bash_funs)])) | |
52 | |
53 test_obj = bot_config.test_obj | |
54 if test_obj: | |
55 run_test_cmd = ['build/android/buildbot/bb_run_tests.py'] + property_args | |
56 for test in test_obj.tests: | |
57 run_test_cmd.extend(['-f', test]) | |
58 if test_obj.extra_args: | |
59 run_test_cmd.extend(test_obj.extra_args) | |
60 commands.append(Command('Run tests', run_test_cmd)) | |
61 | |
62 return commands | |
63 | |
64 | |
65 def GetBuildbotConfig(options): | |
66 """Lookup a bot config based on a bot_id. | |
67 | |
68 If factory_properties specifies a bot_id, that is used in preference to | |
69 options.bot_id. | |
70 Returns: | |
71 BotConfig object, choosing a configuration for a given bot_id with the | |
72 following order of preference: | |
73 1) Exact match | |
74 2) Substring match (so similar bots can have unique IDs, but share config) | |
75 3) A default config based on bot name. | |
76 """ | |
77 std_build_steps = ['bb_compile', 'bb_zip_build'] | |
78 std_test_steps = ['bb_extract_build', 'bb_reboot_phones'] | |
79 std_tests = ['ui', 'unit'] | |
80 | |
81 B = BotConfig | |
82 def T(tests, extra_args=None): | |
83 return TestConfig(tests, extra_args) | |
84 | |
85 bot_configs = [ | |
86 B('main-clobber', ['bb_compile'], None, None), | |
87 B('main-builder-dbg', | |
88 ['bb_compile', 'bb_run_findbugs', 'bb_zip_build'], None, None), | |
89 B('main-builder-rel', std_build_steps, None, None), | |
90 B('main-tests-dbg', std_test_steps, T(std_tests), None), | |
91 B('clang-builder', ['bb_compile'], None, None), | |
92 B('fyi-builder-dbg', | |
93 ['check_webview_licenses', 'bb_compile', 'bb_compile_experimental', | |
94 'bb_run_findbugs', 'bb_zip_build'], None, None), | |
95 B('fyi-builder-rel', | |
96 ['bb_compile', 'bb_compile_experimental', 'bb_zip_build'], None, None), | |
97 B('fyi-tests', std_test_steps, T(std_tests, ['--experimental']), None), | |
98 B('asan-builder', std_build_steps, None, None), | |
99 B('asan-tests', std_test_steps, T(std_tests, ['--asan']), None), | |
100 B('perf-builder-rel', std_build_steps, None, None), | |
101 B('perf-tests-rel', std_test_steps, T([], ['--install=ContentShell']), | |
102 None), | |
103 B('webkit-latest-builder', std_build_steps, None, None), | |
104 B('webkit-latest-tests', std_test_steps, T(['unit']), None), | |
105 B('webkit-latest-webkit-tests', std_test_steps, | |
106 T(['webkit_layout', 'webkit']), None), | |
107 ] | |
108 bot_map = dict((config.bot_id, config) for config in bot_configs) | |
109 | |
110 def CopyConfig(from_id, to_id): | |
111 assert to_id not in bot_map | |
112 bot_map[to_id] = bot_map[from_id]._replace(bot_id=to_id) | |
113 | |
114 CopyConfig('main-builder-dbg', 'try-builder-dbg') | |
115 CopyConfig('main-tests-dbg', 'try-tests-dbg') | |
116 CopyConfig('clang-builder', 'try-clang-builder') | |
117 CopyConfig('fyi-builder-dbg', 'try-fyi-builder-dbg') | |
118 CopyConfig('fyi-tests', 'try-fyi-tests') | |
119 | |
120 bot_id = options.factory_properties.get('bot_id', options.bot_id) | |
121 if bot_id: | |
122 if bot_id in bot_map: | |
123 return bot_map[bot_id] | |
124 for cur_id, cur_config in bot_map.iteritems(): | |
125 if cur_id in bot_id: | |
126 return cur_config | |
127 if 'Test' in options.build_properties.get('buildername', ''): | |
128 return B('default-test', base_test_steps, default_tests, {}) | |
129 else: | |
130 return B('default-build', base_build_steps, [], {}) | |
131 | |
132 | |
133 def main(argv): | |
134 parser = optparse.OptionParser() | |
135 | |
136 def ConvertJson(option, _, value, parser): | |
137 setattr(parser.values, option.dest, json.loads(value)) | |
138 | |
139 parser.add_option('--build-properties', action='callback', | |
140 callback=ConvertJson, type='string', default={}, | |
141 help='build properties in JSON format') | |
142 parser.add_option('--factory-properties', action='callback', | |
143 callback=ConvertJson, type='string', default={}, | |
144 help='factory properties in JSON format') | |
145 parser.add_option('--bot-id', help='Specify bot id directly.') | |
146 parser.add_option('--TESTING', action='store_true', | |
147 help='For testing: print, but do not run commands') | |
148 options, args = parser.parse_args(argv[1:]) | |
149 if args: | |
150 optparse.error('Unused args: %s' % args) | |
151 | |
152 bot_config = GetBuildbotConfig(options) | |
153 print 'Using config:', bot_config | |
154 | |
155 return_code = 0 | |
156 | |
157 def CommandToString(command): | |
158 """Returns quoted command that can be run in bash shell.""" | |
159 return ' '.join(map(pipes.quote, command)) | |
160 | |
161 command_objs = GetCommands(bot_config, options) | |
162 for command_obj in command_objs: | |
163 print 'Will run:', CommandToString(command_obj.command) | |
164 | |
165 for command_obj in command_objs: | |
166 if command_obj.step_name: | |
167 buildbot_report.PrintNamedStep(command_obj.step_name) | |
168 command = command_obj.command | |
169 print CommandToString(command) | |
170 sys.stdout.flush() | |
171 env = None | |
172 if options.TESTING: | |
173 # The bash command doesn't yet support the testing option. | |
174 if command[0] == 'bash': | |
175 continue | |
176 env = dict(os.environ) | |
177 env['BUILDBOT_TESTING'] = '1' | |
178 | |
179 return_code |= subprocess.call(command, cwd=CHROME_SRC, env=env) | |
180 return return_code | |
181 if __name__ == '__main__': | |
xusydoc (do not use)
2013/01/04 17:09:21
2 spaces
| |
182 sys.exit(main(sys.argv)) | |
OLD | NEW |