Skip to content

Commit a48f13c

Browse files
committed
Fix naming of temp object files in emcc. NFC
The existing code was naming every object file with an `_N` suffix where N was the number files seen so far. This meant we were using suffixes for all files, not just files that were duplicates.
1 parent 992775c commit a48f13c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

emcc.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,24 @@ def get_clang_command_asm():
538538
assert state.mode == Mode.COMPILE_AND_LINK
539539
assert not options.dash_c
540540
compile_args, linker_args = separate_linker_flags(newargs)
541+
542+
# Map of file basenames to how many times we've seen them. We use this to generate
543+
# unique `_NN` suffix for object files in cases when we are compiling multiple soures that
544+
# have the same basename. e.g. `foo/utils.c` and `bar/utils.c` on the same command line.
541545
seen_names = {}
542546

543547
def uniquename(name):
544-
if name not in seen_names:
545-
seen_names[name] = str(len(seen_names))
546-
return unsuffixed(name) + '_' + seen_names[name] + shared.suffix(name)
548+
unique_suffix = ''
549+
if name in seen_names:
550+
unique_suffix = '_%d' % seen_names[name]
551+
seen_names[name] += 1
552+
else:
553+
seen_names[name] = 1
554+
return unsuffixed(name) + unique_suffix + shared.suffix(name)
547555

548556
def get_object_filename(input_file):
549-
return in_temp(shared.replace_suffix(uniquename(input_file), '.o'))
557+
objfile = os.path.basename(shared.replace_suffix(input_file, '.o'))
558+
return in_temp(uniquename(objfile))
550559

551560
def compile_source_file(input_file):
552561
logger.debug(f'compiling source file: {input_file}')

0 commit comments

Comments
 (0)