Skip to content

Cleaner handling of clusure compiler errors #7313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8594,16 +8594,17 @@ def test_IGNORE_CLOSURE_COMPILER_ERRORS(self):
}
''')

def test(extra=[]):
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-O2', '--closure', '1', '--pre-js', 'pre.js'] + extra)
def test(check, extra=[]):
cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-O2', '--closure', '1', '--pre-js', 'pre.js'] + extra
proc = run_process(cmd, check=check, stderr=PIPE)
if not check:
self.assertNotEqual(proc.returncode, 0)
return proc

failed = False
try:
test()
except:
failed = True
assert failed
test(['-s', 'IGNORE_CLOSURE_COMPILER_ERRORS=1'])
proc = test(check=False)
self.assertContained('ERROR - Variable dupe declared more than once', proc.stderr)
proc = test(check=True, extra=['-s', 'IGNORE_CLOSURE_COMPILER_ERRORS=1'])
self.assertEqual(proc.stderr, '')

def test_toolchain_profiler(self):
environ = os.environ.copy()
Expand Down
12 changes: 7 additions & 5 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2445,14 +2445,15 @@ def closure_compiler(filename, pretty=True):

# Something like this (adjust memory as needed):
# java -Xmx1024m -jar CLOSURE_COMPILER --compilation_level ADVANCED_OPTIMIZATIONS --variable_map_output_file src.cpp.o.js.vars --js src.cpp.o.js --js_output_file src.cpp.o.cc.js
outfile = filename + '.cc.js'
args = [JAVA,
'-Xmx' + (os.environ.get('JAVA_HEAP_SIZE') or '1024m'), # if you need a larger Java heap, use this environment variable
'-jar', CLOSURE_COMPILER,
'--compilation_level', 'ADVANCED_OPTIMIZATIONS',
'--language_in', 'ECMASCRIPT5',
'--externs', CLOSURE_EXTERNS,
# '--variable_map_output_file', filename + '.vars',
'--js', filename, '--js_output_file', filename + '.cc.js']
'--js', filename, '--js_output_file', outfile]
for extern in NODE_EXTERNS:
args.append('--externs')
args.append(extern)
Expand All @@ -2466,11 +2467,12 @@ def closure_compiler(filename, pretty=True):
if os.environ.get('EMCC_CLOSURE_ARGS'):
args += shlex.split(os.environ.get('EMCC_CLOSURE_ARGS'))
logging.debug('closure compiler: ' + ' '.join(args))
process = run_process(args, stdout=PIPE, stderr=STDOUT, check=False)
if process.returncode != 0 or not os.path.exists(filename + '.cc.js'):
raise Exception('closure compiler error: ' + process.stdout + ' (rc: %d)' % process.returncode)
proc = run_process(args, stderr=PIPE, check=False)
if proc.returncode != 0:
sys.stderr.write(proc.stderr)
exit_with_error('closure compiler failed (rc: %d)', proc.returncode)

return filename + '.cc.js'
return outfile

# minify the final wasm+JS combination. this is done after all the JS
# and wasm optimizations; here we do the very final optimizations on them
Expand Down