Skip to content

Commit 5e33efb

Browse files
authored
Cleaner handling of clusure compiler errors (#7313)
Previously you would see an emscripten internal backtrace if closure compiler failed. Sadly we have a lot of existing warnings so we don't display the process stderr unless we the subprcess returns non-zero. I guess we should try to address the closure warnings, at least the ones in emscripten proper.
1 parent 432ff16 commit 5e33efb

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

tests/test_other.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8594,16 +8594,17 @@ def test_IGNORE_CLOSURE_COMPILER_ERRORS(self):
85948594
}
85958595
''')
85968596

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

8600-
failed = False
8601-
try:
8602-
test()
8603-
except:
8604-
failed = True
8605-
assert failed
8606-
test(['-s', 'IGNORE_CLOSURE_COMPILER_ERRORS=1'])
8604+
proc = test(check=False)
8605+
self.assertContained('ERROR - Variable dupe declared more than once', proc.stderr)
8606+
proc = test(check=True, extra=['-s', 'IGNORE_CLOSURE_COMPILER_ERRORS=1'])
8607+
self.assertEqual(proc.stderr, '')
86078608

86088609
def test_toolchain_profiler(self):
86098610
environ = os.environ.copy()

tools/shared.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,14 +2445,15 @@ def closure_compiler(filename, pretty=True):
24452445

24462446
# Something like this (adjust memory as needed):
24472447
# 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
2448+
outfile = filename + '.cc.js'
24482449
args = [JAVA,
24492450
'-Xmx' + (os.environ.get('JAVA_HEAP_SIZE') or '1024m'), # if you need a larger Java heap, use this environment variable
24502451
'-jar', CLOSURE_COMPILER,
24512452
'--compilation_level', 'ADVANCED_OPTIMIZATIONS',
24522453
'--language_in', 'ECMASCRIPT5',
24532454
'--externs', CLOSURE_EXTERNS,
24542455
# '--variable_map_output_file', filename + '.vars',
2455-
'--js', filename, '--js_output_file', filename + '.cc.js']
2456+
'--js', filename, '--js_output_file', outfile]
24562457
for extern in NODE_EXTERNS:
24572458
args.append('--externs')
24582459
args.append(extern)
@@ -2466,11 +2467,12 @@ def closure_compiler(filename, pretty=True):
24662467
if os.environ.get('EMCC_CLOSURE_ARGS'):
24672468
args += shlex.split(os.environ.get('EMCC_CLOSURE_ARGS'))
24682469
logging.debug('closure compiler: ' + ' '.join(args))
2469-
process = run_process(args, stdout=PIPE, stderr=STDOUT, check=False)
2470-
if process.returncode != 0 or not os.path.exists(filename + '.cc.js'):
2471-
raise Exception('closure compiler error: ' + process.stdout + ' (rc: %d)' % process.returncode)
2470+
proc = run_process(args, stderr=PIPE, check=False)
2471+
if proc.returncode != 0:
2472+
sys.stderr.write(proc.stderr)
2473+
exit_with_error('closure compiler failed (rc: %d)', proc.returncode)
24722474

2473-
return filename + '.cc.js'
2475+
return outfile
24742476

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

0 commit comments

Comments
 (0)