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 DIR_BUILD_ROOT = os.path.dirname(constants.DIR_SOURCE_ROOT)
     21 
     22 # Short hand for RunCmd which is used extensively in this file.
     23 RunCmd = bb_utils.RunCmd
     24 
     25 
     26 def SrcPath(*path):
     27   return os.path.join(constants.DIR_SOURCE_ROOT, *path)
     28 
     29 
     30 def CheckWebViewLicenses(_):
     31   bb_annotations.PrintNamedStep('check_licenses')
     32   RunCmd([SrcPath('android_webview', 'tools', 'webview_licenses.py'), 'scan'],
     33          warning_code=1)
     34 
     35 
     36 def RunHooks(build_type):
     37   RunCmd([SrcPath('build', 'landmines.py')])
     38   build_path = SrcPath('out', build_type)
     39   landmine_path = os.path.join(build_path, '.landmines_triggered')
     40   clobber_env = os.environ.get('BUILDBOT_CLOBBER')
     41   if clobber_env or os.path.isfile(landmine_path):
     42     bb_annotations.PrintNamedStep('Clobber')
     43     if not clobber_env:
     44       print 'Clobbering due to triggered landmines:'
     45       with open(landmine_path) as f:
     46         print f.read()
     47     RunCmd(['rm', '-rf', build_path])
     48 
     49   bb_annotations.PrintNamedStep('runhooks')
     50   RunCmd(['gclient', 'runhooks'], halt_on_failure=True)
     51 
     52 
     53 def Compile(options):
     54   RunHooks(options.target)
     55   cmd = [os.path.join(SLAVE_SCRIPTS_DIR, 'compile.py'),
     56          '--build-tool=ninja',
     57          '--compiler=goma',
     58          '--target=%s' % options.target,
     59          '--goma-dir=%s' % bb_utils.GOMA_DIR]
     60   build_targets = options.build_targets.split(',')
     61   bb_annotations.PrintNamedStep('compile')
     62   for build_target in build_targets:
     63     RunCmd(cmd + ['--build-args=%s' % build_target],
     64         halt_on_failure=True,
     65         cwd=DIR_BUILD_ROOT)
     66   if options.experimental:
     67     for compile_target in EXPERIMENTAL_TARGETS:
     68       bb_annotations.PrintNamedStep('Experimental Compile %s' % compile_target)
     69       RunCmd(cmd + ['--build-args=%s' % compile_target],
     70              flunk_on_failure=False,
     71              cwd=DIR_BUILD_ROOT)
     72 
     73 
     74 def ZipBuild(options):
     75   bb_annotations.PrintNamedStep('zip_build')
     76   RunCmd([
     77       os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'),
     78       '--src-dir', constants.DIR_SOURCE_ROOT,
     79       '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests']
     80       + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT)
     81 
     82 
     83 def ExtractBuild(options):
     84   bb_annotations.PrintNamedStep('extract_build')
     85   RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'extract_build.py')]
     86          + bb_utils.EncodeProperties(options),
     87          warning_code=1, cwd=DIR_BUILD_ROOT)
     88 
     89 
     90 def FindBugs(options):
     91   bb_annotations.PrintNamedStep('findbugs')
     92   build_type = []
     93   if options.target == 'Release':
     94     build_type = ['--release-build']
     95   RunCmd([SrcPath('build', 'android', 'findbugs_diff.py')] + build_type)
     96   RunCmd([SrcPath(
     97       'tools', 'android', 'findbugs_plugin', 'test',
     98       'run_findbugs_plugin_tests.py')] + build_type)
     99 
    100 
    101 def BisectPerfRegression(_):
    102   RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'),
    103           '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)])
    104   RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'),
    105           '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)])
    106 
    107 
    108 def GetHostStepCmds():
    109   return [
    110       ('compile', Compile),
    111       ('extract_build', ExtractBuild),
    112       ('check_webview_licenses', CheckWebViewLicenses),
    113       ('bisect_perf_regression', BisectPerfRegression),
    114       ('findbugs', FindBugs),
    115       ('zip_build', ZipBuild)
    116   ]
    117 
    118 
    119 def GetHostStepsOptParser():
    120   parser = bb_utils.GetParser()
    121   parser.add_option('--steps', help='Comma separated list of host tests.')
    122   parser.add_option('--build-targets', default='All',
    123                     help='Comma separated list of build targets.')
    124   parser.add_option('--experimental', action='store_true',
    125                     help='Indicate whether to compile experimental targets.')
    126 
    127   return parser
    128 
    129 
    130 def main(argv):
    131   parser = GetHostStepsOptParser()
    132   options, args = parser.parse_args(argv[1:])
    133   if args:
    134     return sys.exit('Unused args %s' % args)
    135 
    136   setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
    137 
    138   if options.steps:
    139     bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options)
    140 
    141 
    142 if __name__ == '__main__':
    143   sys.exit(main(sys.argv))
    144