Defining a custom timeout allows the scan to finish (albeit unsuccessfully)
before GitLab's 60 minute limit and thus preserve the cache of already
scanned files.

A successive run, e.g. when the "rerun" button in GitLab's web interface is
clicked, roughly picks up where the previous run stopped, gradually increasing
the amount of cached results and eventually succeeds.

Signed-off-by: Tim Wiederhake <twied...@redhat.com>
---
 scripts/run-clang-tidy.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/scripts/run-clang-tidy.py b/scripts/run-clang-tidy.py
index cc9c20ea32..19b8640982 100755
--- a/scripts/run-clang-tidy.py
+++ b/scripts/run-clang-tidy.py
@@ -51,6 +51,11 @@ def parse_args():
         "--cache",
         dest="cache",
         help="Path to cache directory")
+    parser.add_argument(
+        "--timeout",
+        dest="timeout",
+        type=int,
+        help="Timeout in minutes")
 
     return parser.parse_args()
 
@@ -132,6 +137,11 @@ def cache_write(filename, result):
 def worker():
     while True:
         item = items.get()
+        if args.timeout and args.timeout < time.time():
+            findings.append("%s (timeout)" % item["file"])
+            items.task_done()
+            continue
+
         os.chdir(item["directory"])
 
         cache = cache_name(item)
@@ -164,6 +174,9 @@ if args.cache:
     args.cache = os.path.abspath(args.cache)
     os.makedirs(args.cache, exist_ok=True)
 
+if args.timeout:
+    args.timeout = time.time() + args.timeout * 60
+
 for _ in range(args.thread_num):
     threading.Thread(target=worker, daemon=True).start()
 
-- 
2.26.2

Reply via email to