check-include-order.py: Add --debug option and log shell commands executed
To help debugging issues with apparent LTS false positives.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I600b42ce19eb6014dfb40addadf300d80712df56
(cherry picked from commit fefed491cd7a1cfca851a74ffc41bc7d06c63839)
diff --git a/script/static-checks/check-include-order.py b/script/static-checks/check-include-order.py
index 3d6b3a3..2160165 100755
--- a/script/static-checks/check-include-order.py
+++ b/script/static-checks/check-include-order.py
@@ -37,6 +37,11 @@
INCLUDE_RE_DIFF = re.compile(r"^\+?\s*#\s*include\s\s*(?P<path>[\"<].+[\">])")
+def subprocess_run(cmd, **kwargs):
+ logging.debug("Running command: %r %r", cmd, kwargs)
+ return subprocess.run(cmd, **kwargs)
+
+
def include_paths(lines, diff_mode=False):
"""List all include paths in a file. Ignore starting `+` in diff mode."""
pattern = INCLUDE_RE_DIFF if diff_mode else INCLUDE_RE
@@ -201,7 +206,7 @@
"""Get the output of a git diff and analyse each modified file."""
# Get patches of the affected commits with one line of context.
- gitlog = subprocess.run(
+ gitlog = subprocess_run(
[
"git",
"log",
@@ -263,6 +268,11 @@
help="Final commit in patch mode (default: %(default)s)",
default="HEAD",
)
+ parser.add_argument(
+ "--debug",
+ help="Enable debug logging",
+ action="store_true",
+ )
args = parser.parse_args(argv)
return args
@@ -270,6 +280,9 @@
if __name__ == "__main__":
args = parse_cmd_line(sys.argv[1:], sys.argv[0])
+ if args.debug:
+ logging.basicConfig(level=logging.DEBUG)
+
os.chdir(args.tree)
if args.patch: