diff --git a/emcc.py b/emcc.py index b54b380e5d39a..c91d238b76b65 100644 --- a/emcc.py +++ b/emcc.py @@ -173,7 +173,7 @@ '--bind', '--closure', '--cpuprofiler', '--embed-file', '--emit-symbol-map', '--emrun', '--exclude-file', '--extern-post-js', '--extern-pre-js', '--ignore-dynamic-linking', '--js-library', - '--js-transform', '--memory-init-file', '--oformat', '--output_eol', + '--js-transform', '--memory-init-file', '--oformat', '--output_eol', '--output-eol', '--post-js', '--pre-js', '--preload-file', '--profiling-funcs', '--proxy-to-worker', '--shell-file', '--source-map-base', '--threadprofiler', '--use-preload-plugins' @@ -3427,8 +3427,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile): diagnostics.warning('experimental', 'The SPLIT_MODULE setting is experimental and subject to change') do_split_module(wasm_target, options) - if not settings.SINGLE_FILE: - tools.line_endings.convert_line_endings_in_file(js_target, os.linesep, options.output_eol) + tools.line_endings.convert_line_endings_in_file(js_target, options.output_eol) if options.executable: make_js_executable(js_target) @@ -3731,14 +3730,14 @@ def consume_arg_file(): options.default_object_extension = '.' + options.default_object_extension elif arg.startswith('-fsanitize=cfi'): exit_with_error('emscripten does not currently support -fsanitize=cfi') - elif check_arg('--output_eol'): + elif check_arg('--output_eol') or check_arg('--output-eol'): style = consume_arg() if style.lower() == 'windows': options.output_eol = '\r\n' elif style.lower() == 'linux': options.output_eol = '\n' else: - exit_with_error(f'Invalid value "{style}" to --output_eol!') + exit_with_error(f'invalid value for --output-eol: `{style}`') # Record PTHREADS setting because it controls whether --shared-memory is passed to lld elif arg == '-pthread': settings.PTHREADS = 1 @@ -4198,12 +4197,7 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam html_contents = do_replace(shell, '{{{ SCRIPT }}}', script.replacement()) html_contents = tools.line_endings.convert_line_endings(html_contents, '\n', options.output_eol) - - try: - # Force UTF-8 output for consistency across platforms and with the web. - utils.write_binary(target, html_contents.encode('utf-8')) - except OSError as e: - exit_with_error(f'cannot write output file: {e}') + utils.write_file(target, html_contents) def minify_html(filename): diff --git a/tools/line_endings.py b/tools/line_endings.py index 2e1f1b3b95eda..43bdaf9d05071 100755 --- a/tools/line_endings.py +++ b/tools/line_endings.py @@ -7,6 +7,8 @@ import os import sys +from . import utils + def convert_line_endings(text, from_eol, to_eol): if from_eol == to_eol: @@ -14,15 +16,13 @@ def convert_line_endings(text, from_eol, to_eol): return text.replace(from_eol, to_eol) -def convert_line_endings_in_file(filename, from_eol, to_eol): - if from_eol == to_eol: +def convert_line_endings_in_file(filename, to_eol): + if to_eol == os.linesep: return # No conversion needed - with open(filename, 'rb') as f: - text = f.read() - text = convert_line_endings(text, from_eol.encode(), to_eol.encode()) - with open(filename, 'wb') as f: - f.write(text) + text = utils.read_binary(filename) + text = convert_line_endings(text, os.linesep.encode(), to_eol.encode()) + utils.write_binary(filename, text) def check_line_endings(filename, expect_only=None, print_errors=True, print_info=False):