Skip to content

Commit

Permalink
Calculate target JS name more reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed May 10, 2021
1 parent cf3770b commit 5232c1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,13 @@ def phase_setup(state):
else:
target = 'a.out.js'

settings.TARGET_BASENAME_WITH_EXT = os.path.basename(target)
settings.TARGET_BASENAME = unsuffixed(settings.TARGET_BASENAME_WITH_EXT)
if options.oformat in (OFormat.JS, OFormat.MJS):
js_target = target
else:
js_target = get_secondary_target(target, '.js')
settings.TARGET_JS_NAME = js_target

settings.TARGET_BASENAME = unsuffixed_basename(target)

if settings.EXTRA_EXPORTED_RUNTIME_METHODS:
diagnostics.warning('deprecated', 'EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead')
Expand Down Expand Up @@ -2540,7 +2545,7 @@ def phase_final_emitting(options, target, wasm_target, memfile):
if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META:
with open(final_js, 'r+') as f:
src = f.read()
src = src.replace('EMSCRIPTEN$IMPORT$META', 'import.meta')
# src = src.replace('EMSCRIPTEN$IMPORT$META', 'import.meta')
f.seek(0)
f.write(src)
f.truncate()
Expand All @@ -2558,10 +2563,7 @@ def phase_final_emitting(options, target, wasm_target, memfile):

shared.JS.handle_license(final_js)

if options.oformat in (OFormat.JS, OFormat.MJS):
js_target = target
else:
js_target = get_secondary_target(target, '.js')
js_target = settings.TARGET_JS_NAME

# The JS is now final. Move it to its final location
move_file(final_js, js_target)
Expand Down
4 changes: 2 additions & 2 deletions src/settings_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var SIDE_MODULE_IMPORTS = [];
// stores the base name of the output file (-o TARGET_BASENAME.js)
var TARGET_BASENAME = '';

// stores the base name of the output file with extension (TARGET_BASENAME.js or TARGET_BASENAME.mjs)
var TARGET_BASENAME_WITH_EXT = '';
// stores the base name (with extension) of the output JS file
var TARGET_JS_NAME = '';

// Indicates that the syscalls (which we see statically) indicate that they need
// full filesystem support. Otherwise, when just a small subset are used, we can
Expand Down
2 changes: 1 addition & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ self.onmessage = function(e) {
#endif

#if MODULARIZE && EXPORT_ES6
(e.data.urlOrBlob ? import(e.data.urlOrBlob) : import('./{{{ TARGET_BASENAME_WITH_EXT }}}')).then(function({{{ EXPORT_NAME }}}) {
(e.data.urlOrBlob ? import(e.data.urlOrBlob) : import('./{{{ TARGET_JS_NAME }}}')).then(function({{{ EXPORT_NAME }}}) {
return {{{ EXPORT_NAME }}}.default(Module);
}).then(function(instance) {
Module = instance;
Expand Down

0 comments on commit 5232c1d

Please sign in to comment.