diff --git a/.clang-format b/.clang-format index 9ec7ad886..6dbc0244d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,4 @@ --- -Language: Cpp # BasedOnStyle: Chromium AccessModifierOffset: -2 AlignAfterOpenBracket: Align @@ -11,7 +10,8 @@ AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: true -AllowShortFunctionsOnASingleLine: Inline +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortLambdasOnASingleLine: All AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None @@ -21,6 +21,7 @@ AlwaysBreakTemplateDeclarations: true BinPackArguments: true BinPackParameters: true BraceWrapping: + AfterCaseLabel: true AfterClass: true AfterControlStatement: true AfterEnum: true @@ -44,7 +45,9 @@ ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false +EmptyLineBeforeAccessModifier: Leave ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] IncludeCategories: - Regex: '<.*\.h>' @@ -55,6 +58,7 @@ IncludeCategories: Priority: 3 - Regex: '.*' Priority: 4 +IncludeIsMainRegex: '' IndentCaseLabels: true IndentWidth: 2 IndentWrappedFunctionNames: false @@ -63,7 +67,9 @@ MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None +ObjCBinPackProtocolList: Never ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: false PenaltyBreakBeforeFirstCallParameter: 1 @@ -75,18 +81,33 @@ PenaltyReturnTypeOnItsOwnLine: 2000 PointerAlignment: Right ReflowComments: true SortIncludes: true +SortUsingDeclarations: false SpaceAfterCStyleCast: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: Never SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 4 -SpacesInAngles: false +SpacesInAngles: Never SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Auto +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION + - BEGIN_ENUM_STRINGISE + - BEGIN_ENUM_CLASS_STRINGISE + - STRINGISE_ENUM + - STRINGISE_ENUM_CLASS + - STRINGISE_ENUM_NAMED + - STRINGISE_ENUM_CLASS_NAMED + - STRINGISE_BITFIELD_BIT TabWidth: 2 UseTab: Never +--- +Language: Cpp +--- +Language: ObjC ... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f0b13fdc..c583aaa59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,17 +42,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 5 - - name: Add LLVM apt repository - run: | - wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo add-apt-repository -y 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.8 main' - sudo apt-get update - curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb - sudo dpkg -i libffi6_3.2.1-8_amd64.deb - - name: Install clang-format-3.8 - run: | - sudo apt-get install -y clang-format-3.8 - - name: Run clang-format-3.8 + - name: Run clang-format run: | . ./util/clang_format_all.sh git clean -f diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 46f4fb4a8..d00ea7c09 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -41,7 +41,7 @@ Commit messages should have a first line with a **maximum of 72 characters**, th For more information, check the section about [commit messages](CONTRIBUTING/Preparing-Commits.md#commit-messages). -Code should be formatted using **clang-format 3.8**. The reason we fix a specific version of clang-format is that unfortunately different versions can format code in different ways using the same config file, so this would cause problems with automatic verification of code formatting. +Code should be formatted using **clang-format 15.0**. The reason we fix a specific version of clang-format is that unfortunately different versions can format code in different ways using the same config file, so this would cause problems with automatic verification of code formatting. For more information, check the section about [code formatting](CONTRIBUTING/Preparing-Commits.md#code-formatting). diff --git a/docs/CONTRIBUTING/Preparing-Commits.md b/docs/CONTRIBUTING/Preparing-Commits.md index f677c6c61..a8376555c 100644 --- a/docs/CONTRIBUTING/Preparing-Commits.md +++ b/docs/CONTRIBUTING/Preparing-Commits.md @@ -20,11 +20,13 @@ Likewise commits for code formatting or compile fixes should be squashed into th To make things easier for everyone, I've adopted clang-format for keeping code consistently formatted. -| :warning: | | :warning: | -| --------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------- | -| :warning: | **Unfortunately clang-format output changes between versions even with the same config.** | :warning: | -| :warning: | **I have fixed the version used for RenderDoc at [clang-format-3.8](http://releases.llvm.org/download.html#3.8.1).** | :warning: | -| :warning: | **This formatting is enforced by CI checks that run on PRs, so if you aren't running the same version locally it will show up there.** | :warning: | +| :warning: | | :warning: | +| --------- | ----------------------------------------------------------------------------------------------------------------------------------------- | --------- | +| :warning: | **Unfortunately clang-format output changes between versions even with the same config.** | :warning: | +| :warning: | **I have fixed the version used for RenderDoc at [clang-format-15.0](https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7).** | :warning: | +| :warning: | **This formatting is enforced by CI checks that run on PRs, so if you aren't running the same version locally it will show up there.** | :warning: | + +This version changed as of 2023-09-02, from clang-format-3.8 to clang-format-15.0. A statically linked binary of clang-format-15.0.7 for x64 windows and linux is committed to the repo under util/clangformat. If you want to format a single file, run: `clang-format -i file.cpp`. If you want to format any changes you make before you commit them, you'll need python installed and then run: `git clang-format`. To clang-format the whole codebase, you can run the bash script `util/clang_format_all.sh` but be sure to squash any changes into the right commits. diff --git a/util/clang_format_all.sh b/util/clang_format_all.sh index bc0043a09..b1f81455e 100755 --- a/util/clang_format_all.sh +++ b/util/clang_format_all.sh @@ -1,7 +1,7 @@ #!/bin/sh -CLANG_MAJOR=3 -CLANG_MINOR=8 +CLANG_MAJOR=15 +CLANG_MINOR=0 CLANG_FORMAT_VERSION=$CLANG_MAJOR.$CLANG_MINOR @@ -47,12 +47,24 @@ fi; # Check if we have a valid $CLANG_FORMAT if ! valid_clang_format; then - # If we didn't find one, bail out + SCRIPTDIR=$(dirname $(readlink -f $0)); + # If we didn't find one, fall back to repo-included binary. Check it can run + if "${SCRIPTDIR}"/clangformat/clang-format-15.0.exe --version 2>&1 | grep -q 15.0.7; + then + CLANG_FORMAT="${SCRIPTDIR}"/clangformat/clang-format-15.0.exe + elif "${SCRIPTDIR}"/clangformat/clang-format-15.0 --version 2>&1 | grep -q 15.0.7; + then + CLANG_FORMAT="${SCRIPTDIR}"/clangformat/clang-format-15.0 + fi +fi + +if ! valid_clang_format; then echo "Couldn't find correct clang-format version, was looking for $CLANG_FORMAT_VERSION" echo "Renderdoc requires a very specific clang-format version to ensure there isn't any" echo "variance between versions that can happen. You can install it as" echo "'clang-format-$CLANG_FORMAT_VERSION' so that it doesn't interfere with any other" echo "versions you might have installed, and this script will find it there" + echo "The repository includes a windows and linux x64 binary version, but it failed to run." exit 1; fi; diff --git a/util/clangformat/README.md b/util/clangformat/README.md new file mode 100644 index 000000000..7ee4cc30c --- /dev/null +++ b/util/clangformat/README.md @@ -0,0 +1,8 @@ +# Building static clang-format + +The docker script will build and static link clang-format to make a portable static linked binary. + +``` +docker run --rm -v $(pwd):/script:ro -v $(pwd):/out ubuntu:jammy bash /script/build.sh +``` + diff --git a/util/clangformat/build.sh b/util/clangformat/build.sh new file mode 100644 index 000000000..7e58b2e6f --- /dev/null +++ b/util/clangformat/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e +set -x + +apt-get update +apt-get install -y git cmake python3 gcc g++ + +git clone --depth=5 https://github.com/llvm/llvm-project --branch llvmorg-15.0.7 +mkdir llvm-build +cd llvm-build +cmake /llvm-project/llvm -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_EXE_LINKER_FLAGS=-static -DCMAKE_BUILD_TYPE=Release +make -j8 clang-format +strip --strip-unneeded bin/clang-format +cp bin/clang-format /out diff --git a/util/clangformat/clang-format-15.0 b/util/clangformat/clang-format-15.0 new file mode 100755 index 000000000..a902a3480 Binary files /dev/null and b/util/clangformat/clang-format-15.0 differ diff --git a/util/clangformat/clang-format-15.0.exe b/util/clangformat/clang-format-15.0.exe new file mode 100644 index 000000000..fe4eae18b Binary files /dev/null and b/util/clangformat/clang-format-15.0.exe differ