2 # Copyright (c) 2013 The Native Client 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.
15 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
16 NACL_DIR = os.path.dirname(SCRIPT_DIR)
18 # As this is a buildbot script, we want verbose logging. Note however, that
19 # toolchain_build has its own log settings, controlled by its CLI flags.
20 logging.getLogger().setLevel(logging.DEBUG)
22 parser = argparse.ArgumentParser(description='PNaCl toolchain buildbot script')
23 group = parser.add_mutually_exclusive_group()
24 group.add_argument('--buildbot', action='store_true',
25 help='Buildbot mode (build and archive the toolchain)')
26 group.add_argument('--trybot', action='store_true',
27 help='Trybot mode (build but do not archove the toolchain)')
28 args = parser.parse_args()
30 host_os = buildbot_lib.GetHostPlatform()
32 # This is a minimal context, not useful for running tests yet, but enough for
33 # basic Step handling.
34 context = buildbot_lib.BuildContext()
35 status = buildbot_lib.BuildStatus(context)
37 with buildbot_lib.Step('Update cygwin/check bash', status, halt_on_fail=True):
38 # Update cygwin if necessary.
40 if sys.platform == 'cygwin':
41 print 'This script does not support running from inside cygwin!'
43 subprocess.check_call(os.path.join(SCRIPT_DIR, 'cygwin_env.bat'))
44 print os.environ['PATH']
45 paths = os.environ['PATH'].split(os.pathsep)
46 # Put path to cygwin tools at the beginning, so cygwin tools like python
47 # and cmake will supercede others (which do not understand cygwin paths)
48 paths = [os.path.join(NACL_DIR, 'cygwin', 'bin')] + paths
50 os.environ['PATH'] = os.pathsep.join(paths)
51 print os.environ['PATH']
52 bash = os.path.join(NACL_DIR, 'cygwin', 'bin', 'bash')
54 # Assume bash is in the path
60 subprocess.check_call([bash , '--version'])
61 except subprocess.CalledProcessError:
62 print 'Bash not found in path!'
63 raise buildbot_lib.StepFailed()
65 toolchain_build_cmd = [
68 NACL_DIR, 'toolchain_build', 'toolchain_build_pnacl.py'),
69 '--verbose', '--sync', '--clobber']
71 # Sync the git repos used by build.sh
72 with buildbot_lib.Step('Sync build.sh repos', status, halt_on_fail=True):
73 buildbot_lib.Command(context, toolchain_build_cmd + ['--legacy-repo-sync'])
75 # Run toolchain_build.py first. Its outputs are not actually being used yet.
76 # toolchain_build outputs its own buildbot annotations, so don't use
77 # buildbot_lib.Step to run it here.
81 gsd_arg = ['--buildbot']
83 gsd_arg = ['--trybot']
85 cmd = toolchain_build_cmd + gsd_arg
86 logging.info('Running: ' + ' '.join(cmd))
87 subprocess.check_call(cmd)
88 except subprocess.CalledProcessError:
89 # Ignore any failures and keep going (but make the bot stage red).
91 print '@@@STEP_WARNINGS@@@'
93 print '@@@STEP_FAILURE@@@'
97 # Now we run the PNaCl buildbot script. It in turn runs the PNaCl build.sh
98 # script and runs scons tests.
99 # TODO(dschuff): re-implement the test-running portion of buildbot_pnacl.sh
100 # using buildbot_lib, and use them here and in the non-toolchain builder.
101 buildbot_shell = os.path.join(NACL_DIR, 'buildbot', 'buildbot_pnacl.sh')
103 # Because patching mangles the shell script on the trybots, fix it up here
104 # so we can have working windows trybots.
106 with open(f, 'rb') as script:
107 data = script.read().replace('\r\n', '\n')
108 with open(f, 'wb') as script:
112 FixCRLF(buildbot_shell)
113 FixCRLF(os.path.join(NACL_DIR, 'pnacl', 'build.sh'))
114 FixCRLF(os.path.join(NACL_DIR, 'pnacl', 'scripts', 'common-tools.sh'))
116 # Generate flags for buildbot_pnacl.sh
117 if host_os == 'linux':
119 # TODO(dschuff): Figure out if it makes sense to import the utilities from
120 # build/ into scripts from buildbot/ or only use things from buildbot_lib,
121 # or unify them in some way.
122 arch = 'x8664' if platform.machine() == 'x86_64' else 'x8632'
123 elif host_os == 'mac':
126 elif host_os == 'win':
130 print 'Unrecognized platform: ', host_os
134 trybot_mode = 'false'
138 platform_arg = 'mode-buildbot-tc-' + arch + '-' + arg_os
144 logging.info('Running: ' + ' '.join(command))
145 subprocess.check_call(command)