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.
6 """Runnables for toolchain_build_pnacl.py
16 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
17 import pynacl.file_tools
18 import pynacl.repo_tools
21 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
22 NACL_DIR = os.path.dirname(SCRIPT_DIR)
25 DRIVER_TOOLS = ['pnacl-' + tool + '.py' for tool in
26 ('abicheck', 'ar', 'as', 'clang', 'clang++', 'compress', 'dis',
27 'driver', 'finalize', 'ld', 'nativeld', 'nm', 'opt',
28 'ranlib', 'readelf', 'strip', 'translate')]
29 # Utilities used by the driver
30 DRIVER_UTILS = [name + '.py' for name in
31 ('artools', 'driver_env', 'driver_log', 'driver_temps',
32 'driver_tools', 'elftools', 'filetype', 'ldtools',
33 'loader', 'pathtools', 'shelltools')]
35 def InstallDriverScripts(subst, srcdir, dstdir, host_windows=False,
36 host_64bit=False, extra_config=[]):
37 srcdir = subst.SubstituteAbsPaths(srcdir)
38 dstdir = subst.SubstituteAbsPaths(dstdir)
39 pynacl.file_tools.MakeDirectoryIfAbsent(os.path.join(dstdir, 'pydir'))
40 for name in DRIVER_TOOLS + DRIVER_UTILS:
41 shutil.copy(os.path.join(srcdir, name), os.path.join(dstdir, 'pydir'))
42 # Install redirector sh/bat scripts
43 for name in DRIVER_TOOLS:
44 # Chop the .py off the name
45 nopy_name = os.path.join(dstdir, os.path.splitext(name)[0])
46 shutil.copy(os.path.join(srcdir, 'redirect.sh'), nopy_name)
48 stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR | stat.S_IRGRP |
49 stat.S_IWGRP | stat.S_IXGRP)
52 # Windows gets both sh and bat extensions so it works w/cygwin and without
53 batch_script = nopy_name + '.bat'
54 shutil.copy(os.path.join(srcdir, 'redirect.bat'), batch_script)
55 os.chmod(batch_script,
56 stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR | stat.S_IRGRP |
57 stat.S_IWGRP | stat.S_IXGRP)
58 # Install the driver.conf file
59 with open(os.path.join(dstdir, 'driver.conf'), 'w') as f:
60 print >> f, 'HAS_FRONTEND=1'
61 print >> f, 'HOST_ARCH=x86_64' if host_64bit else 'HOST_ARCH=x86_32'
62 for line in extra_config:
63 print >> f, subst.Substitute(line)
64 # Install the REV file
65 with open(os.path.join(dstdir, 'REV'), 'w') as f:
67 url, rev = pynacl.repo_tools.GitRevInfo(NACL_DIR)
69 except subprocess.CalledProcessError:
70 url, rev = pynacl.repo_tools.SvnRevInfo(NACL_DIR)
72 print >> f, '[%s] %s: %s' % (repotype, url, rev)
75 def CheckoutGitBundleForTrybot(repo, destination):
76 # For testing LLVM, Clang, etc. changes on the trybots, look for a
77 # Git bundle file created by llvm_change_try_helper.sh.
78 bundle_file = os.path.join(NACL_DIR, 'pnacl', 'not_for_commit',
80 base64_file = '%s.b64' % bundle_file
81 if os.path.exists(base64_file):
82 input_fh = open(base64_file, 'r')
83 output_fh = open(bundle_file, 'wb')
84 base64.decode(input_fh, output_fh)
87 subprocess.check_call(
88 pynacl.repo_tools.GitCmd() + ['fetch'],
91 subprocess.check_call(
92 pynacl.repo_tools.GitCmd() + ['bundle', 'unbundle', bundle_file],
95 commit_id_file = os.path.join(NACL_DIR, 'pnacl', 'not_for_commit',
96 '%s_commit_id' % repo)
97 commit_id = open(commit_id_file, 'r').readline().strip()
98 subprocess.check_call(
99 pynacl.repo_tools.GitCmd() + ['checkout', commit_id],
103 def CmdCheckoutGitBundleForTrybot(subst, repo, destination):
104 return CheckoutGitBundleForTrybot(repo, subst.SubstituteAbsPaths(destination))