99_MAKEFILE_NAMES = {"makefile" , "gnumakefile" }
1010_MAKEFILE_EXTS = {".mk" , ".mak" , ".make" }
1111
12- _MAKE_TARGET_RE = re .compile (r"^([a-zA-Z_][a-zA-Z0-9_.-]{0,100})\s{0,20}:(?!=)" , re .MULTILINE )
1312_MAKE_INCLUDE_RE = re .compile (r"^(?:-)?include\s+([^\n]{1,500})$" , re .MULTILINE )
14- _MAKE_VAR_RE = re .compile (r"^\s{0,20}([A-Z_][A-Z0-9_]{0,100})\s{0,20}[:?]?=" , re .MULTILINE )
1513_MAKE_RECIPE_RE = re .compile (r"^\t([^\n]{1,1000})$" , re .MULTILINE )
1614
17- _CMAKE_ADD_EXE_RE = re .compile (r"add_executable\s{0,10}\(\s{0,10}(\w{1,100})" , re .IGNORECASE )
18- _CMAKE_ADD_LIB_RE = re .compile (r"add_library\s{0,10}\(\s{0,10}(\w{1,100})" , re .IGNORECASE )
19- _CMAKE_TARGET_LINK_RE = re .compile (
20- r"target_link_libraries\s{0,10}\(\s{0,10}(\w{1,100})\s{1,20}(?:PUBLIC|PRIVATE|INTERFACE)?\s{0,10}([^)]{1,500})\)" ,
21- re .IGNORECASE ,
22- )
2315_CMAKE_INCLUDE_RE = re .compile (r"include\s{0,10}\(\s{0,10}([^)]{1,300})\)" , re .IGNORECASE )
2416_CMAKE_ADD_SUBDIR_RE = re .compile (r"add_subdirectory\s{0,10}\(\s{0,10}([^\)\s]{1,200})" , re .IGNORECASE )
25- _CMAKE_FIND_PKG_RE = re .compile (r"find_package\s{0,10}\(\s{0,10}(\w{1,100})" , re .IGNORECASE )
26- _CMAKE_SET_RE = re .compile (r"set\s{0,10}\(\s{0,10}([A-Z_][A-Z0-9_]{0,100})" , re .IGNORECASE )
2717
2818_SCRIPT_CALL_RE = re .compile (r"(?:bash|sh|python|python3|\.\/scripts\/|\.\/bin\/)([a-zA-Z0-9_.-]+)" )
2919_SOURCE_FILE_RE = re .compile (r"\b([a-zA-Z_]\w*\.(?:c|cpp|cc|cxx|h|hpp|hxx|py|sh|go|rs|java))\b" )
@@ -39,13 +29,9 @@ def _is_cmake(path: Path) -> bool:
3929 return name == "cmakelists.txt" or path .suffix .lower () == ".cmake"
4030
4131
42- def _extract_make_refs (content : str ) -> tuple [set [str ], set [str ]]:
43- targets : set [str ] = set ()
32+ def _extract_make_refs (content : str ) -> set [str ]:
4433 file_refs : set [str ] = set ()
4534
46- for match in _MAKE_TARGET_RE .finditer (content ):
47- targets .add (match .group (1 ))
48-
4935 for match in _MAKE_INCLUDE_RE .finditer (content ):
5036 includes = match .group (1 ).split ()
5137 for inc in includes :
@@ -60,22 +46,12 @@ def _extract_make_refs(content: str) -> tuple[set[str], set[str]]:
6046
6147 file_refs .update (_SOURCE_FILE_RE .findall (content ))
6248
63- return targets , file_refs
49+ return file_refs
6450
6551
66- def _extract_cmake_refs (content : str ) -> tuple [set [str ], set [str ]]:
67- targets : set [str ] = set ()
52+ def _extract_cmake_refs (content : str ) -> set [str ]:
6853 file_refs : set [str ] = set ()
6954
70- for pattern in [_CMAKE_ADD_EXE_RE , _CMAKE_ADD_LIB_RE ]:
71- for match in pattern .finditer (content ):
72- targets .add (match .group (1 ))
73-
74- for match in _CMAKE_TARGET_LINK_RE .finditer (content ):
75- targets .add (match .group (1 ))
76- deps = match .group (2 ).split ()
77- targets .update (d for d in deps if d and not d .startswith ("$" ))
78-
7955 for match in _CMAKE_INCLUDE_RE .finditer (content ):
8056 file_refs .add (match .group (1 ).strip ())
8157
@@ -86,7 +62,7 @@ def _extract_cmake_refs(content: str) -> tuple[set[str], set[str]]:
8662
8763 file_refs .update (_SOURCE_FILE_RE .findall (content ))
8864
89- return targets , file_refs
65+ return file_refs
9066
9167
9268def _collect_build_refs (make_files : list [Path ], cmake_files : list [Path ]) -> set [str ]:
@@ -95,16 +71,14 @@ def _collect_build_refs(make_files: list[Path], cmake_files: list[Path]) -> set[
9571 for mf in make_files :
9672 try :
9773 content = mf .read_text (encoding = "utf-8" )
98- _ , file_refs = _extract_make_refs (content )
99- refs .update (file_refs )
74+ refs .update (_extract_make_refs (content ))
10075 except (OSError , UnicodeDecodeError ):
10176 continue
10277
10378 for cf in cmake_files :
10479 try :
10580 content = cf .read_text (encoding = "utf-8" )
106- _ , file_refs = _extract_cmake_refs (content )
107- refs .update (file_refs )
81+ refs .update (_extract_cmake_refs (content ))
10882 except (OSError , UnicodeDecodeError ):
10983 continue
11084
@@ -150,7 +124,7 @@ def build(self, fragments: list[Fragment], repo_root: Path | None = None) -> Edg
150124 return edges
151125
152126 def _add_makefile_edges (self , mf : Fragment , cmake_frags : list [Fragment ], idx : FragmentIndex , edges : EdgeDict ) -> None :
153- _ , file_refs = _extract_make_refs (mf .content )
127+ file_refs = _extract_make_refs (mf .content )
154128
155129 for ref in file_refs :
156130 self ._link_ref (mf .id , ref , idx , edges )
@@ -160,7 +134,7 @@ def _add_makefile_edges(self, mf: Fragment, cmake_frags: list[Fragment], idx: Fr
160134 self .add_edge (edges , mf .id , cf .id , self .weight * 0.7 )
161135
162136 def _add_cmake_edges (self , cf : Fragment , fragments : list [Fragment ], idx : FragmentIndex , edges : EdgeDict ) -> None :
163- _ , file_refs = _extract_cmake_refs (cf .content )
137+ file_refs = _extract_cmake_refs (cf .content )
164138
165139 for ref in file_refs :
166140 self ._link_ref (cf .id , ref , idx , edges )
0 commit comments