From 7d391f61d6292c324287416a0b800fc0d89cf576 Mon Sep 17 00:00:00 2001 From: mhasekioglu Date: Tue, 14 Feb 2023 20:21:32 -0500 Subject: [PATCH] store std err parsed compile command paths in set to prevent duplicates, rectify db entries as read from jsons --- compdb/postprocess.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/compdb/postprocess.py b/compdb/postprocess.py index 67d5a60..39bbe66 100755 --- a/compdb/postprocess.py +++ b/compdb/postprocess.py @@ -28,7 +28,6 @@ import subprocess import tempfile - if __name__ == "__main__": ## ## Setup Args @@ -61,21 +60,16 @@ local_exec_root = event['workspaceInfo']['localExecRoot'] print('Execution Root:', local_exec_root) - compile_command_json_db_files = [] + compile_command_json_db_files = set() for line in bazel_stderr: if line.endswith('.compile_commands.json'): - compile_command_json_db_files.append(line.strip()) + compile_command_json_db_files.add(line.strip()) ## ## Collect/Fix/Merge Compilation Databases ## - print("Preparing compilation database...") - - db_entries = [] - for db in compile_command_json_db_files: - with open(db, 'r') as f: - db_entries.extend(json.load(f)) + print("Preparing compilation database...") def fix_db_entry(db_entry): if 'directory' in db_entry and db_entry['directory'] == '__EXEC_ROOT__': db_entry['directory'] = bazel_workspace if args.source_dir else local_exec_root @@ -90,7 +84,11 @@ def fix_db_entry(db_entry): command = command.replace('-iquote', '-I') db_entry['command'] = command return db_entry - db_entries = list(map(fix_db_entry, db_entries)) + + db_entries = [] + for db in compile_command_json_db_files: + with open(db, 'r') as f: + db_entries.extend(list(map(fix_db_entry, json.load(f)))) compdb_file = os.path.join(workspace_directory, "compile_commands.json")