Skip to content

Commit 0e37c34

Browse files
committed
Fix for collisions between output name and secondary output names
Fixes #13729
1 parent ebf0c5f commit 0e37c34

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

emcc.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,13 @@ def get_file_suffix(filename):
817817
return ''
818818

819819

820+
def get_secondary_target(target, ext):
821+
base = unsuffixed(target)
822+
if get_file_suffix(target) == ext:
823+
base += '_'
824+
return base + ext
825+
826+
820827
def in_temp(name):
821828
temp_dir = shared.get_emscripten_temp_dir()
822829
return os.path.join(temp_dir, os.path.basename(name))
@@ -829,8 +836,6 @@ def in_temp(name):
829836
# Main run() function
830837
#
831838
def run(args):
832-
target = None
833-
834839
# Additional compiler flags that we treat as if they were passed to us on the
835840
# commandline
836841
EMCC_CFLAGS = os.environ.get('EMCC_CFLAGS')
@@ -1227,7 +1232,7 @@ def add_link_flag(i, f):
12271232
wasm_target = target
12281233
else:
12291234
# Otherwise the wasm file is produced alongside the final target.
1230-
wasm_target = unsuffixed(target) + '.wasm'
1235+
wasm_target = get_secondary_target(target, '.wasm')
12311236

12321237
# Apply user -jsD settings
12331238
for s in user_js_defines:
@@ -2438,7 +2443,7 @@ def post_link(options, in_wasm, wasm_target, target):
24382443
if options.oformat in (OFormat.JS, OFormat.MJS):
24392444
js_target = target
24402445
else:
2441-
js_target = unsuffixed(target) + '.js'
2446+
js_target = get_secondary_target(target, '.js')
24422447

24432448
# The JS is now final. Move it to its final location
24442449
move_file(final_js, js_target)

tests/test_other.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10179,3 +10179,13 @@ def create_o(name, i):
1017910179

1018010180
self.run_process(building.get_command_with_possible_response_file([EMCC, 'main.c'] + files))
1018110181
self.assertContained(str(count * (count - 1) // 2), self.run_js('a.out.js'))
10182+
10183+
def test_output_name_collision(self):
10184+
# Ensure that the seconday filenames never collide with the primary output filename
10185+
# In this case we explcitly ask for JS to be ceated in a file with the `.wasm` suffix.
10186+
# Even though this doesn't make much sense the `--oformat` flag is designed to overide
10187+
# any implict type that we might infer from the output name.
10188+
self.run_process([EMCC, '-o', 'hello.wasm', '--oformat=js', test_file('hello_world.c')])
10189+
self.assertExists('hello.wasm')
10190+
self.assertExists('hello_.wasm')
10191+
self.assertContained('hello, world!', self.run_js('hello.wasm'))

0 commit comments

Comments
 (0)