Skip to content

Commit 5d0a6a0

Browse files
authored
Merge pull request #79 from Pennycook/remove-duplicate-detection
Remove duplicate detection
2 parents 14096fe + e77e6f5 commit 5d0a6a0

File tree

23 files changed

+165
-162
lines changed

23 files changed

+165
-162
lines changed

codebasin/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ def load_database(dbpath, rootdir):
493493
else:
494494
log.warning("Couldn't find file %s -- ignoring it.", path)
495495

496+
if len(configuration) == 0:
497+
log.warning(
498+
f"No files found in compilation database at '{dbpath}'.\n"
499+
+ "Ensure that 'directory' and 'file' are in the root directory.",
500+
)
501+
496502
return configuration
497503

498504

codebasin/finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, summarize_only):
4141
self.langs = {}
4242
self.summarize_only = summarize_only
4343
self.fileinfo = collections.defaultdict(list)
44-
self.merge_duplicates = True
44+
self.merge_duplicates = False
4545

4646
def _map_filename(self, fn):
4747
"""

tests/build-dir/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause

tests/build-dir/foo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void foo() { return; }

tests/build-dir/test_build_dir.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
import json
5+
import logging
6+
import tempfile
7+
import unittest
8+
from pathlib import Path
9+
10+
from codebasin import config, finder
11+
from codebasin.walkers.platform_mapper import PlatformMapper
12+
13+
14+
class TestBuildDirectories(unittest.TestCase):
15+
"""
16+
Test ability to correctly handle out-of-tree builds.
17+
"""
18+
19+
def setUp(self):
20+
self.rootdir = str(Path(__file__).parent)
21+
logging.getLogger("codebasin").disabled = False
22+
23+
def test_absolute_paths(self):
24+
"""
25+
Test database with build "directory" path but source "file" path.
26+
All "file" fields are absolute paths.
27+
"""
28+
29+
source = str(Path(__file__).parent.joinpath("foo.cpp"))
30+
31+
# CBI only understands how to load compilation databases from file.
32+
# For now, create temporary files every time we test.
33+
dir1 = str(Path(__file__).parent.joinpath("build1/"))
34+
build1 = tempfile.NamedTemporaryFile()
35+
json1 = [
36+
{
37+
"command": f"/usr/bin/c++ -o foo.cpp.o -c {source}",
38+
"directory": f"{dir1}",
39+
"file": f"{source}",
40+
},
41+
]
42+
with open(build1.name, "w") as f:
43+
json.dump(json1, f)
44+
45+
dir2 = str(Path(__file__).parent.joinpath("build2/"))
46+
build2 = tempfile.NamedTemporaryFile()
47+
json2 = [
48+
{
49+
"command": f"/usr/bin/c++ -o foo.cpp.o -c {source}",
50+
"directory": f"{dir2}",
51+
"file": f"{source}",
52+
},
53+
]
54+
with open(build2.name, "w") as f:
55+
json.dump(json2, f)
56+
57+
codebase = {
58+
"files": [source],
59+
"platforms": ["one", "two"],
60+
"exclude_files": set(),
61+
"exclude_patterns": [],
62+
"rootdir": self.rootdir,
63+
}
64+
65+
configuration = {}
66+
for name, path in [("one", build1.name), ("two", build2.name)]:
67+
db = config.load_database(path, self.rootdir)
68+
configuration.update({name: db})
69+
70+
expected_setmap = {frozenset(["one", "two"]): 1}
71+
72+
state = finder.find(self.rootdir, codebase, configuration)
73+
mapper = PlatformMapper(codebase)
74+
setmap = mapper.walk(state)
75+
self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")
76+
77+
def test_empty_platform(self):
78+
"""
79+
Check that we warn if all files from a platform are excluded.
80+
This may be a sign that the compilation database has incorrect paths.
81+
"""
82+
83+
source = str(Path(__file__).parent.joinpath("foo.cpp"))
84+
85+
# CBI only understands how to load compilation databases from file.
86+
# For now, create temporary files every time we test.
87+
build = str(Path(__file__).parent.joinpath("build/"))
88+
tmp = tempfile.NamedTemporaryFile()
89+
obj = [
90+
{
91+
"command": f"/usr/bin/c++ -o foo.cpp.o -c {source}",
92+
"directory": f"{build}",
93+
"file": "foo.cpp",
94+
},
95+
]
96+
with open(tmp.name, "w") as f:
97+
json.dump(obj, f)
98+
99+
with self.assertLogs("codebasin", level="WARNING") as log:
100+
config.load_database(tmp.name, self.rootdir)
101+
102+
found_expected_warning = False
103+
for msg in log.output:
104+
if msg.find("No files found in compilation database"):
105+
found_expected_warning = True
106+
self.assertTrue(found_expected_warning)
107+
108+
109+
if __name__ == "__main__":
110+
unittest.main()

tests/duplicates/build1/bar.c

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/duplicates/build1/bar.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/duplicates/build1/baz.c

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/duplicates/build1/baz.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/duplicates/build1/foo.c

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)