1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#!/usr/bin/env python
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Copyright 2013 The Chromium Authors. All rights reserved.
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# found in the LICENSE file.
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)import os
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)import sys
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)import bb_utils
107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochimport bb_annotations
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)from pylib import constants
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)VALID_HOST_TESTS = set(['check_webview_licenses', 'findbugs'])
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)DIR_BUILD_ROOT = os.path.dirname(constants.DIR_SOURCE_ROOT)
208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Short hand for RunCmd which is used extensively in this file.
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)RunCmd = bb_utils.RunCmd
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)def SrcPath(*path):
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return os.path.join(constants.DIR_SOURCE_ROOT, *path)
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)def CheckWebViewLicenses(_):
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bb_annotations.PrintNamedStep('check_licenses')
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  RunCmd([SrcPath('android_webview', 'tools', 'webview_licenses.py'), 'scan'],
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)         warning_code=1)
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)def RunHooks(build_type):
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  RunCmd([SrcPath('build', 'landmines.py')])
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  build_path = SrcPath('out', build_type)
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  landmine_path = os.path.join(build_path, '.landmines_triggered')
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  clobber_env = os.environ.get('BUILDBOT_CLOBBER')
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if clobber_env or os.path.isfile(landmine_path):
417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    bb_annotations.PrintNamedStep('Clobber')
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if not clobber_env:
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      print 'Clobbering due to triggered landmines:'
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      with open(landmine_path) as f:
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        print f.read()
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    RunCmd(['rm', '-rf', build_path])
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bb_annotations.PrintNamedStep('runhooks')
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  RunCmd(['gclient', 'runhooks'], halt_on_failure=True)
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)def Compile(options):
537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunHooks(options.target)
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  cmd = [os.path.join(SLAVE_SCRIPTS_DIR, 'compile.py'),
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)         '--build-tool=ninja',
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)         '--compiler=goma',
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)         '--target=%s' % options.target,
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)         '--goma-dir=%s' % bb_utils.GOMA_DIR]
597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bb_annotations.PrintNamedStep('compile')
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if options.build_targets:
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    build_targets = options.build_targets.split(',')
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    cmd += ['--build-args', ' '.join(build_targets)]
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RunCmd(cmd, halt_on_failure=True, cwd=DIR_BUILD_ROOT)
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)def ZipBuild(options):
677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bb_annotations.PrintNamedStep('zip_build')
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  RunCmd([
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'),
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      '--src-dir', constants.DIR_SOURCE_ROOT,
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests']
728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT)
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)def ExtractBuild(options):
767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bb_annotations.PrintNamedStep('extract_build')
77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'extract_build.py')]
785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)         + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT)
79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)def FindBugs(options):
827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bb_annotations.PrintNamedStep('findbugs')
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  build_type = []
847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if options.target == 'Release':
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    build_type = ['--release-build']
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  RunCmd([SrcPath('build', 'android', 'findbugs_diff.py')] + build_type)
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  RunCmd([SrcPath(
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      'tools', 'android', 'findbugs_plugin', 'test',
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      'run_findbugs_plugin_tests.py')] + build_type)
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
9223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)def BisectPerfRegression(options):
9323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  args = []
9423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  if options.extra_src:
9523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    args = ['--extra_src', options.extra_src]
967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'),
977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)])
987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'),
9923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)          '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)] + args)
1007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochdef GetHostStepCmds():
1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return [
1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      ('compile', Compile),
1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      ('extract_build', ExtractBuild),
1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      ('check_webview_licenses', CheckWebViewLicenses),
1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      ('bisect_perf_regression', BisectPerfRegression),
1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      ('findbugs', FindBugs),
1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      ('zip_build', ZipBuild)
1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ]
1117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochdef GetHostStepsOptParser():
114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  parser = bb_utils.GetParser()
1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  parser.add_option('--steps', help='Comma separated list of host tests.')
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  parser.add_option('--build-targets', default='',
117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                    help='Comma separated list of build targets.')
118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  parser.add_option('--experimental', action='store_true',
119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                    help='Indicate whether to compile experimental targets.')
12023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  parser.add_option('--extra_src', default='',
12123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)                    help='Path to extra source file. If this is supplied, '
12223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)                    'bisect script will use it to override default behavior.')
123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return parser
125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochdef main(argv):
128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  parser = GetHostStepsOptParser()
129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  options, args = parser.parse_args(argv[1:])
130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if args:
131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return sys.exit('Unused args %s' % args)
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
13423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  setattr(options, 'extra_src',
13523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)          options.factory_properties.get('extra_src', ''))
1367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if options.steps:
138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options)
139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)if __name__ == '__main__':
142868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  sys.exit(main(sys.argv))
143