Skip to content

Commit

Permalink
Fix line endings of generated on windows (emscripten-core#20664)
Browse files Browse the repository at this point in the history
A couple of windows tests started failing after emscripten-core#20663.

If we write the file as text file we need to perform the line
ending conversions on the file after we write it and not before.
  • Loading branch information
sbc100 authored Nov 9, 2023
1 parent 9ed1ba6 commit b4d5c4a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4207,7 +4207,6 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
shell = do_replace(shell, '{{{ SCRIPT }}}', script.replacement())
shell = shell.replace('{{{ SHELL_CSS }}}', utils.read_file(utils.path_from_root('src/shell.css')))
shell = shell.replace('{{{ SHELL_LOGO }}}', utils.read_file(utils.path_from_root('media/powered_by_logo_mini.svg')))
shell = tools.line_endings.convert_line_endings(shell, '\n', options.output_eol)

check_output_file(target)
write_file(target, shell)
Expand Down Expand Up @@ -4277,6 +4276,8 @@ def generate_html(target, options, js_target, target_basename,
if settings.MINIFY_HTML and (settings.OPT_LEVEL >= 1 or settings.SHRINK_LEVEL >= 1):
minify_html(target)

tools.line_endings.convert_line_endings_in_file(target, os.linesep, options.output_eol)


def generate_worker_js(target, js_target, target_basename):
if settings.SINGLE_FILE:
Expand Down
8 changes: 5 additions & 3 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7904,6 +7904,7 @@ def test_disable_inlining(self):
output = self.run_process([common.LLVM_OBJDUMP, '-t', 'test.o'], stdout=PIPE).stdout
self.assertContained('foo', output)

@crossplatform
def test_output_eol(self):
for params in [[], ['--proxy-to-worker'], ['--proxy-to-worker', '-sWASM=0']]:
for output_suffix in ['html', 'js']:
Expand All @@ -7922,7 +7923,7 @@ def test_output_eol(self):
expected_ending = '\r\n'

ret = line_endings.check_line_endings(f, expect_only=expected_ending)
assert ret == 0
self.assertEqual(ret, 0)

for f in files:
delete_file(f)
Expand Down Expand Up @@ -9779,14 +9780,15 @@ def test_js_preprocess(self):
self.assertContained('JSLIB: EXIT_RUNTIME', err)
self.assertNotContained('JSLIB: MAIN_MODULE', err)

@crossplatform
def test_html_preprocess(self):
src_file = test_file('module/test_stdin.c')
output_file = 'test_stdin.html'
shell_file = test_file('module/test_html_preprocess.html')

self.run_process([EMCC, '-o', output_file, src_file, '--shell-file', shell_file, '-sASSERTIONS=0'], stdout=PIPE, stderr=PIPE)
output = read_file(output_file)
self.assertContained("""<style>
self.assertContained('''<style>
/* Disable preprocessing inside style block as syntax is ambiguous with CSS */
#include {background-color: black;}
#if { background-color: red;}
Expand All @@ -9799,7 +9801,7 @@ def test_html_preprocess(self):
T3:ASSERTIONS < 2
T4:(else) ASSERTIONS <= 1
T5:(else) ASSERTIONS
T6:!ASSERTIONS""", output)
T6:!ASSERTIONS''', output)

self.run_process([EMCC, '-o', output_file, src_file, '--shell-file', shell_file, '-sASSERTIONS'], stdout=PIPE, stderr=PIPE)
output = read_file(output_file)
Expand Down
2 changes: 1 addition & 1 deletion tools/line_endings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def check_line_endings(filename, expect_only=None, print_errors=True, print_info
if print_errors:
print("File '" + filename + "' contains BAD line endings of form \\r\\r\\n!", file=sys.stderr)
bad_line = data[index - 50:index + 50].replace(b'\r', b'\\r').replace(b'\n', b'\\n')
print("Content around the location: '" + bad_line + "'", file=sys.stderr)
print("Content around the location: '" + bad_line.decode('utf-8') + "'", file=sys.stderr)
return 1 # Bad line endings in file, return a non-zero process exit code.

has_dos_line_endings = False
Expand Down

0 comments on commit b4d5c4a

Please sign in to comment.