Skip to content

Commit 79cf4ab

Browse files
committed
Merge compile_commands.json if --file
1 parent 4cac1f6 commit 79cf4ab

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

refresh.template.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,17 @@ def _ensure_cwd_is_workspace_root():
10651065
for (target, flags) in target_flag_pairs:
10661066
compile_command_entries.extend(_get_commands(target, flags))
10671067

1068+
should_merge = any(arg.startswith('--file') for arg in sys.argv[1:])
1069+
if should_merge and os.path.isfile('compile_commands.json'):
1070+
origin_compile_command_entries = []
1071+
with open('compile_commands.json') as fd:
1072+
try:
1073+
origin_compile_command_entries = json.load(fd)
1074+
except:
1075+
log_warning(">>> Failed to merge compile_commands.json the file seems has broken")
1076+
files_index = set(entry['file'] for entry in compile_command_entries)
1077+
compile_command_entries += [entry for entry in origin_compile_command_entries if entry['file'] not in files_index]
1078+
10681079
# Chain output into compile_commands.json
10691080
with open('compile_commands.json', 'w') as output_file:
10701081
json.dump(

0 commit comments

Comments
 (0)