summaryrefslogtreecommitdiffstats
path: root/build/android/buildbot/bb_host_steps.py
blob: 48d2d9a437a12cc930c1415ddf3e959e470898a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import sys

import bb_utils
import bb_annotations

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from pylib import constants


SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
VALID_HOST_TESTS = set(['check_webview_licenses', 'findbugs'])

DIR_BUILD_ROOT = os.path.dirname(constants.DIR_SOURCE_ROOT)

# Short hand for RunCmd which is used extensively in this file.
RunCmd = bb_utils.RunCmd


def SrcPath(*path):
  return os.path.join(constants.DIR_SOURCE_ROOT, *path)


def CheckWebViewLicenses(_):
  bb_annotations.PrintNamedStep('check_licenses')
  RunCmd([SrcPath('android_webview', 'tools', 'webview_licenses.py'), 'scan'],
         warning_code=1)


def RunHooks(build_type):
  RunCmd([SrcPath('build', 'landmines.py')])
  build_path = SrcPath('out', build_type)
  landmine_path = os.path.join(build_path, '.landmines_triggered')
  clobber_env = os.environ.get('BUILDBOT_CLOBBER')
  if clobber_env or os.path.isfile(landmine_path):
    bb_annotations.PrintNamedStep('Clobber')
    if not clobber_env:
      print 'Clobbering due to triggered landmines:'
      with open(landmine_path) as f:
        print f.read()
    RunCmd(['rm', '-rf', build_path])

  bb_annotations.PrintNamedStep('runhooks')
  RunCmd(['gclient', 'runhooks'], halt_on_failure=True)


def Compile(options):
  RunHooks(options.target)
  cmd = [os.path.join(SLAVE_SCRIPTS_DIR, 'compile.py'),
         '--build-tool=ninja',
         '--compiler=goma',
         '--target=%s' % options.target,
         '--goma-dir=%s' % bb_utils.GOMA_DIR]
  bb_annotations.PrintNamedStep('compile')
  if options.build_targets:
    build_targets = options.build_targets.split(',')
    cmd += ['--build-args', ' '.join(build_targets)]
  RunCmd(cmd, halt_on_failure=True, cwd=DIR_BUILD_ROOT)


def ZipBuild(options):
  bb_annotations.PrintNamedStep('zip_build')
  RunCmd([
      os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'),
      '--src-dir', constants.DIR_SOURCE_ROOT,
      '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests']
      + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT)


def ExtractBuild(options):
  bb_annotations.PrintNamedStep('extract_build')
  RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'extract_build.py')]
         + bb_utils.EncodeProperties(options),
         warning_code=1, cwd=DIR_BUILD_ROOT)


def FindBugs(options):
  _ = options # keeps the linter and findbugs happy, parameter is not used
  bb_annotations.PrintNamedStep('findbugs')
  RunCmd([SrcPath('build', 'android', 'findbugs_diff.py')])
  RunCmd([SrcPath(
      'tools', 'android', 'findbugs_plugin', 'test',
      'run_findbugs_plugin_tests.py')])


def BisectPerfRegression(options):
  args = []
  if options.extra_src:
    args = ['--extra_src', options.extra_src]
  RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'),
          '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)])
  RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'),
          '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)] + args)


def GetHostStepCmds():
  return [
      ('compile', Compile),
      ('extract_build', ExtractBuild),
      ('check_webview_licenses', CheckWebViewLicenses),
      ('bisect_perf_regression', BisectPerfRegression),
      ('findbugs', FindBugs),
      ('zip_build', ZipBuild)
  ]


def GetHostStepsOptParser():
  parser = bb_utils.GetParser()
  parser.add_option('--steps', help='Comma separated list of host tests.')
  parser.add_option('--build-targets', default='',
                    help='Comma separated list of build targets.')
  parser.add_option('--experimental', action='store_true',
                    help='Indicate whether to compile experimental targets.')
  parser.add_option('--extra_src', default='',
                    help='Path to extra source file. If this is supplied, '
                    'bisect script will use it to override default behavior.')

  return parser


def main(argv):
  parser = GetHostStepsOptParser()
  options, args = parser.parse_args(argv[1:])
  if args:
    return sys.exit('Unused args %s' % args)

  setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
  setattr(options, 'extra_src',
          options.factory_properties.get('extra_src', ''))
  constants.SetBuildType(options.target)

  if options.steps:
    bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options)


if __name__ == '__main__':
  sys.exit(main(sys.argv))