From 8639d8bc212dcb45aff80405b4b0f6b1ef1087e7 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 17 Oct 2022 00:05:51 +0200 Subject: [PATCH] Meta: Switch to clang-format-15 as the standard formatter The two major changes noticeable on the SerenityOS codebase are: - Much improved support for const placement, clang-format-14 ignored our east-const configuration in various places - Different formatting for requires clauses, now breaking them onto their own line, which helps with readability a bit Current versions of CLion also ship LLVM 15, so the built-in formatting now matches CI formatting again :^) --- .clang-format | 2 ++ .github/workflows/cmake.yml | 6 +++--- .../workflows/pvs-studio-static-analysis.yml | 4 ++-- .../workflows/sonar-cloud-static-analysis.yml | 4 ++-- Documentation/SelfHostedRunners.md | 4 ++-- Meta/Azure/Setup.yml | 4 ++-- Meta/lint-clang-format.sh | 18 +++++++++--------- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.clang-format b/.clang-format index 61e0467fa65..9b7a6b629df 100644 --- a/.clang-format +++ b/.clang-format @@ -12,3 +12,5 @@ BraceWrapping: AfterFunction: true NamespaceIndentation: None QualifierAlignment: Right +RequiresClausePosition: WithFollowing +IndentRequiresClause: false diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a40ad367091..56575891824 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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-14 main' + sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main' sudo apt-get update - sudo apt-get install -y clang-format-14 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-15 ccache e2fsprogs gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build optipng qemu-utils qemu-system-i386 unzip - name: Install JS dependencies run: sudo npm install -g prettier@2.7.1 - name: Install Python dependencies @@ -68,7 +68,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-14 --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-15 --version; prettier --version; python --version; python3 --version; ninja --version; flake8 --version; ccache --version; qemu-system-i386 --version # === PREPARE FOR BUILDING === diff --git a/.github/workflows/pvs-studio-static-analysis.yml b/.github/workflows/pvs-studio-static-analysis.yml index fc08333cb88..733eb0a0448 100644 --- a/.github/workflows/pvs-studio-static-analysis.yml +++ b/.github/workflows/pvs-studio-static-analysis.yml @@ -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-14 main' + sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main' sudo apt-get update - sudo apt-get install -y clang-format-14 gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build unzip pvs-studio + sudo apt-get install -y clang-format-15 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; diff --git a/.github/workflows/sonar-cloud-static-analysis.yml b/.github/workflows/sonar-cloud-static-analysis.yml index ecaed3111be..415c38c20e0 100644 --- a/.github/workflows/sonar-cloud-static-analysis.yml +++ b/.github/workflows/sonar-cloud-static-analysis.yml @@ -59,9 +59,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-14 main' + sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main' sudo apt-get update - sudo apt-get install -y clang-format-14 gcc-12 g++-12 libstdc++-12-dev libmpfr-dev libmpc-dev ninja-build unzip + sudo apt-get install -y clang-format-15 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; diff --git a/Documentation/SelfHostedRunners.md b/Documentation/SelfHostedRunners.md index fb99c251c4e..d8ed616824e 100644 --- a/Documentation/SelfHostedRunners.md +++ b/Documentation/SelfHostedRunners.md @@ -20,9 +20,9 @@ These instructions assume the OS installed is Ubuntu 22.04 (Jammy), so they migh ```shell sudo add-apt-repository ppa:canonical-server/server-backports 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-focal-14 main' +sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main' apt update -apt install git build-essential make cmake clang-format-14 gcc-12 g++-12 libstdc++-12-dev libgmp-dev ccache libmpfr-dev libmpc-dev ninja-build e2fsprogs qemu-utils qemu-system-i386 wabt +apt install git build-essential make cmake clang-format-15 gcc-12 g++-12 libstdc++-12-dev libgmp-dev ccache libmpfr-dev libmpc-dev ninja-build e2fsprogs qemu-utils qemu-system-i386 wabt ``` ### Force usage of GCC 12 ```shell diff --git a/Meta/Azure/Setup.yml b/Meta/Azure/Setup.yml index 97fc47f662c..c24b7eb5ca3 100644 --- a/Meta/Azure/Setup.yml +++ b/Meta/Azure/Setup.yml @@ -8,9 +8,9 @@ steps: - ${{ if eq(parameters.os, 'Serenity') }}: - script: | 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-14 main' + sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main' sudo apt-get update - sudo apt-get install clang-format-14 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-15 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') }}: diff --git a/Meta/lint-clang-format.sh b/Meta/lint-clang-format.sh index 66414763025..d8746c19842 100755 --- a/Meta/lint-clang-format.sh +++ b/Meta/lint-clang-format.sh @@ -28,21 +28,21 @@ fi if (( ${#files[@]} )); then TOOLCHAIN_DIR=Toolchain/Local/clang/bin CLANG_FORMAT=false - if command -v clang-format-14 >/dev/null 2>&1 ; then - CLANG_FORMAT=clang-format-14 - elif command -v brew >/dev/null 2>&1 && command -v "$(brew --prefix llvm@14)"/bin/clang-format >/dev/null 2>&1 ; then - CLANG_FORMAT="$(brew --prefix llvm@14)"/bin/clang-format - elif command -v $TOOLCHAIN_DIR/clang-format >/dev/null 2>&1 && $TOOLCHAIN_DIR/clang-format --version | grep -qF ' 14.' ; then + 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 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) < 14) exit 1; }'; then - echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 14 or later." + 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." echo "It is very likely that the resulting changes are not what you wanted." fi else - echo "clang-format-14 is not available, but C or C++ files need linting! Either skip this script, or install clang-format-14." - echo "(If you install a package 'clang-format', please make sure it's version 14 or later.)" + 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.)" exit 1 fi