|
36 | 36 |
|
37 | 37 | from tools import shared, system_libs, utils, cmdline
|
38 | 38 | from tools import diagnostics, building, compile
|
39 |
| -from tools.shared import unsuffixed, unsuffixed_basename, get_file_suffix |
| 39 | +from tools.shared import unsuffixed_basename, get_file_suffix |
40 | 40 | from tools.shared import run_process, exit_with_error, DEBUG
|
41 | 41 | from tools.shared import in_temp
|
42 | 42 | from tools.shared import DYLIB_EXTENSIONS
|
@@ -538,15 +538,26 @@ def get_clang_command_asm():
|
538 | 538 | assert state.mode == Mode.COMPILE_AND_LINK
|
539 | 539 | assert not options.dash_c
|
540 | 540 | 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. |
541 | 545 | seen_names = {}
|
542 | 546 |
|
543 | 547 | def uniquename(name):
|
544 | 548 | if name not in seen_names:
|
545 |
| - seen_names[name] = str(len(seen_names)) |
546 |
| - return unsuffixed(name) + '_' + seen_names[name] + shared.suffix(name) |
| 549 | + # No suffix needed the firt time we see given name. |
| 550 | + seen_names[name] = 1 |
| 551 | + return name |
| 552 | + |
| 553 | + unique_suffix = '_%d' % seen_names[name] |
| 554 | + seen_names[name] += 1 |
| 555 | + base, ext = os.path.splitext(name) |
| 556 | + return base + unique_suffix + ext |
547 | 557 |
|
548 | 558 | def get_object_filename(input_file):
|
549 |
| - return in_temp(shared.replace_suffix(uniquename(input_file), '.o')) |
| 559 | + objfile = unsuffixed_basename(input_file) + '.o' |
| 560 | + return in_temp(uniquename(objfile)) |
550 | 561 |
|
551 | 562 | def compile_source_file(input_file):
|
552 | 563 | logger.debug(f'compiling source file: {input_file}')
|
|
0 commit comments