Skip to content

Commit

Permalink
Use utils.write_file to write html output. NFC (emscripten-core#20663)
Browse files Browse the repository at this point in the history
`utils.write_file` already encodes as utf-8.
  • Loading branch information
sbc100 authored Nov 9, 2023
1 parent 43e8a3f commit 45550a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 8 additions & 7 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,10 +1089,14 @@ def dedup_list(lst):
return list(dict.fromkeys(lst))


def check_output_file(f):
if os.path.isdir(f):
exit_with_error(f'cannot write output file `{f}`: Is a directory')


def move_file(src, dst):
logging.debug('move: %s -> %s', src, dst)
if os.path.isdir(dst):
exit_with_error(f'cannot write output file `{dst}`: Is a directory')
check_output_file(dst)
src = os.path.abspath(src)
dst = os.path.abspath(dst)
if src == dst:
Expand Down Expand Up @@ -4205,11 +4209,8 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
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)

try:
# Force UTF-8 output for consistency across platforms and with the web.
utils.write_binary(target, shell.encode('utf-8'))
except OSError as e:
exit_with_error(f'cannot write output file: {e}')
check_output_file(target)
write_file(target, shell)


def minify_html(filename):
Expand Down
4 changes: 1 addition & 3 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7995,9 +7995,7 @@ def test_dasho_is_dir(self):
self.assertContained(['Is a directory', 'is a directory'], ret)

ret = self.expect_fail([EMCC, test_file('hello_world.c'), '-o', '.', '--oformat=html'])
self.assertContained('emcc: error: cannot write output file:', ret)
# Linux/Mac and Windows's error codes and messages are different
self.assertContained(['Is a directory', 'Permission denied'], ret)
self.assertContained('emcc: error: cannot write output file `.`: Is a directory', ret)

def test_binaryen_ctors(self):
# ctor order must be identical to js builds, deterministically
Expand Down

0 comments on commit 45550a8

Please sign in to comment.