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 6import os 7import json 8import sys 9 10import bb_utils 11import bb_annotations 12 13sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 14from pylib.constants import host_paths 15 16 17SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave') 18VALID_HOST_TESTS = set(['check_webview_licenses']) 19 20DIR_BUILD_ROOT = os.path.dirname(host_paths.DIR_SOURCE_ROOT) 21 22# Short hand for RunCmd which is used extensively in this file. 23RunCmd = bb_utils.RunCmd 24 25 26def SrcPath(*path): 27 return os.path.join(host_paths.DIR_SOURCE_ROOT, *path) 28 29 30def CheckWebViewLicenses(_): 31 bb_annotations.PrintNamedStep('check_licenses') 32 RunCmd([SrcPath('android_webview', 'tools', 'webview_licenses.py'), 'scan'], 33 warning_code=1) 34 35 36def 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 53def GenerateBuildFiles(options): 54 cmd = [SrcPath('tools', 'mb', 'mb.py'), 55 'gen', 56 '-m', options.build_properties['mastername'], 57 '-b', options.build_properties['buildername'], 58 '--goma-dir', bb_utils.GOMA_DIR, 59 '//out/%s' % options.target] 60 bb_annotations.PrintNamedStep('generate_build_files') 61 RunCmd(cmd, halt_on_failure=True) 62 63 64def Compile(options): 65 if options.run_mb: 66 os.environ['GYP_CHROMIUM_NO_ACTION'] = '1' 67 RunHooks(options.target) 68 GenerateBuildFiles(options) 69 else: 70 RunHooks(options.target) 71 72 cmd = [os.path.join(SLAVE_SCRIPTS_DIR, 'compile.py'), 73 '--build-tool=ninja', 74 '--compiler=goma', 75 '--target=%s' % options.target, 76 '--goma-dir=%s' % bb_utils.GOMA_DIR] 77 bb_annotations.PrintNamedStep('compile') 78 if options.build_targets: 79 build_targets = options.build_targets.split(',') 80 cmd += ['--build-args', ' '.join(build_targets)] 81 RunCmd(cmd, halt_on_failure=True, cwd=DIR_BUILD_ROOT) 82 83 84def ZipBuild(options): 85 bb_annotations.PrintNamedStep('zip_build') 86 RunCmd([ 87 os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'), 88 '--src-dir', host_paths.DIR_SOURCE_ROOT, 89 '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests'] 90 + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT) 91 92 93def ExtractBuild(options): 94 bb_annotations.PrintNamedStep('extract_build') 95 RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'extract_build.py')] 96 + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT) 97 98 99def BisectPerfRegression(options): 100 args = [] 101 if options.extra_src: 102 args = ['--extra_src', options.extra_src] 103 RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'), 104 '-w', os.path.join(host_paths.DIR_SOURCE_ROOT, os.pardir)]) 105 RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'), 106 '-w', os.path.join(host_paths.DIR_SOURCE_ROOT, os.pardir), 107 '--build-properties=%s' % json.dumps(options.build_properties)] + 108 args) 109 110 111def GetHostStepCmds(): 112 return [ 113 ('compile', Compile), 114 ('extract_build', ExtractBuild), 115 ('check_webview_licenses', CheckWebViewLicenses), 116 ('bisect_perf_regression', BisectPerfRegression), 117 ('zip_build', ZipBuild) 118 ] 119 120 121def GetHostStepsOptParser(): 122 parser = bb_utils.GetParser() 123 parser.add_option('--steps', help='Comma separated list of host tests.') 124 parser.add_option('--build-targets', default='', 125 help='Comma separated list of build targets.') 126 parser.add_option('--experimental', action='store_true', 127 help='Indicate whether to compile experimental targets.') 128 parser.add_option('--extra_src', default='', 129 help='Path to extra source file. If this is supplied, ' 130 'bisect script will use it to override default behavior.') 131 parser.add_option('--run-mb', action='store_true', 132 help='Use mb to generate build files.') 133 134 return parser 135 136 137def main(argv): 138 parser = GetHostStepsOptParser() 139 options, args = parser.parse_args(argv[1:]) 140 if args: 141 return sys.exit('Unused args %s' % args) 142 143 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) 144 setattr(options, 'extra_src', 145 options.factory_properties.get('extra_src', '')) 146 147 if options.steps: 148 bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options) 149 150 151if __name__ == '__main__': 152 sys.exit(main(sys.argv)) 153