Handle patches that do not touch lib/drivers (e.g. doc-only) without
crashing. Treat every file header (--- a/ or +++ b/) 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.
v3:
Use a regex so both '--- a/' and '+++ b/' start a new file, and run 'if lib
is None: continue; right after the file-header block so non-lib lines are
skipped before any export regex is run.
devtools/check-symbol-change.py | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/devtools/check-symbol-change.py b/devtools/check-symbol-change.py
index 1efeb82fcd..b1daa2934a 100755
--- a/devtools/check-symbol-change.py
+++ b/devtools/check-symbol-change.py
@@ -7,6 +7,7 @@
import argparse
import re
+new_file_regexp = re.compile(r"^(\-\-\-|\+\+\+) [ab]/")
file_header_regexp = re.compile(r"^(\-\-\-|\+\+\+)
[ab]/(lib|drivers)/([^/]+)/([^/]+)")
# From eal_exports.h
export_exp_sym_regexp =
re.compile(r"^.RTE_EXPORT_EXPERIMENTAL_SYMBOL\(([^,]+),")
@@ -29,17 +30,24 @@
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 new_file_regexp.match(ln):
+ 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))
+ lib = None
+ continue
- if lib not in symbols:
- symbols[lib] = {}
+ if lib is None:
continue
if export_exp_sym_regexp.match(ln):
--
2.53.0