File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ #
3+ # clang formats all files in the repository.
4+ # certain files are excluded via .clang-format-ignore files
5+ # supported from clang format 18 upwards.
6+
7+ set -eu
8+
9+ cf=clang-format-18
10+
11+ # Check if clang-format is installed
12+ if ! command -v $cf 2>&1 > /dev/null
13+ then
14+ echo " Error: $cf not found. Please install Clang version 18."
15+ echo " We recommend using the clang_format_docker.sh script."
16+ exit 1
17+ fi
18+
19+ if ! command -v git 2>&1 > /dev/null
20+ then
21+ echo " Error: Git not found. Please install Git to use this script."
22+ echo " You can get Git from:"
23+ echo " - Linux: Most distributions include Git; use your package manager (e.g., 'sudo apt-get install git')"
24+ echo " - macOS: Use Homebrew with 'brew install git'"
25+ echo " - Windows: Download from the official Git website"
26+ exit 1
27+ fi
28+
29+ gitroot=" $( git rev-parse --show-toplevel) "
30+
31+ cd " $gitroot "
32+
33+ git ls-files -z | \
34+ grep -z -E ' (\.cpp|\.h)$' | \
35+ xargs --null -P $( nproc) -n1 $cf -i
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ #
3+ # clang formats all files in the repository, using
4+ # a specific docker image.
5+
6+ set -eu
7+
8+ # Check if Docker is installed
9+ if ! command -v docker 2>&1 > /dev/null
10+ then
11+ echo " Error: Docker not found. Please install Docker to use this script."
12+ echo " You can get Docker from:"
13+ echo " - Linux: https://docs.docker.com/engine/install/"
14+ echo " - macOS: Use Homebrew with 'brew install --cask docker'"
15+ echo " - Windows: Download from Docker Desktop website"
16+ exit 1
17+ fi
18+
19+ # Check if Git is installed
20+ if ! command -v git 2>&1 > /dev/null
21+ then
22+ echo " Error: Git not found. Please install Git to use this script."
23+ echo " You can get Git from:"
24+ echo " - Linux: Most distributions include Git; use your package manager (e.g., 'sudo apt-get install git')"
25+ echo " - macOS: Use Homebrew with 'brew install git'"
26+ echo " - Windows: Download from the official Git website"
27+ exit 1
28+ fi
29+
30+ gitroot=" $( git rev-parse --show-toplevel) "
31+
32+ cd " $gitroot "
33+
34+ docker run -v" $( pwd) :/src" \
35+ --workdir /src \
36+ -u " $( id -u $USER ) :$( id -g $USER ) " \
37+ ghcr.io/pauldreik/clang-format-18:latest \
38+ scripts/clang_format.sh
You can’t perform that action at this time.
0 commit comments