1#!/usr/bin/env python
2# Copyright (c) 2012 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"""Main entry point for the NaCl SDK buildbot.
7
8The entry point used to be build_sdk.py itself, but we want
9to be able to simplify build_sdk (for example separating out
10the test code into test_sdk) and change its default behaviour
11while being able to separately control excactly what the bots
12run.
13"""
14
15import buildbot_common
16import os
17import subprocess
18import sys
19
20from buildbot_common import Run
21from build_paths import SRC_DIR, SDK_SRC_DIR, SCRIPT_DIR
22import getos
23
24
25def StepRunUnittests():
26  buildbot_common.BuildStep('Run unittests')
27
28  # Our tests shouldn't be using the proxy; they should all be connecting to
29  # localhost. Some slaves can't route HTTP traffic through the proxy to
30  # localhost (we get 504 gateway errors), so we clear it here.
31  env = dict(os.environ)
32  if 'http_proxy' in env:
33    del env['http_proxy']
34
35  Run([sys.executable, 'test_all.py'], env=env, cwd=SDK_SRC_DIR)
36
37
38def StepBuildSDK():
39  is_win = getos.GetPlatform() == 'win'
40
41  # Windows has a path length limit of 255 characters, after joining cwd with a
42  # relative path. Use subst before building to keep the path lengths short.
43  if is_win:
44    subst_drive = 'S:'
45    root_dir = os.path.dirname(SRC_DIR)
46    new_root_dir = subst_drive + '\\'
47    subprocess.check_call(['subst', subst_drive, root_dir])
48    new_script_dir = os.path.join(new_root_dir,
49                                  os.path.relpath(SCRIPT_DIR, root_dir))
50  else:
51    new_script_dir = SCRIPT_DIR
52
53  try:
54    Run([sys.executable, 'build_sdk.py'], cwd=new_script_dir)
55  finally:
56    if is_win:
57      subprocess.check_call(['subst', '/D', subst_drive])
58
59
60def StepTestSDK():
61  cmd = []
62  if getos.GetPlatform() == 'linux':
63    # Run all of test_sdk.py under xvfb-run; it's startup time leaves something
64    # to be desired, so only start it up once.
65    # We also need to make sure that there are at least 24 bits per pixel.
66    # https://code.google.com/p/chromium/issues/detail?id=316687
67    cmd.extend([
68        'xvfb-run',
69        '--auto-servernum',
70        '--server-args', '-screen 0 1024x768x24'
71    ])
72
73  cmd.extend([sys.executable, 'test_sdk.py'])
74  Run(cmd, cwd=SCRIPT_DIR)
75
76
77def main():
78  StepRunUnittests()
79  StepBuildSDK()
80  # Skip the testing phase if we are running on a build-only bots.
81  if not buildbot_common.IsBuildOnlyBot():
82    StepTestSDK()
83  return 0
84
85
86if __name__ == '__main__':
87  try:
88    sys.exit(main())
89  except KeyboardInterrupt:
90    buildbot_common.ErrorExit('buildbot_run: interrupted')
91