Skip to content

Commit 1b8e2c0

Browse files
authored
Minor cleanups to emscripten.py (emscripten-core#6414)
- use """ for docstrings. - don't overuse default args. In this case they are always specified. - libaries can never be None so don't check this.
1 parent 53bba7e commit 1b8e2c0

2 files changed

Lines changed: 16 additions & 29 deletions

File tree

emscripten.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#!/usr/bin/env python2
2-
3-
'''
4-
You should normally never use this! Use emcc instead.
2+
"""You should normally never use this! Use emcc instead.
53
64
This is a small wrapper script around the core JS compiler. This calls that
75
compiler with the settings given to it. It can also read data from C/C++
86
header files (so that the JS compiler can see the constants in those
97
headers, for the libc implementation in JS).
10-
'''
8+
"""
119

1210
from tools.toolchain_profiler import ToolchainProfiler
1311
if __name__ == '__main__':
@@ -61,8 +59,8 @@ def access_quote(prop):
6159
return access_quote
6260

6361

64-
def emscript(infile, settings, outfile, libraries=None, compiler_engine=None,
65-
temp_files=None, DEBUG=None):
62+
def emscript(infile, settings, outfile, libraries, compiler_engine, temp_files,
63+
DEBUG):
6664
"""Runs the emscripten LLVM-to-JS compiler.
6765
6866
Args:
@@ -72,8 +70,6 @@ def emscript(infile, settings, outfile, libraries=None, compiler_engine=None,
7270
outfile: The file where the output is written.
7371
"""
7472

75-
if libraries is None: libraries = []
76-
7773
assert settings['ASM_JS'], 'fastcomp is asm.js-only (mode 1 or 2)'
7874

7975
success = False
@@ -1738,15 +1734,13 @@ def coerce(self, expression):
17381734
]
17391735

17401736

1741-
def emscript_wasm_backend(infile, settings, outfile, libraries=None, compiler_engine=None,
1742-
temp_files=None, DEBUG=None):
1737+
def emscript_wasm_backend(infile, settings, outfile, libraries, compiler_engine,
1738+
temp_files, DEBUG):
17431739
# Overview:
17441740
# * Run LLVM backend to emit .s
17451741
# * Run Binaryen's s2wasm to generate WebAssembly.
17461742
# * We may also run some Binaryen passes here.
17471743

1748-
if libraries is None: libraries = []
1749-
17501744
if shared.Settings.EXPERIMENTAL_USE_LLD:
17511745
wasm, metadata = build_wasm_lld(temp_files, infile, outfile, settings, DEBUG)
17521746
else:
@@ -2232,11 +2226,6 @@ def asmjs_mangle(name):
22322226
return '_' + ''.join(['_' if not c.isalnum() else c for c in name])
22332227

22342228

2235-
if os.environ.get('EMCC_FAST_COMPILER') == '0':
2236-
logging.critical('Non-fastcomp compiler is no longer available, please use fastcomp or an older version of emscripten')
2237-
sys.exit(1)
2238-
2239-
22402229
def normalize_line_endings(text):
22412230
"""Normalize to UNIX line endings.
22422231
@@ -2256,7 +2245,7 @@ def main(args, compiler_engine, cache, temp_files, DEBUG):
22562245
settings[name] = asstr(value)
22572246

22582247
# libraries
2259-
libraries = args.libraries[0].split(',') if len(args.libraries) > 0 else []
2248+
libraries = args.libraries[0].split(',') if len(args.libraries) else []
22602249

22612250
settings.setdefault('STRUCT_INFO', shared.path_from_root('src', 'struct_info.compiled.json'))
22622251
struct_info = settings['STRUCT_INFO']
@@ -2272,17 +2261,13 @@ def main(args, compiler_engine, cache, temp_files, DEBUG):
22722261
temp_files=temp_files, DEBUG=DEBUG)
22732262

22742263

2275-
def _main(args=None):
2276-
if args is None:
2277-
args = sys.argv[1:]
2278-
2264+
def _main(args):
22792265
substitute_response_files(args)
22802266

22812267
parser = argparse.ArgumentParser(
22822268
usage='%(prog)s [-h] [-H HEADERS] [-o OUTFILE] [-c COMPILER_ENGINE] [-s FOO=BAR]* infile',
22832269
description=('You should normally never use this! Use emcc instead. '
2284-
'This is a wrapper around the JS compiler, converting .ll to .js.'),
2285-
epilog='')
2270+
'This is a wrapper around the JS compiler, converting .ll to .js.'))
22862271
parser.add_argument('-H', '--headers',
22872272
default=[],
22882273
action='append',
@@ -2335,7 +2320,9 @@ def _main(args=None):
23352320
''')
23362321

23372322
if len(positional) != 1:
2338-
raise RuntimeError('Must provide exactly one positional argument. Got ' + str(len(positional)) + ': "' + '", "'.join(positional) + '"')
2323+
logging.error('Must provide exactly one positional argument. Got ' + str(len(positional)) + ': "' + '", "'.join(positional) + '"')
2324+
return 1
2325+
23392326
keywords.infile = os.path.abspath(positional[0])
23402327
if isinstance(keywords.outfile, (type(u''), bytes)):
23412328
keywords.outfile = open(keywords.outfile, 'w')
@@ -2365,7 +2352,7 @@ def _main(args=None):
23652352
temp_files=temp_files,
23662353
DEBUG=DEBUG,
23672354
))
2355+
return 0
23682356

23692357
if __name__ == '__main__':
2370-
_main()
2371-
sys.exit(0)
2358+
sys.exit(_main(sys.argv[1:]))

tools/shared.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,15 +1998,15 @@ def emscripten(filename, append_ext=True, extra_args=[]):
19981998

19991999
if path_from_root() not in sys.path:
20002000
sys.path += [path_from_root()]
2001-
from emscripten import _main as call_emscripten
2001+
import emscripten
20022002
# Run Emscripten
20032003
settings = Settings.serialize()
20042004
args = settings + extra_args
20052005
cmdline = [filename + ('.o.ll' if append_ext else ''), '-o', filename + '.o.js'] + args
20062006
if jsrun.TRACK_PROCESS_SPAWNS:
20072007
logging.info('Executing emscripten.py compiler with cmdline "' + ' '.join(cmdline) + '"')
20082008
with ToolchainProfiler.profile_block('emscripten.py'):
2009-
call_emscripten(cmdline)
2009+
emscripten._main(cmdline)
20102010

20112011
# Detect compilation crashes and errors
20122012
assert os.path.exists(filename + '.o.js'), 'Emscripten failed to generate .js'

0 commit comments

Comments
 (0)