Handle patches that do not touch lib/drivers (e.g. doc-only) without
crashing. Treat every '--- a/' line as the start of a new file: if the
path is under lib/ or drivers/, set lib and process symbol lines;
otherwise set lib to None and ignore lines until the next file. This
avoids both NameError exceptions and misattributing export-like lines
from doc (or other) files to the previous lib when file order varies.

Fixes: 1a0c104a7fa9 ("build: generate symbol maps")
Cc: [email protected]

Suggested-by: David Marchand <[email protected]>
Signed-off-by: Ali Alnubani <[email protected]>
---

v2:
Treat every '--- a/' as a new file: set lib only for paths under lib/
or drivers/, otherwise set lib to None and skip lines until the next
file, so behavior no longer depends on patch file order.

 devtools/check-symbol-change.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/devtools/check-symbol-change.py b/devtools/check-symbol-change.py
index 1efeb82fcd..a476ceae5e 100755
--- a/devtools/check-symbol-change.py
+++ b/devtools/check-symbol-change.py
@@ -29,17 +29,21 @@
 symbols = {}
 
 for file in args.patch:
+    lib = None
     for ln in file.readlines():
-        if file_header_regexp.match(ln):
-            if file_header_regexp.match(ln).group(2) == "lib":
-                lib = "/".join(file_header_regexp.match(ln).group(2, 3))
-            elif file_header_regexp.match(ln).group(3) == "intel":
-                lib = "/".join(file_header_regexp.match(ln).group(2, 3, 4))
+        if ln.startswith("--- a/"):
+            if file_header_regexp.match(ln):
+                m = file_header_regexp.match(ln)
+                if m.group(2) == "lib":
+                    lib = "/".join(m.group(2, 3))
+                elif m.group(3) == "intel":
+                    lib = "/".join(m.group(2, 3, 4))
+                else:
+                    lib = "/".join(m.group(2, 3))
+                if lib not in symbols:
+                    symbols[lib] = {}
             else:
-                lib = "/".join(file_header_regexp.match(ln).group(2, 3))
-
-            if lib not in symbols:
-                symbols[lib] = {}
+                lib = None
             continue
 
         if export_exp_sym_regexp.match(ln):
@@ -54,6 +58,8 @@
         else:
             continue
 
+        if lib is None:
+            continue
         if symbol not in symbols[lib]:
             symbols[lib][symbol] = {}
         added = ln[0] == "+"
-- 
2.53.0

Reply via email to