]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
generate-sym-test: Only include required headers
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 23 May 2025 09:27:31 +0000 (11:27 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 24 May 2025 18:56:27 +0000 (20:56 +0200)
If we don't use any symbols from a header, let's not include it.

src/test/generate-sym-test.py

index 7b5ded936c692813f45f70f4849e4fc114d5a1e9..5aaf372c1db8e96abbf75d50aae6670a2a6ed716 100755 (executable)
@@ -19,7 +19,9 @@ def process_sym_file(file: IO[str]) -> None:
                 print(f'        {{ "{m[1]}", {m[1]} }},')
 
 
-def process_header_file(file: IO[str]) -> None:
+def process_header_file(file: IO[str]) -> str:
+    text = ''
+
     for line in file:
         if (
             line.startswith('#')
@@ -43,22 +45,24 @@ def process_header_file(file: IO[str]) -> None:
         # Functions
         m = re.search(r'^(\S+\s+)+\**(\w+)\s*\(', line)
         if m:
-            print(f'        {{ "{m[2]}", {m[2]} }},')
+            text += f'        {{ "{m[2]}", {m[2]} }},\n'
             continue
 
         # Variables
         m = re.search(r'^extern\s', line)
         if m:
             n = line.split()[-1].rstrip(';')
-            print(f'        {{ "{n}", &{n} }},')
+            text += f'        {{ "{n}", &{n} }},\n'
             continue
 
         # Functions defined by macro
         m = re.search(r'_SD_DEFINE_POINTER_CLEANUP_FUNC\(\w+,\s*(\w+)\)', line)
         if m:
-            print(f'        {{ "{m[1]}", {m[1]} }},')
+            text += f'        {{ "{m[1]}", {m[1]} }},\n'
             continue
 
+    return text
+
 
 def process_source_file(file: IO[str]) -> None:
     for line in file:
@@ -107,7 +111,9 @@ print("""/* SPDX-License-Identifier: LGPL-2.1-or-later */
 """)
 
 for header in sys.argv[3:]:
-    print('#include "{}"'.format(header.split('/')[-1]))
+    with open(header, 'r') as f:
+        if process_header_file(f):
+            print('#include "{}"'.format(header.split('/')[-1]))
 
 print("""
 /* We want to check deprecated symbols too, without complaining */
@@ -129,7 +135,7 @@ print("""        {}
 
 for header in sys.argv[3:]:
     with open(header, 'r') as f:
-        process_header_file(f)
+        print(process_header_file(f), end='')
 
 print("""        {}
 }, symbols_from_source[] = {""")