Chromium Code Reviews| Index: build/android/buildbot/bb_bot_steps.py |
| diff --git a/build/android/buildbot/bb_bot_steps.py b/build/android/buildbot/bb_bot_steps.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a4eb998e2dc1ae04e29cc6859b65738be7148952 |
| --- /dev/null |
| +++ b/build/android/buildbot/bb_bot_steps.py |
| @@ -0,0 +1,182 @@ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import collections |
| +import json |
| +import optparse |
| +import os |
| +import pipes |
| +import subprocess |
| +import sys |
| + |
| +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| +from pylib import buildbot_report |
| + |
| +CHROME_SRC = os.path.abspath( |
| + os.path.join(os.path.dirname(__file__), '..', '..', '..')) |
| + |
| +GLOBAL_SLAVE_PROPS = {} |
| + |
| +BotConfig = collections.namedtuple( |
| + 'BotConfig', ['bot_id', 'bash_funs', 'test_obj', 'slave_props']) |
| +TestConfig = collections.namedtuple('Tests', ['tests', 'extra_args']) |
| +Command = collections.namedtuple('Command', ['step_name', 'command']) |
| + |
| +def GetCommands(bot_config, options): |
| + """Get a formatted list of commands. |
| + |
| + Args: |
| + bot_config: A BotConfig named tuple. |
| + options: Options object. |
| + """ |
| + slave_props = dict(GLOBAL_SLAVE_PROPS) |
| + if bot_config.slave_props: |
| + slave_props.update(bot_config.slave_props) |
| + |
| + property_args = [ |
| + '--factory-properties=%s' % json.dumps(options.factory_properties), |
| + '--build-properties=%s' % json.dumps(options.build_properties), |
| + '--slave-properties=%s' % json.dumps(slave_props)] |
| + |
| + commands = [] |
| + if bot_config.bash_funs: |
| + bash_base = [ |
| + '. build/android/buildbot/buildbot_functions.sh', |
| + "bb_baseline_setup %s '%s'" % |
| + (CHROME_SRC, "' '".join(property_args))] |
| + commands.append(Command( |
| + None, ['bash', '-exc', ' && '.join(bash_base + bot_config.bash_funs)])) |
| + |
| + test_obj = bot_config.test_obj |
| + if test_obj: |
| + run_test_cmd = ['build/android/buildbot/bb_run_tests.py'] + property_args |
| + for test in test_obj.tests: |
| + run_test_cmd.extend(['-f', test]) |
| + if test_obj.extra_args: |
| + run_test_cmd.extend(test_obj.extra_args) |
| + commands.append(Command('Run tests', run_test_cmd)) |
| + |
| + return commands |
| + |
| + |
| +def GetBuildbotConfig(options): |
| + """Lookup a bot config based on a bot_id. |
| + |
| + If factory_properties specifies a bot_id, that is used in preference to |
| + options.bot_id. |
| + Returns: |
| + BotConfig object, choosing a configuration for a given bot_id with the |
| + following order of preference: |
| + 1) Exact match |
| + 2) Substring match (so similar bots can have unique IDs, but share config) |
| + 3) A default config based on bot name. |
| + """ |
| + std_build_steps = ['bb_compile', 'bb_zip_build'] |
| + std_test_steps = ['bb_extract_build', 'bb_reboot_phones'] |
| + std_tests = ['ui', 'unit'] |
| + |
| + B = BotConfig |
| + def T(tests, extra_args=None): |
| + return TestConfig(tests, extra_args) |
| + |
| + bot_configs = [ |
| + B('main-clobber', ['bb_compile'], None, None), |
| + B('main-builder-dbg', |
| + ['bb_compile', 'bb_run_findbugs', 'bb_zip_build'], None, None), |
| + B('main-builder-rel', std_build_steps, None, None), |
| + B('main-tests-dbg', std_test_steps, T(std_tests), None), |
| + B('clang-builder', ['bb_compile'], None, None), |
| + B('fyi-builder-dbg', |
| + ['check_webview_licenses', 'bb_compile', 'bb_compile_experimental', |
| + 'bb_run_findbugs', 'bb_zip_build'], None, None), |
| + B('fyi-builder-rel', |
| + ['bb_compile', 'bb_compile_experimental', 'bb_zip_build'], None, None), |
| + B('fyi-tests', std_test_steps, T(std_tests, ['--experimental']), None), |
| + B('asan-builder', std_build_steps, None, None), |
| + B('asan-tests', std_test_steps, T(std_tests, ['--asan']), None), |
| + B('perf-builder-rel', std_build_steps, None, None), |
| + B('perf-tests-rel', std_test_steps, T([], ['--install=ContentShell']), |
| + None), |
| + B('webkit-latest-builder', std_build_steps, None, None), |
| + B('webkit-latest-tests', std_test_steps, T(['unit']), None), |
| + B('webkit-latest-webkit-tests', std_test_steps, |
| + T(['webkit_layout', 'webkit']), None), |
| + ] |
| + bot_map = dict((config.bot_id, config) for config in bot_configs) |
| + |
| + def CopyConfig(from_id, to_id): |
| + assert to_id not in bot_map |
| + bot_map[to_id] = bot_map[from_id]._replace(bot_id=to_id) |
| + |
| + CopyConfig('main-builder-dbg', 'try-builder-dbg') |
| + CopyConfig('main-tests-dbg', 'try-tests-dbg') |
| + CopyConfig('clang-builder', 'try-clang-builder') |
| + CopyConfig('fyi-builder-dbg', 'try-fyi-builder-dbg') |
| + CopyConfig('fyi-tests', 'try-fyi-tests') |
| + |
| + bot_id = options.factory_properties.get('bot_id', options.bot_id) |
| + if bot_id: |
| + if bot_id in bot_map: |
| + return bot_map[bot_id] |
| + for cur_id, cur_config in bot_map.iteritems(): |
| + if cur_id in bot_id: |
| + return cur_config |
| + if 'Test' in options.build_properties.get('buildername', ''): |
| + return B('default-test', base_test_steps, default_tests, {}) |
| + else: |
| + return B('default-build', base_build_steps, [], {}) |
| + |
| + |
| +def main(argv): |
| + parser = optparse.OptionParser() |
| + |
| + def ConvertJson(option, _, value, parser): |
| + setattr(parser.values, option.dest, json.loads(value)) |
| + |
| + parser.add_option('--build-properties', action='callback', |
| + callback=ConvertJson, type='string', default={}, |
| + help='build properties in JSON format') |
| + parser.add_option('--factory-properties', action='callback', |
| + callback=ConvertJson, type='string', default={}, |
| + help='factory properties in JSON format') |
| + parser.add_option('--bot-id', help='Specify bot id directly.') |
| + parser.add_option('--TESTING', action='store_true', |
| + help='For testing: print, but do not run commands') |
| + options, args = parser.parse_args(argv[1:]) |
| + if args: |
| + optparse.error('Unused args: %s' % args) |
| + |
| + bot_config = GetBuildbotConfig(options) |
| + print 'Using config:', bot_config |
| + |
| + return_code = 0 |
| + |
| + def CommandToString(command): |
| + """Returns quoted command that can be run in bash shell.""" |
| + return ' '.join(map(pipes.quote, command)) |
| + |
| + command_objs = GetCommands(bot_config, options) |
| + for command_obj in command_objs: |
| + print 'Will run:', CommandToString(command_obj.command) |
| + |
| + for command_obj in command_objs: |
| + if command_obj.step_name: |
| + buildbot_report.PrintNamedStep(command_obj.step_name) |
| + command = command_obj.command |
| + print CommandToString(command) |
| + sys.stdout.flush() |
| + env = None |
| + if options.TESTING: |
| + # The bash command doesn't yet support the testing option. |
| + if command[0] == 'bash': |
| + continue |
| + env = dict(os.environ) |
| + env['BUILDBOT_TESTING'] = '1' |
| + |
| + return_code |= subprocess.call(command, cwd=CHROME_SRC, env=env) |
| + return return_code |
| +if __name__ == '__main__': |
|
xusydoc (do not use)
2013/01/04 17:09:21
2 spaces
|
| + sys.exit(main(sys.argv)) |