summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/build_tools/buildbot_run.py
blob: b58df097d8356c2b4c90fc20bcfb5983231628a4 (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
#!/usr/bin/env python
# Copyright (c) 2012 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.

"""Main entry point for the NaCl SDK buildbot.

The entry point used to be build_sdk.py itself, but we want
to be able to simplify build_sdk (for example separating out
the test code into test_sdk) and change its default behaviour
while being able to separately control excactly what the bots
run.
"""

import buildbot_common
import os
import subprocess
import sys

from buildbot_common import Run
from build_paths import SRC_DIR, SDK_SRC_DIR, SCRIPT_DIR
import getos


def StepRunUnittests():
  buildbot_common.BuildStep('Run unittests')

  # Our tests shouldn't be using the proxy; they should all be connecting to
  # localhost. Some slaves can't route HTTP traffic through the proxy to
  # localhost (we get 504 gateway errors), so we clear it here.
  env = dict(os.environ)
  if 'http_proxy' in env:
    del env['http_proxy']

  Run([sys.executable, 'test_all.py'], env=env, cwd=SDK_SRC_DIR)


def StepBuildSDK(args):
  is_win = getos.GetPlatform() == 'win'

  # Windows has a path length limit of 255 characters, after joining cwd with a
  # relative path. Use subst before building to keep the path lengths short.
  if is_win:
    subst_drive = 'S:'
    root_dir = os.path.dirname(SRC_DIR)
    new_root_dir = subst_drive + '\\'
    subprocess.check_call(['subst', subst_drive, root_dir])
    new_script_dir = os.path.join(new_root_dir,
                                  os.path.relpath(SCRIPT_DIR, root_dir))
  else:
    new_script_dir = SCRIPT_DIR

  try:
    Run([sys.executable, 'build_sdk.py'] + args, cwd=new_script_dir)
  finally:
    if is_win:
      subprocess.check_call(['subst', '/D', subst_drive])


def StepTestSDK():
  cmd = []
  if getos.GetPlatform() == 'linux':
    # Run all of test_sdk.py under xvfb-run; it's startup time leaves something
    # to be desired, so only start it up once.
    cmd.extend(['xvfb-run', '--auto-servernum'])

  cmd.extend([sys.executable, 'test_sdk.py'])
  Run(cmd, cwd=SCRIPT_DIR)


def main(args):
  StepRunUnittests()
  StepBuildSDK(args)
  StepTestSDK()
  return 0


if __name__ == '__main__':
  try:
    sys.exit(main(sys.argv[1:]))
  except KeyboardInterrupt:
    buildbot_common.ErrorExit('buildbot_run: interrupted')