Skip to content

Commit

Permalink
Meta: Switch to clang-format-16 as the standard formatter
Browse files Browse the repository at this point in the history
This includes a few new options to the .clang-format configuration file
to A) adhere to option changes within clang-format 16 (namely the option
AlignTrailingComments), and B) enforce existing style guide rules with
new clang-format rules.
  • Loading branch information
trflynn89 authored and linusg committed Jul 8, 2023
1 parent 1e733b1 commit 388d455
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 26 deletions.
7 changes: 6 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
Language: Cpp
AlignEscapedNewlines: Left
AlignTrailingComments: true
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
BasedOnStyle: WebKit
BraceWrapping:
AfterFunction: true
Expand All @@ -10,7 +12,10 @@ BreakBeforeInheritanceComma: true
BreakConstructorInitializers: BeforeComma
IndentPPDirectives: AfterHash
IndentRequiresClause: false
InsertNewlineAtEOF: true
LineEnding: LF
NamespaceIndentation: None
QualifierAlignment: Right
RequiresClausePosition: WithFollowing
RequiresExpressionIndentation: OuterScope
SpaceAfterTemplateKeyword: false
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:1": {},
"./features/serenity": {
"llvm_version": 15,
"llvm_version": 16,
"enable_ladybird": true,
"enable_serenity": true
},
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/features/serenity/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"llvm_version": {
"type": "string",
"proposals": [
14,
15,
16,
"trunk"
],
"default": 15,
"default": 16,
"description": "Select LLVM compiler version to use"
},
"enable_ladybird": {
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/features/serenity/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

# Feature options

LLVM_VERSION=${LLVM_VERSION:-15}
LLVM_VERSION=${LLVM_VERSION:-16}
ENABLE_LADYBIRD=${ENABLE_LADYBIRD:-true}
ENABLE_SERENITY=${ENABLE_SERENITY:-true}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ jobs:
# Packages below aren't.
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main'
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main'
sudo apt-get update
sudo apt-get install -y clang-format-15 ccache e2fsprogs gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build optipng qemu-utils qemu-system-i386 unzip
sudo apt-get install -y clang-format-16 ccache e2fsprogs gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build optipng qemu-utils qemu-system-i386 unzip
if ${{ matrix.arch == 'aarch64' }}; then
# FIXME: Remove this when we no longer build our own Qemu binary.
sudo apt-get install libgtk-3-dev libpixman-1-dev libsdl2-dev libslirp-dev
Expand All @@ -72,7 +72,7 @@ jobs:
python -m pip install --upgrade pip
pip install flake8 requests
- name: Check versions
run: set +e; g++ --version; g++-12 --version; clang-format --version; clang-format-15 --version; prettier --version; python --version; python3 --version; ninja --version; flake8 --version; ccache --version; qemu-system-i386 --version
run: set +e; g++ --version; g++-12 --version; clang-format --version; clang-format-16 --version; prettier --version; python --version; python3 --version; ninja --version; flake8 --version; ccache --version; qemu-system-i386 --version

# === PREPARE FOR BUILDING ===

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pvs-studio-static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
#
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main'
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main'
sudo apt-get update
sudo apt-get install -y clang-format-15 gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build unzip pvs-studio
sudo apt-get install -y clang-format-16 gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build unzip pvs-studio
- name: Check versions
run: set +e; g++ --version; g++-12 --version; ninja --version;
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonar-cloud-static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ jobs:
# Packages below aren't.
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main'
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main'
sudo apt-get update
sudo apt-get install -y clang-format-15 gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build unzip
sudo apt-get install -y clang-format-16 gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build unzip
- name: Check versions
run: set +e; g++ --version; g++-12 --version; ninja --version;
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Nobody is perfect, and sometimes we mess things up. That said, here are some goo
**Do:**

* Write in idiomatic SerenityOS C++20, using the `AK` containers in all code.
* Conform to the project coding style found in [CodingStyle.md](https://github.com/SerenityOS/serenity/blob/master/Documentation/CodingStyle.md). Use `clang-format` (version 15 or later) to automatically format C++ files. See [AdvancedBuildInstructions.md](https://github.com/SerenityOS/serenity/blob/master/Documentation/AdvancedBuildInstructions.md#clang-format-updates) for instructions on how to get an up-to-date version if your OS distribution does not ship clang-format-15.
* Conform to the project coding style found in [CodingStyle.md](https://github.com/SerenityOS/serenity/blob/master/Documentation/CodingStyle.md). Use `clang-format` (version 16 or later) to automatically format C++ files. See [AdvancedBuildInstructions.md](https://github.com/SerenityOS/serenity/blob/master/Documentation/AdvancedBuildInstructions.md#clang-format-updates) for instructions on how to get an up-to-date version if your OS distribution does not ship clang-format-15.
* Choose expressive variable, function and class names. Make it as obvious as possible what the code is doing.
* Split your changes into separate, atomic commits (i.e. A commit per feature or fix, where the build, tests and the system are all functioning).
* Make sure your commits are rebased on the master branch.
Expand Down
2 changes: 1 addition & 1 deletion Documentation/CodingStyle.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

For low-level styling (spaces, parentheses, brace placement, etc), all code should follow the format specified in `.clang-format` in the project root.

**Important: Make sure you use `clang-format` version 15 or later!**
**Important: Make sure you use `clang-format` version 16 or later!**

This document describes the coding style used for C++ code in the Serenity Operating System project. All new code should conform to this style.

Expand Down
2 changes: 1 addition & 1 deletion Documentation/QtCreatorConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Qt Creator should be set up correctly now, go ahead and explore the project and

## Auto-Formatting

You can use `clang-format` to help you with the [style guide](CodingStyle.md). Before you proceed, check that you're actually using clang-format version 15, as some OSes will ship older clang-format versions by default.
You can use `clang-format` to help you with the [style guide](CodingStyle.md). Before you proceed, check that you're actually using clang-format version 16, as some OSes will ship older clang-format versions by default.

- In QtCreator, go to "Help > About Plugins…"
- Find the `Beautifier (experimental)` row (for example, by typing `beau` into the search)
Expand Down
4 changes: 2 additions & 2 deletions Meta/Azure/Setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ steps:
- script: |
set -e
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main'
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main'
sudo apt-get update
sudo apt-get install clang-format-15 ccache e2fsprogs gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build qemu-utils qemu-system-i386 unzip lld
sudo apt-get install clang-format-16 ccache e2fsprogs gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build qemu-utils qemu-system-i386 unzip lld
displayName: 'Install Dependencies'
- ${{ if eq(parameters.os, 'Linux') }}:
Expand Down
18 changes: 9 additions & 9 deletions Meta/lint-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ fi
if (( ${#files[@]} )); then
TOOLCHAIN_DIR=Toolchain/Local/clang/bin
CLANG_FORMAT=false
if command -v clang-format-15 >/dev/null 2>&1 ; then
CLANG_FORMAT=clang-format-15
elif command -v brew >/dev/null 2>&1 && command -v "$(brew --prefix llvm@15)"/bin/clang-format >/dev/null 2>&1 ; then
CLANG_FORMAT="$(brew --prefix llvm@15)"/bin/clang-format
elif command -v $TOOLCHAIN_DIR/clang-format >/dev/null 2>&1 && $TOOLCHAIN_DIR/clang-format --version | grep -qF ' 15.' ; then
if command -v clang-format-16 >/dev/null 2>&1 ; then
CLANG_FORMAT=clang-format-16
elif command -v brew >/dev/null 2>&1 && command -v "$(brew --prefix llvm@16)"/bin/clang-format >/dev/null 2>&1 ; then
CLANG_FORMAT="$(brew --prefix llvm@16)"/bin/clang-format
elif command -v $TOOLCHAIN_DIR/clang-format >/dev/null 2>&1 && $TOOLCHAIN_DIR/clang-format --version | grep -qF ' 16.' ; then
CLANG_FORMAT=$TOOLCHAIN_DIR/clang-format
elif command -v clang-format >/dev/null 2>&1 ; then
CLANG_FORMAT=clang-format
if ! "${CLANG_FORMAT}" --version | awk '{ if (substr($NF, 1, index($NF, ".") - 1) < 15) exit 1; }'; then
echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 15 or later."
if ! "${CLANG_FORMAT}" --version | awk '{ if (substr($NF, 1, index($NF, ".") - 1) < 16) exit 1; }'; then
echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 16 or later."
echo "It is very likely that the resulting changes are not what you wanted."
fi
else
echo "clang-format-15 is not available, but C or C++ files need linting! Either skip this script, or install clang-format-15."
echo "(If you install a package 'clang-format', please make sure it's version 15 or later.)"
echo "clang-format-16 is not available, but C or C++ files need linting! Either skip this script, or install clang-format-16."
echo "(If you install a package 'clang-format', please make sure it's version 16 or later.)"
exit 1
fi

Expand Down

0 comments on commit 388d455

Please sign in to comment.