diff options
author | max99x <max99x@gmail.com> | 2011-07-13 22:30:29 +0300 |
---|---|---|
committer | max99x <max99x@gmail.com> | 2011-07-13 22:30:29 +0300 |
commit | 9ee300c1906aae24e1a27521c7a0ef5e461efded (patch) | |
tree | 3f3ad341ea9fae89c7581c0402a094208e9367de | |
parent | fcacb4c13c73f2febfa7dabe2ffc70c727ea7762 (diff) |
Switched from argparse to optparse in emscripten.py, for older Python.
-rwxr-xr-x | emscripten.py | 61 | ||||
-rw-r--r-- | tests/runner.py | 4 |
2 files changed, 36 insertions, 29 deletions
diff --git a/emscripten.py b/emscripten.py index 6fe7b504..b77c361d 100755 --- a/emscripten.py +++ b/emscripten.py @@ -1,12 +1,12 @@ #!/usr/bin/python -import argparse import json +import optparse import os import subprocess import sys import tempfile -import tools.shared as shared +from tools import shared # Temporary files that should be deleted once the program is finished. @@ -173,7 +173,7 @@ def main(args): # Prepare settings for serialization to JSON. settings = {} for setting in args.settings: - name, value = setting.split('=', 1) + name, value = setting.strip().split('=', 1) settings[name] = json.loads(value) # Adjust sign correction for dlmalloc. @@ -192,33 +192,40 @@ def main(args): if __name__ == '__main__': - parser = argparse.ArgumentParser( - description='Compile LLVM assembly to Javascript.', + parser = optparse.OptionParser( + usage='usage: %prog [-h] [-O] [-m] [-o OUTFILE] [-s FOO=BAR]* infile', + description=('Compile an LLVM assembly file to Javascript. Accepts both ' + 'human-readable (*.ll) and bitcode (*.bc) formats.'), epilog='You should have an ~/.emscripten file set up; see settings.py.') - parser.add_argument('infile', - help='The LLVM assembly file to compile, either in ' - 'human-readable (*.ll) or in bitcode (*.bc) format.') - parser.add_argument('-O', '--optimize', - default=False, - action='store_true', - help='Run LLVM optimizations on the input.') - parser.add_argument('-m', '--dlmalloc', - default=False, - action='store_true', - help='Use dlmalloc. Without, uses a dummy allocator.') - parser.add_argument('-o', '--outfile', - default=sys.stdout, - type=argparse.FileType('w'), - help='Where to write the output; defaults to stdout.') - parser.add_argument('-s', '--settings', - default=[], - nargs=argparse.ZERO_OR_MORE, - metavar='FOO=BAR', - help='Overrides for settings defined in settings.js.') + parser.add_option('-O', '--optimize', + default=False, + action='store_true', + help='Run LLVM optimizations on the input.') + parser.add_option('-m', '--dlmalloc', + default=False, + action='store_true', + help='Use dlmalloc. Without, uses a dummy allocator.') + parser.add_option('-o', '--outfile', + default=sys.stdout, + help='Where to write the output; defaults to stdout.') + parser.add_option('-s', '--setting', + dest='settings', + default=[], + action='append', + metavar='FOO=BAR', + help=('Overrides for settings defined in settings.js. ' + 'May occur multiple times.')) + + # Convert to the same format that argparse would have produced. + keywords, positional = parser.parse_args() + if len(positional) != 1: + raise RuntimeError('Must provide exactly one positional argument.') + keywords.infile = positional[0] + if isinstance(keywords.outfile, basestring): + keywords.outfile = open(keywords.outfile, 'w') try: - main(parser.parse_args()) + main(keywords) finally: - # Clean up temporary files. for filename in TEMP_FILES_TO_CLEAN: os.unlink(filename) diff --git a/tests/runner.py b/tests/runner.py index e21a74a5..ede51756 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -179,8 +179,8 @@ class RunnerCore(unittest.TestCase): exported_settings[setting] = value except: pass - settings = ['%s=%s' % (k, json.dumps(v)) for k, v in exported_settings.items()] - compiler_output = timeout_run(Popen([EMSCRIPTEN, filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js', '-s'] + settings + extra_args, stdout=PIPE, stderr=STDOUT), TIMEOUT, 'Compiling') + settings = ['-s %s=%s' % (k, json.dumps(v)) for k, v in exported_settings.items()] + compiler_output = timeout_run(Popen([EMSCRIPTEN, filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js'] + settings + extra_args, stdout=PIPE, stderr=STDOUT), TIMEOUT, 'Compiling') # Detect compilation crashes and errors if compiler_output is not None and 'Traceback' in compiler_output and 'in test_' in compiler_output: print compiler_output; assert 0 |