Home | History | Annotate | Download | only in build_tools
      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 
      8 The entry point used to be build_sdk.py itself, but we want
      9 to be able to simplify build_sdk (for example separating out
     10 the test code into test_sdk) and change its default behaviour
     11 while being able to separately control excactly what the bots
     12 run.
     13 """
     14 
     15 import buildbot_common
     16 import os
     17 import subprocess
     18 import sys
     19 
     20 from buildbot_common import Run
     21 from build_paths import SRC_DIR, SDK_SRC_DIR, SCRIPT_DIR
     22 import getos
     23 
     24 
     25 def 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 
     38 def StepBuildSDK(args):
     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'] + args, cwd=new_script_dir)
     55   finally:
     56     if is_win:
     57       subprocess.check_call(['subst', '/D', subst_drive])
     58 
     59 
     60 def 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     cmd.extend(['xvfb-run', '--auto-servernum'])
     66 
     67   cmd.extend([sys.executable, 'test_sdk.py'])
     68   Run(cmd, cwd=SCRIPT_DIR)
     69 
     70 
     71 def main(args):
     72   StepRunUnittests()
     73   StepBuildSDK(args)
     74   StepTestSDK()
     75   return 0
     76 
     77 
     78 if __name__ == '__main__':
     79   try:
     80     sys.exit(main(sys.argv[1:]))
     81   except KeyboardInterrupt:
     82     buildbot_common.ErrorExit('buildbot_run: interrupted')
     83