OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import collections | 7 import collections |
8 import json | 8 import json |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
11 import pipes | 11 import pipes |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 | 14 |
15 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 15 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
16 from pylib import buildbot_report | 16 from pylib import buildbot_report |
17 | 17 |
18 CHROME_SRC = os.path.abspath( | 18 CHROME_SRC = os.path.abspath( |
19 os.path.join(os.path.dirname(__file__), '..', '..', '..')) | 19 os.path.join(os.path.dirname(__file__), '..', '..', '..')) |
20 | 20 |
21 GLOBAL_SLAVE_PROPS = {} | 21 GLOBAL_SLAVE_PROPS = {} |
22 | 22 |
23 BotConfig = collections.namedtuple( | 23 BotConfig = collections.namedtuple( |
24 'BotConfig', ['bot_id', 'bash_funs', 'test_obj', 'slave_props']) | 24 'BotConfig', ['bot_id', 'bash_funs', 'test_obj', 'slave_props']) |
25 TestConfig = collections.namedtuple('Tests', ['tests', 'extra_args']) | 25 TestConfig = collections.namedtuple('Tests', ['tests', 'extra_args']) |
26 Command = collections.namedtuple('Command', ['step_name', 'command']) | 26 Command = collections.namedtuple( |
| 27 'Command', ['step_name', 'command', 'testing_cmd']) |
27 | 28 |
28 | 29 |
29 def GetCommands(options, bot_config): | 30 def GetCommands(options, bot_config): |
30 """Get a formatted list of commands. | 31 """Get a formatted list of commands. |
31 | 32 |
32 Args: | 33 Args: |
33 options: Options object. | 34 options: Options object. |
34 bot_config: A BotConfig named tuple. | 35 bot_config: A BotConfig named tuple. |
35 Returns: | 36 Returns: |
36 list of Command objects. | 37 list of Command objects. |
37 """ | 38 """ |
38 slave_props = dict(GLOBAL_SLAVE_PROPS) | 39 slave_props = dict(GLOBAL_SLAVE_PROPS) |
39 if bot_config.slave_props: | 40 if bot_config.slave_props: |
40 slave_props.update(bot_config.slave_props) | 41 slave_props.update(bot_config.slave_props) |
41 | 42 |
42 property_args = [ | 43 property_args = [ |
43 '--factory-properties=%s' % json.dumps(options.factory_properties), | 44 '--factory-properties=%s' % json.dumps(options.factory_properties), |
44 '--build-properties=%s' % json.dumps(options.build_properties), | 45 '--build-properties=%s' % json.dumps(options.build_properties), |
45 '--slave-properties=%s' % json.dumps(slave_props)] | 46 '--slave-properties=%s' % json.dumps(slave_props)] |
46 | 47 |
47 commands = [] | 48 commands = [] |
| 49 def WrapWithBash(command): |
| 50 """Wrap a bash command string with envsetup scripts.""" |
| 51 return ['bash', '-exc', '; '.join([ |
| 52 '. build/android/buildbot/buildbot_functions.sh', |
| 53 'bb_baseline_setup %s %s' % ( |
| 54 CHROME_SRC, |
| 55 ' '.join(map(pipes.quote, property_args))), |
| 56 command]) |
| 57 ] |
| 58 |
48 if bot_config.bash_funs: | 59 if bot_config.bash_funs: |
49 bash_base = [ | 60 # bash_funs command does not have a testing mode. |
50 '. build/android/buildbot/buildbot_functions.sh', | 61 commands.append( |
51 "bb_baseline_setup %s '%s'" % | 62 Command(None, WrapWithBash('; '.join(bot_config.bash_funs)), None)) |
52 (CHROME_SRC, "' '".join(property_args))] | |
53 commands.append(Command( | |
54 None, ['bash', '-exc', '; '.join(bash_base + bot_config.bash_funs)])) | |
55 | 63 |
56 test_obj = bot_config.test_obj | 64 test_obj = bot_config.test_obj |
57 if test_obj: | 65 if test_obj: |
58 run_test_cmd = [ | 66 run_test_cmd = [ |
59 'build/android/buildbot/bb_device_steps.py', '--reboot'] + property_args | 67 'build/android/buildbot/bb_device_steps.py', '--reboot'] + property_args |
60 for test in test_obj.tests: | 68 for test in test_obj.tests: |
61 run_test_cmd.extend(['-f', test]) | 69 run_test_cmd.extend(['-f', test]) |
62 if test_obj.extra_args: | 70 if test_obj.extra_args: |
63 run_test_cmd.extend(test_obj.extra_args) | 71 run_test_cmd.extend(test_obj.extra_args) |
64 commands.append(Command('Run tests', run_test_cmd)) | 72 commands.append(Command( |
| 73 'Run tests', |
| 74 WrapWithBash(' '.join(map(pipes.quote, run_test_cmd))), run_test_cmd)) |
65 | 75 |
66 return commands | 76 return commands |
67 | 77 |
68 | 78 |
69 def GetBotStepMap(): | 79 def GetBotStepMap(): |
70 compile_step = ['bb_compile'] | 80 compile_step = ['bb_compile'] |
71 std_build_steps = ['bb_compile', 'bb_zip_build'] | 81 std_build_steps = ['bb_compile', 'bb_zip_build'] |
72 std_test_steps = ['bb_extract_build'] | 82 std_test_steps = ['bb_extract_build'] |
73 std_tests = ['ui', 'unit'] | 83 std_tests = ['ui', 'unit'] |
74 | 84 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 print 'Will run:', CommandToString(command_obj.command) | 191 print 'Will run:', CommandToString(command_obj.command) |
182 | 192 |
183 for command_obj in command_objs: | 193 for command_obj in command_objs: |
184 if command_obj.step_name: | 194 if command_obj.step_name: |
185 buildbot_report.PrintNamedStep(command_obj.step_name) | 195 buildbot_report.PrintNamedStep(command_obj.step_name) |
186 command = command_obj.command | 196 command = command_obj.command |
187 print CommandToString(command) | 197 print CommandToString(command) |
188 sys.stdout.flush() | 198 sys.stdout.flush() |
189 env = None | 199 env = None |
190 if options.TESTING: | 200 if options.TESTING: |
191 # The bash command doesn't yet support the testing option. | 201 if not command_obj.testing_cmd: |
192 if command[0] == 'bash': | |
193 continue | 202 continue |
194 env = dict(os.environ) | 203 return_code = subprocess.call( |
195 env['BUILDBOT_TESTING'] = '1' | 204 command_obj.testing_cmd, |
196 | 205 cwd=CHROME_SRC, |
197 return_code = subprocess.call(command, cwd=CHROME_SRC, env=env) | 206 env=dict(os.environ, BUILDBOT_TESTING='1')) |
| 207 else: |
| 208 return_code = subprocess.call(command, cwd=CHROME_SRC, env=env) |
198 if return_code != 0: | 209 if return_code != 0: |
199 return return_code | 210 return return_code |
200 | 211 |
201 | 212 |
202 if __name__ == '__main__': | 213 if __name__ == '__main__': |
203 sys.exit(main(sys.argv)) | 214 sys.exit(main(sys.argv)) |
OLD | NEW |