blob: 1e927fb399ddd2bd61badd428c8f9597c3056bfd [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001#!/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
James Robinson0fae0002015-05-05 16:31:51 -07007import json
James Robinson646469d2014-10-03 15:33:28 -07008import sys
9
10import bb_utils
11import bb_annotations
12
13sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
14from pylib import constants
15
16
17SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
James Robinson0fae0002015-05-05 16:31:51 -070018VALID_HOST_TESTS = set(['check_webview_licenses'])
James Robinson646469d2014-10-03 15:33:28 -070019
20DIR_BUILD_ROOT = os.path.dirname(constants.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(constants.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 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 bb_annotations.PrintNamedStep('compile')
61 if options.build_targets:
62 build_targets = options.build_targets.split(',')
63 cmd += ['--build-args', ' '.join(build_targets)]
64 RunCmd(cmd, halt_on_failure=True, cwd=DIR_BUILD_ROOT)
65
66
67def ZipBuild(options):
68 bb_annotations.PrintNamedStep('zip_build')
69 RunCmd([
70 os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'),
71 '--src-dir', constants.DIR_SOURCE_ROOT,
72 '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests']
73 + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT)
74
75
76def ExtractBuild(options):
77 bb_annotations.PrintNamedStep('extract_build')
78 RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'extract_build.py')]
79 + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT)
80
81
James Robinson646469d2014-10-03 15:33:28 -070082def BisectPerfRegression(options):
83 args = []
84 if options.extra_src:
85 args = ['--extra_src', options.extra_src]
86 RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'),
87 '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)])
88 RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'),
James Robinson0fae0002015-05-05 16:31:51 -070089 '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir),
90 '--build-properties=%s' % json.dumps(options.build_properties)] +
91 args)
James Robinson646469d2014-10-03 15:33:28 -070092
93
94def GetHostStepCmds():
95 return [
96 ('compile', Compile),
97 ('extract_build', ExtractBuild),
98 ('check_webview_licenses', CheckWebViewLicenses),
99 ('bisect_perf_regression', BisectPerfRegression),
James Robinson646469d2014-10-03 15:33:28 -0700100 ('zip_build', ZipBuild)
101 ]
102
103
104def GetHostStepsOptParser():
105 parser = bb_utils.GetParser()
106 parser.add_option('--steps', help='Comma separated list of host tests.')
107 parser.add_option('--build-targets', default='',
108 help='Comma separated list of build targets.')
109 parser.add_option('--experimental', action='store_true',
110 help='Indicate whether to compile experimental targets.')
111 parser.add_option('--extra_src', default='',
112 help='Path to extra source file. If this is supplied, '
113 'bisect script will use it to override default behavior.')
114
115 return parser
116
117
118def main(argv):
119 parser = GetHostStepsOptParser()
120 options, args = parser.parse_args(argv[1:])
121 if args:
122 return sys.exit('Unused args %s' % args)
123
124 setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
125 setattr(options, 'extra_src',
126 options.factory_properties.get('extra_src', ''))
127
128 if options.steps:
129 bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options)
130
131
132if __name__ == '__main__':
133 sys.exit(main(sys.argv))