Chromium Code Reviews| Index: pydir/build-runtime.py |
| diff --git a/pydir/build-runtime.py b/pydir/build-runtime.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a96493e9a69a49ea724717933463957e499182fe |
| --- /dev/null |
| +++ b/pydir/build-runtime.py |
| @@ -0,0 +1,91 @@ |
| +#!/usr/bin/env python2 |
| + |
| +import argparse |
| +import os |
| +import shutil |
| +import tempfile |
| +from utils import shellcmd |
| +from utils import FindBaseNaCl |
| + |
|
jvoung (off chromium)
2015/02/23 17:58:36
Usually nacl/chrome py files have 2 space indent,
Jim Stichnoth
2015/02/23 21:38:19
Yeah, I tried to fit in with the existing files. :
|
| +def Translate(ll_files, extra_args, obj, verbose): |
| + """Translate a set of input bitcode files into a single object file. |
| + |
| + Use pnacl-llc to translate textual bitcode input ll_files into object file |
| + obj, using extra_args as the architectural flags. |
| + """ |
| + shellcmd(['cat'] + ll_files + ['|', |
| + 'pnacl-llc', |
| + '-externalize', |
| + '-filetype=obj', |
| + '-bitcode-format=llvm', |
| + '-o', obj |
| + ] + extra_args, echo=verbose) |
| + shellcmd(['objcopy', |
| + '--localize-symbol=nacl_tp_tdb_offset', |
| + '--localize-symbol=nacl_tp_tls_offset', |
| + obj |
| + ], echo=verbose) |
| + |
| +def main(): |
| + """Build the Subzero runtime support library for all architectures. |
| + """ |
| + argparser = argparse.ArgumentParser( |
| + description=' ' + main.__doc__, |
| + formatter_class=argparse.RawTextHelpFormatter) |
| + argparser.add_argument('--verbose', '-v', dest='verbose', |
| + action='store_true', |
| + help='Display some extra debugging output') |
| + args = argparser.parse_args() |
| + nacl_root = FindBaseNaCl() |
| + os.environ['PATH'] = ( |
| + '{root}/toolchain/linux_x86/pnacl_newlib/bin{sep}' + |
| + '{path}' |
| + ).format(root=nacl_root, sep=os.pathsep, path=os.environ['PATH']) |
| + srcdir = ( |
| + '{root}/toolchain_build/src/subzero/runtime' |
| + ).format(root=nacl_root) |
| + rtdir = ( |
| + '{root}/toolchain_build/src/subzero/build/runtime' |
| + ).format(root=nacl_root) |
| + try: |
| + tempdir = tempfile.mkdtemp() |
| + shellcmd(['mkdir', |
|
jvoung (off chromium)
2015/02/23 17:58:36
Could have done os.makedirs() instead of shelling
Jim Stichnoth
2015/02/23 21:38:19
Done. I don't care that much about logging this p
jvoung (off chromium)
2015/02/23 23:58:38
Hmm actually, compared to "mkdir -p", you'll may n
Jim Stichnoth
2015/02/24 00:37:57
Oh, good point. Fixed it to check for the directo
|
| + '-p', |
| + rtdir |
| + ], echo=args.verbose) |
| + # Compile srcdir/szrt.c to tempdir/szrt.ll |
| + shellcmd(['pnacl-clang', |
| + '-O2', |
| + '-c', |
| + '{srcdir}/szrt.c'.format(srcdir=srcdir), |
| + '-o', '{dir}/szrt.tmp.bc'.format(dir=tempdir) |
| + ], echo=args.verbose) |
| + shellcmd(['pnacl-opt', |
| + '-pnacl-abi-simplify-preopt', |
| + '-pnacl-abi-simplify-postopt', |
| + '-pnaclabi-allow-debug-metadata', |
| + '{dir}/szrt.tmp.bc'.format(dir=tempdir), |
| + '-S', |
| + '-o', '{dir}/szrt.ll'.format(dir=tempdir) |
| + ], echo=args.verbose) |
| + ll_files = ['{dir}/szrt.ll'.format(dir=tempdir), |
| + '{srcdir}/szrt_ll.ll'.format(srcdir=srcdir)] |
| + # Translate tempdir/szrt.ll and srcdir/szrt_ll.ll to szrt_native_x8632.o |
| + Translate(ll_files, |
| + ['-mtriple=i386-unknown-linux-gnu', '-mcpu=pentium4m'], |
| + '{rtdir}/szrt_native_x8632.o'.format(rtdir=rtdir), |
| + args.verbose) |
| + # Translate tempdir/szrt.ll and srcdir/szrt_ll.ll to szrt_sb_x8632.o |
| + Translate(ll_files, |
| + ['-mtriple=i686-none-nacl-gnu', '-mcpu=pentium4m'], |
| + '{rtdir}/szrt_sb_x8632.o'.format(rtdir=rtdir), |
| + args.verbose) |
| + finally: |
| + try: |
| + shutil.rmtree(tempdir) |
| + except OSError as exc: |
| + if exc.errno != errno.ENOENT: # ENOENT - no such file or directory |
| + raise # re-raise exception |
| + |
| +if __name__ == '__main__': |
| + main() |