Home | History | Annotate | Download | only in buildbot
      1 #!/usr/bin/env python
      2 # Copyright 2013 The Chromium Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 import os
      7 import sys
      8 
      9 import bb_utils
     10 import bb_annotations
     11 
     12 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
     13 from pylib import constants
     14 
     15 
     16 SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
     17 VALID_HOST_TESTS = set(['check_webview_licenses', 'findbugs'])
     18 EXPERIMENTAL_TARGETS = ['android_experimental']
     19 
     20 # Short hand for RunCmd which is used extensively in this file.
     21 RunCmd = bb_utils.RunCmd
     22 
     23 
     24 def SrcPath(*path):
     25   return os.path.join(constants.DIR_SOURCE_ROOT, *path)
     26 
     27 
     28 def CheckWebViewLicenses(_):
     29   bb_annotations.PrintNamedStep('check_licenses')
     30   RunCmd([SrcPath('android_webview', 'tools', 'webview_licenses.py'), 'scan'],
     31          warning_code=1)
     32 
     33 
     34 def RunHooks(build_type):
     35   RunCmd([SrcPath('build', 'landmines.py')])
     36   build_path = SrcPath('out', build_type)
     37   landmine_path = os.path.join(build_path, '.landmines_triggered')
     38   clobber_env = os.environ.get('BUILDBOT_CLOBBER')
     39   if clobber_env or os.path.isfile(landmine_path):
     40     bb_annotations.PrintNamedStep('Clobber')
     41     if not clobber_env:
     42       print 'Clobbering due to triggered landmines:'
     43       with open(landmine_path) as f:
     44         print f.read()
     45     RunCmd(['rm', '-rf', build_path])
     46 
     47   bb_annotations.PrintNamedStep('runhooks')
     48   RunCmd(['gclient', 'runhooks'], halt_on_failure=True)
     49 
     50 
     51 def Compile(options):
     52   RunHooks(options.target)
     53   cmd = [os.path.join(SLAVE_SCRIPTS_DIR, 'compile.py'),
     54          '--build-tool=ninja',
     55          '--compiler=goma',
     56          '--target=%s' % options.target,
     57          '--goma-dir=%s' % bb_utils.GOMA_DIR]
     58   build_targets = options.build_targets.split(',')
     59   bb_annotations.PrintNamedStep('compile')
     60   for build_target in build_targets:
     61     RunCmd(cmd + ['--build-args=%s' % build_target], halt_on_failure=True)
     62   if options.experimental:
     63     for compile_target in EXPERIMENTAL_TARGETS:
     64       bb_annotations.PrintNamedStep('Experimental Compile %s' % compile_target)
     65       RunCmd(cmd + ['--build-args=%s' % compile_target], flunk_on_failure=False)
     66 
     67 
     68 def ZipBuild(options):
     69   bb_annotations.PrintNamedStep('zip_build')
     70   RunCmd([
     71       os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'),
     72       '--src-dir', constants.DIR_SOURCE_ROOT,
     73       '--build-dir', SrcPath('out'),
     74       '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests']
     75       + bb_utils.EncodeProperties(options))
     76 
     77 
     78 def ExtractBuild(options):
     79   bb_annotations.PrintNamedStep('extract_build')
     80   RunCmd(
     81       [os.path.join(SLAVE_SCRIPTS_DIR, 'extract_build.py'),
     82        '--build-dir', SrcPath('build'), '--build-output-dir',
     83        SrcPath('out')] + bb_utils.EncodeProperties(options),
     84        warning_code=1)
     85 
     86 
     87 def FindBugs(options):
     88   bb_annotations.PrintNamedStep('findbugs')
     89   build_type = []
     90   if options.target == 'Release':
     91     build_type = ['--release-build']
     92   RunCmd([SrcPath('build', 'android', 'findbugs_diff.py')] + build_type)
     93   RunCmd([SrcPath(
     94       'tools', 'android', 'findbugs_plugin', 'test',
     95       'run_findbugs_plugin_tests.py')] + build_type)
     96 
     97 
     98 def BisectPerfRegression(_):
     99   bb_annotations.PrintNamedStep('Bisect Perf Regression')
    100   RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'),
    101           '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)])
    102   RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'),
    103           '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)])
    104 
    105 
    106 def GetHostStepCmds():
    107   return [
    108       ('compile', Compile),
    109       ('extract_build', ExtractBuild),
    110       ('check_webview_licenses', CheckWebViewLicenses),
    111       ('bisect_perf_regression', BisectPerfRegression),
    112       ('findbugs', FindBugs),
    113       ('zip_build', ZipBuild)
    114   ]
    115 
    116 
    117 def GetHostStepsOptParser():
    118   parser = bb_utils.GetParser()
    119   parser.add_option('--steps', help='Comma separated list of host tests.')
    120   parser.add_option('--build-targets', default='All',
    121                     help='Comma separated list of build targets.')
    122   parser.add_option('--experimental', action='store_true',
    123                     help='Indicate whether to compile experimental targets.')
    124 
    125   return parser
    126 
    127 
    128 def main(argv):
    129   parser = GetHostStepsOptParser()
    130   options, args = parser.parse_args(argv[1:])
    131   if args:
    132     return sys.exit('Unused args %s' % args)
    133 
    134   setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
    135 
    136   if options.steps:
    137     bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options)
    138 
    139 
    140 if __name__ == '__main__':
    141   sys.exit(main(sys.argv))
    142