]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Detect header cycles regardless of how we spell the #include. 18086/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 4 Feb 2025 13:07:02 +0000 (06:07 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 4 Feb 2025 21:41:48 +0000 (14:41 -0700)
contrib/utilities/detect_include_cycles.py

index 81838f2c0a57360bc74cb1c27e33460cbb0bb895..e1a2670bdaa818bd245ebc2e0ae91555babb14cb 100644 (file)
 
 from glob import glob
 import networkx as nx
+import re
+
+match_includes = re.compile(r"# *include *<(deal.II/.*.h)>")
 
 
 # For a given header file, read through all the lines and extract the
-# ones that correspond to #include statements. For those, add a link
-# from header file to the one it includes to the graph.
+# ones that correspond to #include statements for deal.II header
+# files. For those, add a link from header file to the one it includes
+# to the graph.
 def add_includes_for_file(header_file_name, G) :
     f = open(header_file_name)
     lines = f.readlines()
     f.close()
 
     for line in lines :
-        if "#include" in line :
-            line = line.strip()
-            line = line.replace("#include <", "")
-            included_file = line.replace(">", "")
+        m = match_includes.match(line)
+        if m :
+            included_file = m.group(1)
             G.add_edge(header_file_name.replace("include/", ""),
                        included_file)
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.