Skip to content

Commit dff547a

Browse files
committed
Tweaks
1 parent ee07e54 commit dff547a

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

tools/precommit/Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ 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
1212

1313
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1414

15-
RUN apt-get update && apt-get install -y --no-install-recommends \
15+
RUN apt-get update -qq
16+
RUN apt-get install -qy --no-install-recommends \
1617
ca-certificates \
1718
bash \
1819
git \
@@ -22,9 +23,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2223
ninja-build \
2324
pkg-config \
2425
python3 \
25-
clang \
26-
clang-tidy \
27-
clang-format \
26+
python3-pip \
27+
python3-venv \
2828
openmpi-bin \
2929
libopenmpi-dev \
3030
libfftw3-dev \
@@ -35,8 +35,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3535
libcereal-dev \
3636
libgtest-dev \
3737
libgmock-dev \
38-
libomp-dev \
39-
&& rm -rf /var/lib/apt/lists/*
38+
libomp-dev
39+
RUN apt-get clean
40+
41+
RUN python3 -m venv /opt/precommit-venv \
42+
&& /opt/precommit-venv/bin/pip install --no-cache-dir --upgrade pip \
43+
&& /opt/precommit-venv/bin/pip install --no-cache-dir clang-format clang-tidy
44+
ENV PATH="/opt/precommit-venv/bin:${PATH}"
4045

4146
WORKDIR /repo
4247

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)