Skip to content

Commit cb1e10d

Browse files
OSS-Fuzz Teamcopybara-github
authored andcommitted
clang_wrapper: Remove duplicate fragments when merging CDBs.
PiperOrigin-RevId: 864160580
1 parent 4c8f92b commit cb1e10d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

infra/base-images/base-builder/indexer/clang_wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ def load_cdbs(directory: Path) -> Iterator[tuple[Path, dict[str, Any]]]:
540540
if output_path in existing_output_files:
541541
# Remove existing entry for the output file.
542542
os.unlink(existing_output_files[output_path])
543+
del existing_output_files[output_path]
543544

544545
shutil.copy2(file, merged_cdb_path / file.name)
545546

infra/base-images/base-builder/indexer/clang_wrapper_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,38 @@ def test_merge_incremental_cdb(self):
144144
],
145145
)
146146

147+
def test_merge_incremental_cdb_duplicate_outputs(self):
148+
"""Tests that incremental cdb is merged correctly with duplicate outputs."""
149+
cdb_path = pathlib.Path(self.create_tempdir().full_path)
150+
merged_cdb_path = pathlib.Path(self.create_tempdir().full_path)
151+
152+
fragment1 = {
153+
"directory": "/build",
154+
"file": "test.c",
155+
"output": "test.o",
156+
}
157+
(merged_cdb_path / "1.json").write_text(json.dumps(fragment1) + ",\n")
158+
159+
fragment2 = {
160+
"directory": "/build",
161+
"file": "test.c",
162+
"output": "test.o",
163+
}
164+
(cdb_path / "2.json").write_text(json.dumps(fragment2) + ",\n")
165+
(cdb_path / "3.json").write_text(json.dumps(fragment2) + ",\n")
166+
167+
clang_wrapper.merge_incremental_cdb(cdb_path, merged_cdb_path)
168+
169+
self.assertCountEqual(
170+
merged_cdb_path.iterdir(),
171+
[
172+
merged_cdb_path / ".lock",
173+
merged_cdb_path / "2.json",
174+
merged_cdb_path / "3.json",
175+
],
176+
)
177+
self.assertFalse((merged_cdb_path / "1.json").exists())
178+
147179

148180
if __name__ == "__main__":
149181
unittest.main()

0 commit comments

Comments
 (0)