Add more static checks and move to separate file to match main repo

pull/887/head
Aaron Franke 2022-10-09 01:25:44 -05:00
parent f69f1bb58f
commit bcfa3bf320
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
8 changed files with 223 additions and 77 deletions

View File

@ -1,31 +1,40 @@
# Commented out parameters are those with the same value as base LLVM style # Commented out parameters are those with the same value as base LLVM style.
# We can uncomment them if we want to change their value, or enforce the # We can uncomment them if we want to change their value, or enforce the
# chosen value in case the base style changes (last sync: Clang 6.0.1). # chosen value in case the base style changes (last sync: Clang 14.0).
--- ---
### General config, applies to all languages ### ### General config, applies to all languages ###
BasedOnStyle: LLVM BasedOnStyle: LLVM
AccessModifierOffset: -4 AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign AlignAfterOpenBracket: DontAlign
# AlignConsecutiveAssignments: false # AlignArrayOfStructures: None
# AlignConsecutiveDeclarations: false # AlignConsecutiveMacros: None
# AlignConsecutiveAssignments: None
# AlignConsecutiveBitFields: None
# AlignConsecutiveDeclarations: None
# AlignEscapedNewlines: Right # AlignEscapedNewlines: Right
# AlignOperands: true AlignOperands: DontAlign
AlignTrailingComments: false AlignTrailingComments: false
# AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false
# AllowShortBlocksOnASingleLine: false # AllowShortEnumsOnASingleLine: true
# AllowShortBlocksOnASingleLine: Never
# AllowShortCaseLabelsOnASingleLine: false # AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline # AllowShortFunctionsOnASingleLine: All
# AllowShortIfStatementsOnASingleLine: false # AllowShortLambdasOnASingleLine: All
# AllowShortIfStatementsOnASingleLine: Never
# AllowShortLoopsOnASingleLine: false # AllowShortLoopsOnASingleLine: false
# AlwaysBreakAfterDefinitionReturnType: None # AlwaysBreakAfterDefinitionReturnType: None
# AlwaysBreakAfterReturnType: None # AlwaysBreakAfterReturnType: None
# AlwaysBreakBeforeMultilineStrings: false # AlwaysBreakBeforeMultilineStrings: false
# AlwaysBreakTemplateDeclarations: false # AlwaysBreakTemplateDeclarations: MultiLine
# AttributeMacros:
# - __capability
# BinPackArguments: true # BinPackArguments: true
# BinPackParameters: true # BinPackParameters: true
# BraceWrapping: # BraceWrapping:
# AfterCaseLabel: false
# AfterClass: false # AfterClass: false
# AfterControlStatement: false # AfterControlStatement: Never
# AfterEnum: false # AfterEnum: false
# AfterFunction: false # AfterFunction: false
# AfterNamespace: false # AfterNamespace: false
@ -35,32 +44,44 @@ AllowShortFunctionsOnASingleLine: Inline
# AfterExternBlock: false # AfterExternBlock: false
# BeforeCatch: false # BeforeCatch: false
# BeforeElse: false # BeforeElse: false
# BeforeLambdaBody: false
# BeforeWhile: false
# IndentBraces: false # IndentBraces: false
# SplitEmptyFunction: true # SplitEmptyFunction: true
# SplitEmptyRecord: true # SplitEmptyRecord: true
# SplitEmptyNamespace: true # SplitEmptyNamespace: true
# BreakBeforeBinaryOperators: None # BreakBeforeBinaryOperators: None
# BreakBeforeConceptDeclarations: true
# BreakBeforeBraces: Attach # BreakBeforeBraces: Attach
# BreakBeforeInheritanceComma: false # BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false # BreakInheritanceList: BeforeColon
# BreakBeforeTernaryOperators: true
# BreakConstructorInitializersBeforeComma: false # BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon BreakConstructorInitializers: AfterColon
# BreakStringLiterals: true # BreakStringLiterals: true
ColumnLimit: 0 ColumnLimit: 0
# CommentPragmas: '^ IWYU pragma:' # CommentPragmas: '^ IWYU pragma:'
# QualifierAlignment: Leave
# CompactNamespaces: false # CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 8 ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8 ContinuationIndentWidth: 8
Cpp11BracedListStyle: false Cpp11BracedListStyle: false
# DeriveLineEnding: true
# DerivePointerAlignment: false # DerivePointerAlignment: false
# DisableFormat: false # DisableFormat: false
# EmptyLineAfterAccessModifier: Never
# EmptyLineBeforeAccessModifier: LogicalBlock
# ExperimentalAutoDetectBinPacking: false # ExperimentalAutoDetectBinPacking: false
# PackConstructorInitializers: BinPack
ConstructorInitializerAllOnOneLineOrOnePerLine: true
# AllowAllConstructorInitializersOnNextLine: true
# FixNamespaceComments: true # FixNamespaceComments: true
# ForEachMacros: # ForEachMacros:
# - foreach # - foreach
# - Q_FOREACH # - Q_FOREACH
# - BOOST_FOREACH # - BOOST_FOREACH
# IfMacros:
# - KJ_IF_MAYBE
# IncludeBlocks: Preserve # IncludeBlocks: Preserve
IncludeCategories: IncludeCategories:
- Regex: '".*"' - Regex: '".*"'
@ -70,13 +91,21 @@ IncludeCategories:
- Regex: '^<.*' - Regex: '^<.*'
Priority: 3 Priority: 3
# IncludeIsMainRegex: '(Test)?$' # IncludeIsMainRegex: '(Test)?$'
# IncludeIsMainSourceRegex: ''
# IndentAccessModifiers: false
IndentCaseLabels: true IndentCaseLabels: true
# IndentCaseBlocks: false
# IndentGotoLabels: true
# IndentPPDirectives: None # IndentPPDirectives: None
# IndentExternBlock: AfterExternBlock
# IndentRequires: false
IndentWidth: 4 IndentWidth: 4
# IndentWrappedFunctionNames: false # IndentWrappedFunctionNames: false
# InsertTrailingCommas: None
# JavaScriptQuotes: Leave # JavaScriptQuotes: Leave
# JavaScriptWrapImports: true # JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: false
# LambdaBodyIndentation: Signature
# MacroBlockBegin: '' # MacroBlockBegin: ''
# MacroBlockEnd: '' # MacroBlockEnd: ''
# MaxEmptyLinesToKeep: 1 # MaxEmptyLinesToKeep: 1
@ -85,39 +114,81 @@ KeepEmptyLinesAtTheStartOfBlocks: false
# PenaltyBreakBeforeFirstCallParameter: 19 # PenaltyBreakBeforeFirstCallParameter: 19
# PenaltyBreakComment: 300 # PenaltyBreakComment: 300
# PenaltyBreakFirstLessLess: 120 # PenaltyBreakFirstLessLess: 120
# PenaltyBreakOpenParenthesis: 0
# PenaltyBreakString: 1000 # PenaltyBreakString: 1000
# PenaltyBreakTemplateDeclaration: 10
# PenaltyExcessCharacter: 1000000 # PenaltyExcessCharacter: 1000000
# PenaltyReturnTypeOnItsOwnLine: 60 # PenaltyReturnTypeOnItsOwnLine: 60
# PenaltyIndentedWhitespace: 0
# PointerAlignment: Right # PointerAlignment: Right
# RawStringFormats: # PPIndentWidth: -1
# - Delimiter: pb # ReferenceAlignment: Pointer
# Language: TextProto
# BasedOnStyle: google
# ReflowComments: true # ReflowComments: true
# SortIncludes: true # RemoveBracesLLVM: false
# SeparateDefinitionBlocks: Leave
# ShortNamespaceLines: 1
# SortIncludes: CaseSensitive
# SortJavaStaticImport: Before
# SortUsingDeclarations: true # SortUsingDeclarations: true
# SpaceAfterCStyleCast: false # SpaceAfterCStyleCast: false
# SpaceAfterLogicalNot: false
# SpaceAfterTemplateKeyword: true # SpaceAfterTemplateKeyword: true
# SpaceBeforeAssignmentOperators: true # SpaceBeforeAssignmentOperators: true
# SpaceBeforeCaseColon: false
# SpaceBeforeCpp11BracedList: false
# SpaceBeforeCtorInitializerColon: true
# SpaceBeforeInheritanceColon: true
# SpaceBeforeParens: ControlStatements # SpaceBeforeParens: ControlStatements
# SpaceBeforeParensOptions:
# AfterControlStatements: true
# AfterForeachMacros: true
# AfterFunctionDefinitionName: false
# AfterFunctionDeclarationName: false
# AfterIfMacros: true
# AfterOverloadedOperator: false
# BeforeNonEmptyParentheses: false
# SpaceAroundPointerQualifiers: Default
# SpaceBeforeRangeBasedForLoopColon: true
# SpaceInEmptyBlock: false
# SpaceInEmptyParentheses: false # SpaceInEmptyParentheses: false
# SpacesBeforeTrailingComments: 1 # SpacesBeforeTrailingComments: 1
# SpacesInAngles: false # SpacesInAngles: Never
# SpacesInConditionalStatement: false
# SpacesInContainerLiterals: true # SpacesInContainerLiterals: true
# SpacesInCStyleCastParentheses: false # SpacesInCStyleCastParentheses: false
## Godot TODO: We'll want to use a min of 1, but we need to see how to fix
## our comment capitalization at the same time.
SpacesInLineCommentPrefix:
Minimum: 0
Maximum: -1
# SpacesInParentheses: false # SpacesInParentheses: false
# SpacesInSquareBrackets: false # SpacesInSquareBrackets: false
# SpaceBeforeSquareBrackets: false
# BitFieldColonSpacing: Both
# StatementAttributeLikeMacros:
# - Q_EMIT
# StatementMacros:
# - Q_UNUSED
# - QT_REQUIRE_VERSION
TabWidth: 4 TabWidth: 4
# UseCRLF: false
UseTab: Always UseTab: Always
# WhitespaceSensitiveMacros:
# - STRINGIZE
# - PP_STRINGIZE
# - BOOST_PP_STRINGIZE
# - NS_SWIFT_NAME
# - CF_SWIFT_NAME
--- ---
### C++ specific config ### ### C++ specific config ###
Language: Cpp Language: Cpp
Standard: Cpp11 Standard: c++17
--- ---
### ObjC specific config ### ### ObjC specific config ###
Language: ObjC Language: ObjC
Standard: Cpp11 # ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4 ObjCBlockIndentWidth: 4
# ObjCBreakBeforeNestedBlockParam: true
# ObjCSpaceAfterProperty: false # ObjCSpaceAfterProperty: false
# ObjCSpaceBeforeProtocolList: true # ObjCSpaceBeforeProtocolList: true
--- ---

View File

@ -192,35 +192,3 @@ jobs:
run: | run: |
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -G"Visual Studio 16 2019" . cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -G"Visual Studio 16 2019" .
cmake --build . --verbose cmake --build . --verbose
static-checks:
name: 📊 Static Checks (clang-format)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Make apt sources.list use the default Ubuntu repositories
run: |
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
sudo apt-get update
- name: Install dependencies
run: |
sudo apt-get install -qq dos2unix recode clang-format-11
sudo update-alternatives --remove-all clang-format
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100
python -m pip install black==22.3.0
- name: Style checks via clang-format
run: |
bash ./misc/scripts/clang_format.sh
- name: Python style checks via black (black_format.sh)
run: |
bash ./misc/scripts/black_format.sh
- name: Bindings generation checks (ensures get_file_list returns all generated files)
run: |
python ./misc/scripts/check_get_file_list.py

54
.github/workflows/static_checks.yml vendored Normal file
View File

@ -0,0 +1,54 @@
name: 📊 Static Checks
on: [push, pull_request]
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-static
cancel-in-progress: true
jobs:
static-checks:
name: Format (clang-format, black format, file format)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
# Azure repositories are not reliable, we need to prevent Azure giving us packages.
- name: Make apt sources.list use the default Ubuntu repositories
run: |
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main"
sudo apt-get update
- name: Install dependencies
run: |
sudo apt-get install -qq dos2unix recode clang-format-13 libxml2-utils python3-pip moreutils
sudo update-alternatives --remove-all clang-format || true
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-13 100
sudo pip3 install black==22.3.0 pygments pytest==7.1.2 mypy==0.971
- name: File formatting checks (file_format.sh)
run: |
bash ./misc/scripts/file_format.sh
- name: Header guards formatting checks (header_guards.sh)
run: |
bash ./misc/scripts/header_guards.sh
- name: Python style checks via black (black_format.sh)
run: |
bash ./misc/scripts/black_format.sh
- name: Python scripts static analysis (mypy_check.sh)
run: |
bash ./misc/scripts/mypy_check.sh
- name: Bindings generation checks (ensures get_file_list returns all generated files)
run: |
python ./misc/scripts/check_get_file_list.py
- name: Style checks via clang-format (clang_format.sh)
run: |
bash ./misc/scripts/clang_format.sh

View File

@ -6,8 +6,7 @@
set -uo pipefail set -uo pipefail
# Loops through all code files tracked by Git. # Loops through all code files tracked by Git.
git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' '*.java' '*.glsl' \ git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' |
':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' |
while read -r f; do while read -r f; do
# Run clang-format. # Run clang-format.
clang-format --Wno-error=unknown -i "$f" clang-format --Wno-error=unknown -i "$f"

View File

@ -15,29 +15,6 @@ IFS=$'\n\t'
# Loops through all text files tracked by Git. # Loops through all text files tracked by Git.
git grep -zIl '' | git grep -zIl '' |
while IFS= read -rd '' f; do while IFS= read -rd '' f; do
# Exclude some types of files.
if [[ "$f" == *"csproj" ]]; then
continue
elif [[ "$f" == *"sln" ]]; then
continue
elif [[ "$f" == *".bat" ]]; then
continue
elif [[ "$f" == *".out" ]]; then
# GDScript integration testing files.
continue
elif [[ "$f" == *"patch" ]]; then
continue
elif [[ "$f" == *"pot" ]]; then
continue
elif [[ "$f" == *"po" ]]; then
continue
elif [[ "$f" == "thirdparty"* ]]; then
continue
elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
continue
elif [[ "$f" == *"-so_wrap."* ]]; then
continue
fi
# Ensure that files are UTF-8 formatted. # Ensure that files are UTF-8 formatted.
recode UTF-8 "$f" 2> /dev/null recode UTF-8 "$f" 2> /dev/null
# Ensure that files have LF line endings and do not contain a BOM. # Ensure that files have LF line endings and do not contain a BOM.

60
misc/scripts/header_guards.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash
if [ ! -f "SConstruct" ]; then
echo "Warning: This script is intended to be run from the root of the Godot repository."
echo "Some of the paths checks may not work as intended from a different folder."
fi
files_invalid_guard=""
for file in $(find . -name "*.hpp" -print); do
# Skip generated files.
if [[ "$file" == "./gen/"* || "$file" == "./include/gen/"* ]]; then continue; fi
# Skip the test project.
if [[ "$file" == "./test/"* ]]; then continue; fi
bname=$(basename $file .hpp)
# NOTE: The "GODOT_CPP_" prefix is already used by the generated
# bindings, so we can't use that. We'll use "GODOT_" instead.
prefix="GODOT_"
# ^^ is bash builtin for UPPERCASE.
guard="${prefix}${bname^^}_HPP"
# Replaces guards to use computed name.
# We also add some \n to make sure there's a proper separation.
sed -i $file -e "0,/ifndef/s/#ifndef.*/\n#ifndef $guard/"
sed -i $file -e "0,/define/s/#define.*/#define $guard\n/"
sed -i $file -e "$ s/#endif.*/\n#endif \/\/ $guard/"
# Removes redundant \n added before, if they weren't needed.
sed -i $file -e "/^$/N;/^\n$/D"
# Check that first ifndef (should be header guard) is at the expected position.
# If not it can mean we have some code before the guard that should be after.
# "31" is the expected line with the copyright header.
first_ifndef=$(grep -n -m 1 "ifndef" $file | sed 's/\([0-9]*\).*/\1/')
if [[ "$first_ifndef" != "31" ]]; then
files_invalid_guard+="$file\n"
fi
done
if [[ ! -z "$files_invalid_guard" ]]; then
echo -e "The following files were found to have potentially invalid header guard:\n"
echo -e "$files_invalid_guard"
fi
diff=$(git diff --color)
# If no diff has been generated all is OK, clean up, and exit.
if [ -z "$diff" ] ; then
printf "Files in this commit comply with the header guards formatting rules.\n"
exit 0
fi
# A diff has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the header guards formatting rules:\n\n"
echo "$diff"
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
exit 1

11
misc/scripts/mypy.ini Normal file
View File

@ -0,0 +1,11 @@
[mypy]
ignore_missing_imports = true
disallow_any_generics = True
pretty = True
show_column_numbers = True
warn_redundant_casts = True
warn_return_any = True
warn_unreachable = True
namespace_packages = True
explicit_package_bases = True

6
misc/scripts/mypy_check.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -uo pipefail
echo -e "Python: mypy static analysis..."
mypy --config-file=./misc/scripts/mypy.ini .