Skip to content

Commit 3a1e99b

Browse files
committed
Tweaks
1 parent ee07e54 commit 3a1e99b

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

tools/precommit/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM ubuntu:24.04 AS pretty
55

66
ARG DEBIAN_FRONTEND=noninteractive
77
ARG BUILD_DIR=build
8-
ARG JOBS=1
8+
ARG JOBS=16
99
ARG CMAKE_ARGS=""
1010
ARG CLANG_TIDY_EXTRA_ARGS=""
1111
ARG STRICT_CLANG_TIDY=0
@@ -22,9 +22,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2222
ninja-build \
2323
pkg-config \
2424
python3 \
25-
clang \
26-
clang-tidy \
27-
clang-format \
2825
openmpi-bin \
2926
libopenmpi-dev \
3027
libfftw3-dev \
@@ -36,7 +33,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3633
libgtest-dev \
3734
libgmock-dev \
3835
libomp-dev \
39-
&& rm -rf /var/lib/apt/lists/*
36+
&& apt-get clean
37+
38+
RUN python3 -m pip install --no-cache-dir clang-format clang-tidy
4039

4140
WORKDIR /repo
4241

tools/precommit/make-pretty.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import json
44
import os
5+
import shlex
56
import shutil
67
import subprocess
8+
from concurrent.futures import ThreadPoolExecutor, as_completed
79
from pathlib import Path
810

911
root = Path("/repo")
1012
build_dir = Path(os.environ.get("BUILD_DIR", "build"))
13+
jobs = int(os.environ.get("JOBS", "1"))
1114

1215
cpp_format_exts = {
1316
".c", ".cc", ".cpp", ".cxx", ".c++",
@@ -39,7 +42,7 @@ def run(cmd, check=True):
3942
compile_db = root / build_dir / "compile_commands.json"
4043

4144
if not compile_db.exists():
42-
cmake_args = os.environ.get("CMAKE_ARGS", "").split()
45+
cmake_args = shlex.split(os.environ.get("CMAKE_ARGS", ""))
4346
run([
4447
"cmake",
4548
"-S", ".",
@@ -82,10 +85,10 @@ def run(cmd, check=True):
8285
print(f"==> clang-tidy translation units: {len(tidy_files)}", flush=True)
8386

8487
tidy_failures = []
85-
extra = os.environ.get("CLANG_TIDY_EXTRA_ARGS", "").split()
88+
extra = shlex.split(os.environ.get("CLANG_TIDY_EXTRA_ARGS", ""))
8689
strict = os.environ.get("STRICT_CLANG_TIDY", "0") == "1"
8790

88-
for rel in tidy_files:
91+
def run_tidy(rel):
8992
cmd = [
9093
"clang-tidy",
9194
str(rel),
@@ -95,9 +98,15 @@ def run(cmd, check=True):
9598
]
9699
print("+ " + " ".join(cmd), flush=True)
97100
ret = subprocess.run(cmd).returncode
98-
if ret != 0:
99-
tidy_failures.append((str(rel), ret))
100-
print(f"WARNING: clang-tidy failed for {rel} with exit code {ret}", flush=True)
101+
return str(rel), ret
102+
103+
with ThreadPoolExecutor(max_workers=max(1, jobs)) as pool:
104+
futures = [pool.submit(run_tidy, rel) for rel in tidy_files]
105+
for fut in as_completed(futures):
106+
filename, ret = fut.result()
107+
if ret != 0:
108+
tidy_failures.append((str(rel), ret))
109+
print(f"WARNING: clang-tidy failed for {rel} with exit code {ret}", flush=True)
101110

102111
if tidy_failures:
103112
print("==> clang-tidy failures:", flush=True)

0 commit comments

Comments
 (0)