Skip to content

Commit daf5de1

Browse files
authored
Merge pull request #131 from Pennycook/associate-fix
Fix associate() handling of #include from symlink
2 parents 73dd406 + 7032e46 commit daf5de1

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

codebasin/finder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def associator(node: Node) -> Visit:
117117
association[node].add(platform.name)
118118
active = node.evaluate_for_platform(
119119
platform=platform,
120-
filename=filename,
120+
filename=self._get_realpath(filename),
121121
state=self,
122122
)
123123

tests/include/test_include.py

+26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: BSD-3-Clause
33

44
import logging
5+
import os
6+
import tempfile
57
import unittest
68
from pathlib import Path
79

@@ -43,6 +45,30 @@ def test_include(self):
4345
"Mismatch in setmap",
4446
)
4547

48+
def test_include_from_symlink(self):
49+
"""Check included file correctly identifies its parent"""
50+
tmp = tempfile.TemporaryDirectory()
51+
p = Path(tmp.name)
52+
with open(p / "test.cpp", mode="w") as f:
53+
f.write('#include "test.h"')
54+
open(p / "test.h", mode="w").close()
55+
os.symlink(p / "test.cpp", p / "symlink.cpp")
56+
57+
codebase = CodeBase(p)
58+
configuration = {
59+
"test": [
60+
{
61+
"file": str(p / "symlink.cpp"),
62+
"defines": [],
63+
"include_paths": [],
64+
"include_files": [],
65+
},
66+
],
67+
}
68+
_ = finder.find(self.rootdir, codebase, configuration)
69+
70+
tmp.cleanup()
71+
4672

4773
if __name__ == "__main__":
4874
unittest.main()

0 commit comments

Comments
 (0)