Skip to content

Commit 47c46fe

Browse files
committed
Fix issue #2133 with \r\r\n line endings being generated.
1 parent 97ad2b9 commit 47c46fe

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

emscripten.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from tools import shared
1515
from tools import jsrun, cache as cache_module, tempfiles
1616
from tools.response_file import read_response_file
17+
from tools.shared import WINDOWS
1718

1819
__rootpath__ = os.path.abspath(os.path.dirname(__file__))
1920
def path_from_root(*pathelems):
@@ -708,13 +709,15 @@ def fix(m):
708709
funcs_js[i] = None
709710
funcs_js_item = indexize(funcs_js_item)
710711
funcs_js_item = blockaddrsize(funcs_js_item)
712+
if WINDOWS: funcs_js_item = funcs_js_item.replace('\r\n', '\n') # Normalize to UNIX line endings, otherwise writing to text file will duplicate \r\n to \r\r\n!
711713
outfile.write(funcs_js_item)
712714
funcs_js = None
713715

714-
outfile.write(indexize(post))
715-
if DEBUG: logging.debug(' emscript: phase 3 took %s seconds' % (time.time() - t))
716-
716+
indexized = indexize(post)
717+
if WINDOWS: indexized = indexized.replace('\r\n', '\n') # Normalize to UNIX line endings, otherwise writing to text file will duplicate \r\n to \r\r\n!
718+
outfile.write(indexized)
717719
outfile.close()
720+
if DEBUG: logging.debug(' emscript: phase 3 took %s seconds' % (time.time() - t))
718721

719722
# emscript_fast: emscript'en code using the 'fast' compilation path, using
720723
# an LLVM backend
@@ -1316,9 +1319,11 @@ def fix(m):
13161319
outfile.write("var SYMBOL_TABLE = %s;" % json.dumps(symbol_table).replace('"', ''))
13171320

13181321
for i in range(len(funcs_js)): # do this loop carefully to save memory
1322+
if WINDOWS: funcs_js[i] = funcs_js[i].replace('\r\n', '\n') # Normalize to UNIX line endings, otherwise writing to text file will duplicate \r\n to \r\r\n!
13191323
outfile.write(funcs_js[i])
13201324
funcs_js = None
13211325

1326+
if WINDOWS: post = post.replace('\r\n', '\n') # Normalize to UNIX line endings, otherwise writing to text file will duplicate \r\n to \r\r\n!
13221327
outfile.write(post)
13231328

13241329
outfile.close()

0 commit comments

Comments
 (0)