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
9 # Done first to set up python module path
19 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
20 NACL_DIR = os.path.dirname(SCRIPT_DIR)
23 DRIVER_TOOLS = ['pnacl-' + tool + '.py' for tool in
24 ('abicheck', 'ar', 'as', 'clang', 'clang++', 'compress', 'dis',
25 'driver', 'finalize', 'ld', 'nativeld', 'nm', 'opt',
26 'ranlib', 'readelf', 'strip', 'translate')]
27 # Utilities used by the driver
28 DRIVER_UTILS = [name + '.py' for name in
29 ('artools', 'driver_env', 'driver_log', 'driver_tools',
30 'elftools', 'filetype', 'ldtools', 'loader', 'pathtools',
33 def InstallDriverScripts(subst, srcdir, dstdir, host_windows=False,
34 host_64bit=False, extra_config=[]):
35 srcdir = subst.SubstituteAbsPaths(srcdir)
36 dstdir = subst.SubstituteAbsPaths(dstdir)
37 file_tools.MakeDirectoryIfAbsent(os.path.join(dstdir, 'pydir'))
38 for name in DRIVER_TOOLS + DRIVER_UTILS:
39 shutil.copy(os.path.join(srcdir, name), os.path.join(dstdir, 'pydir'))
40 # Install redirector sh/bat scripts
41 for name in DRIVER_TOOLS:
42 # Chop the .py off the name
43 nopy_name = os.path.join(dstdir, os.path.splitext(name)[0])
44 shutil.copy(os.path.join(srcdir, 'redirect.sh'), nopy_name)
46 stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR | stat.S_IRGRP |
47 stat.S_IWGRP | stat.S_IXGRP)
50 # Windows gets both sh and bat extensions so it works w/cygwin and without
51 batch_script = nopy_name + '.bat'
52 shutil.copy(os.path.join(srcdir, 'redirect.bat'), batch_script)
53 os.chmod(batch_script,
54 stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR | stat.S_IRGRP |
55 stat.S_IWGRP | stat.S_IXGRP)
56 # Install the driver.conf file
57 with open(os.path.join(dstdir, 'driver.conf'), 'w') as f:
58 print >> f, 'HAS_FRONTEND=1'
59 print >> f, 'HOST_ARCH=x86_64' if host_64bit else 'HOST_ARCH=x86_32'
60 for line in extra_config:
61 print >> f, subst.Substitute(line)
62 # Install the REV file
63 with open(os.path.join(dstdir, 'REV'), 'w') as f:
65 url, rev = repo_tools.GitRevInfo(NACL_DIR)
67 except subprocess.CalledProcessError:
68 url, rev = repo_tools.SvnRevInfo(NACL_DIR)
70 print >> f, '[%s] %s: %s' % (repotype, url, rev)