Skip to content

Commit cfe4eb5

Browse files
committed
Source maps should only be activated via the --map flag.
1 parent 486413c commit cfe4eb5

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

emcc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ try:
710710
save_bc = False
711711
memory_init_file = False
712712
use_preload_cache = False
713+
make_source_map = False
713714

714715
if use_cxx:
715716
default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline.
@@ -780,6 +781,9 @@ try:
780781
elif newargs[i] == '-g':
781782
keep_llvm_debug = True
782783
keep_js_debug = True
784+
elif newargs[i] == '--map':
785+
make_source_map = True
786+
newargs[i] = '-g' # we'll need this to get LLVM debug info
783787
elif newargs[i] == '--bind':
784788
bind = True
785789
newargs[i] = ''
@@ -869,6 +873,8 @@ try:
869873
if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level]
870874
if llvm_lto is None: llvm_lto = opt_level >= 3
871875
if opt_level <= 0: keep_llvm_debug = keep_js_debug = True # always keep debug in -O0
876+
if opt_level > 0: keep_llvm_debug = False # JS optimizer wipes out llvm debug info
877+
if make_source_map: keep_llvm_debug = True; keep_js_debug = True
872878
if closure is None and opt_level == 3: closure = True
873879

874880
if DEBUG: start_time = time.time() # done after parsing arguments, which might affect debug state
@@ -1498,8 +1504,7 @@ try:
14981504
if shared.Settings.ASM_JS:
14991505
js_optimizer_queue = ['asm'] + js_optimizer_queue
15001506
logging.debug('applying js optimization passes: %s', js_optimizer_queue)
1501-
final = shared.Building.js_optimizer(final, js_optimizer_queue, jcache,
1502-
keep_llvm_debug and keep_js_debug)
1507+
final = shared.Building.js_optimizer(final, js_optimizer_queue, jcache, make_source_map)
15031508
js_transform_tempfiles.append(final)
15041509
if DEBUG: save_intermediate('js_opts')
15051510
else:
@@ -1508,8 +1513,7 @@ try:
15081513
if shared.Settings.ASM_JS:
15091514
passes = ['asm'] + passes
15101515
logging.debug('applying js optimization pass: %s', passes)
1511-
final = shared.Building.js_optimizer(final, passes, jcache,
1512-
keep_llvm_debug and keep_js_debug)
1516+
final = shared.Building.js_optimizer(final, passes, jcache, make_source_map)
15131517
js_transform_tempfiles.append(final)
15141518
save_intermediate(name)
15151519
js_optimizer_queue = []
@@ -1519,8 +1523,7 @@ try:
15191523

15201524
if DEBUG == '2':
15211525
# Clean up the syntax a bit
1522-
final = shared.Building.js_optimizer(final, [], jcache,
1523-
keep_llvm_debug and keep_js_debug)
1526+
final = shared.Building.js_optimizer(final, [], jcache, make_source_map)
15241527
if DEBUG: save_intermediate('pretty')
15251528

15261529
def get_eliminate():
@@ -1608,7 +1611,7 @@ try:
16081611
shell = open(shell_path).read()
16091612
html = open(target, 'w')
16101613
if not Compression.on:
1611-
if keep_llvm_debug and keep_js_debug:
1614+
if make_source_map:
16121615
match = re.match('.*?<script[^>]*>{{{ SCRIPT_CODE }}}</script>', shell,
16131616
re.DOTALL)
16141617
if match is None:
@@ -1684,7 +1687,7 @@ try:
16841687
from tools.split import split_javascript_file
16851688
split_javascript_file(final, unsuffixed(target), split_js_file)
16861689
else:
1687-
if keep_llvm_debug and keep_js_debug: generate_source_map(target)
1690+
if make_source_map: generate_source_map(target)
16881691

16891692
# copy final JS to output
16901693
shutil.move(final, target)

tests/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9586,7 +9586,7 @@ def process(filename):
95869586

95879587
def test_source_map(self):
95889588
if Settings.USE_TYPED_ARRAYS != 2: return self.skip("doesn't pass without typed arrays")
9589-
if '-g' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('-g')
9589+
if '--map' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('--map')
95909590

95919591
src = '''
95929592
#include <stdio.h>
@@ -11754,7 +11754,7 @@ def test_html_source_map(self):
1175411754
return 0;
1175511755
}
1175611756
''')
11757-
Popen([PYTHON, EMCC, cpp_file, '-o', html_file, '-g']).communicate()
11757+
Popen([PYTHON, EMCC, cpp_file, '-o', html_file, '--map']).communicate()
1175811758
webbrowser.open_new('file://' + html_file)
1175911759
print '''
1176011760
Set the debugger to pause on exceptions

tools/js_optimizer.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, js, js_engine):
5757
if curr not in INVALID_3: self.names.append(curr)
5858
#print >> sys.stderr, self.names
5959

60-
def minify_shell(self, shell, compress, debug=False):
60+
def minify_shell(self, shell, compress, source_map=False):
6161
#print >> sys.stderr, "MINIFY SHELL 1111111111", shell, "\n222222222222222"
6262
# Run through js-optimizer.js to find and minify the global symbols
6363
# We send it the globals, which it parses at the proper time. JS decides how
@@ -80,7 +80,7 @@ def minify_shell(self, shell, compress, debug=False):
8080
output = subprocess.Popen(self.js_engine +
8181
[JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] +
8282
(['compress'] if compress else []) +
83-
(['--debug'] if debug else []),
83+
(['--debug'] if source_map else []),
8484
stdout=subprocess.PIPE).communicate()[0]
8585
assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + output
8686
#print >> sys.stderr, "minified SHELL 3333333333333333", output, "\n44444444444444444444"
@@ -107,7 +107,7 @@ def run_on_chunk(command):
107107
if DEBUG and not shared.WINDOWS: print >> sys.stderr, '.' # Skip debug progress indicator on Windows, since it doesn't buffer well with multiple threads printing to console.
108108
return filename
109109

110-
def run_on_js(filename, passes, js_engine, jcache, debug=False):
110+
def run_on_js(filename, passes, js_engine, jcache, source_map=False):
111111
if isinstance(jcache, bool) and jcache: jcache = shared.JCache
112112
if jcache: shared.JCache.ensure()
113113

@@ -175,7 +175,7 @@ def process(line):
175175
js = js[start_funcs + len(start_funcs_marker):end_funcs]
176176

177177
minifier = Minifier(js, js_engine)
178-
asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'compress' in passes, debug).split('EMSCRIPTEN_FUNCS();');
178+
asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'compress' in passes, source_map).split('EMSCRIPTEN_FUNCS();');
179179
asm_shell_post = asm_shell_post.replace('});', '})');
180180
pre += asm_shell_pre + '\n' + start_funcs_marker
181181
post = end_funcs_marker + asm_shell_post + post
@@ -211,7 +211,9 @@ def process(line):
211211
total_size = len(js)
212212
js = None
213213

214-
cores = int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count())
214+
# if we are making source maps, we want our debug numbering to start from the
215+
# top of the file, so avoid breaking the JS into chunks
216+
cores = 1 if source_map else int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count())
215217
intended_num_chunks = int(round(cores * NUM_CHUNKS_PER_CORE))
216218
chunk_size = min(MAX_CHUNK_SIZE, max(MIN_CHUNK_SIZE, total_size / intended_num_chunks))
217219

@@ -253,7 +255,7 @@ def write_chunk(chunk, i):
253255
# XXX Use '--nocrankshaft' to disable crankshaft to work around v8 bug 1895, needed for older v8/node (node 0.6.8+ should be ok)
254256
commands = map(lambda filename: js_engine +
255257
[JS_OPTIMIZER, filename, 'noPrintMetadata'] +
256-
(['--debug'] if debug else []) + passes, filenames)
258+
(['--debug'] if source_map else []) + passes, filenames)
257259
#print [' '.join(command) for command in commands]
258260

259261
cores = min(cores, filenames)
@@ -321,6 +323,6 @@ def write_chunk(chunk, i):
321323

322324
return filename
323325

324-
def run(filename, passes, js_engine, jcache, debug=False):
325-
return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache, debug))
326+
def run(filename, passes, js_engine, jcache, source_map=False):
327+
return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache, source_map))
326328

0 commit comments

Comments
 (0)