summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format128
-rw-r--r--.github/workflows/build_release.yml27
-rwxr-xr-xmisc/scripts/black_format.sh34
-rwxr-xr-xmisc/scripts/clang_format.sh58
-rwxr-xr-xmisc/scripts/copyright_headers.py95
-rwxr-xr-xmisc/scripts/file_format.sh48
6 files changed, 390 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..1c26421
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,128 @@
+# 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
+# chosen value in case the base style changes (last sync: Clang 6.0.1).
+---
+### General config, applies to all languages ###
+BasedOnStyle: LLVM
+AccessModifierOffset: -4
+AlignAfterOpenBracket: DontAlign
+# AlignConsecutiveAssignments: false
+# AlignConsecutiveDeclarations: false
+# AlignEscapedNewlines: Right
+# AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+# AllowShortBlocksOnASingleLine: false
+# AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Inline
+# AllowShortIfStatementsOnASingleLine: false
+# AllowShortLoopsOnASingleLine: false
+# AlwaysBreakAfterDefinitionReturnType: None
+# AlwaysBreakAfterReturnType: None
+# AlwaysBreakBeforeMultilineStrings: false
+# AlwaysBreakTemplateDeclarations: false
+# BinPackArguments: true
+# BinPackParameters: true
+# BraceWrapping:
+# AfterClass: false
+# AfterControlStatement: false
+# AfterEnum: false
+# AfterFunction: false
+# AfterNamespace: false
+# AfterObjCDeclaration: false
+# AfterStruct: false
+# AfterUnion: false
+# AfterExternBlock: false
+# BeforeCatch: false
+# BeforeElse: false
+# IndentBraces: false
+# SplitEmptyFunction: true
+# SplitEmptyRecord: true
+# SplitEmptyNamespace: true
+# BreakBeforeBinaryOperators: None
+# BreakBeforeBraces: Attach
+# BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+# BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: AfterColon
+# BreakStringLiterals: true
+ColumnLimit: 0
+# CommentPragmas: '^ IWYU pragma:'
+# CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+# DerivePointerAlignment: false
+# DisableFormat: false
+# ExperimentalAutoDetectBinPacking: false
+# FixNamespaceComments: true
+# ForEachMacros:
+# - foreach
+# - Q_FOREACH
+# - BOOST_FOREACH
+# IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '".*"'
+ Priority: 1
+ - Regex: '^<.*\.h>'
+ Priority: 2
+ - Regex: '^<.*'
+ Priority: 3
+# IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: true
+# IndentPPDirectives: None
+IndentWidth: 4
+# IndentWrappedFunctionNames: false
+# JavaScriptQuotes: Leave
+# JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+# MacroBlockBegin: ''
+# MacroBlockEnd: ''
+# MaxEmptyLinesToKeep: 1
+# NamespaceIndentation: None
+# PenaltyBreakAssignment: 2
+# PenaltyBreakBeforeFirstCallParameter: 19
+# PenaltyBreakComment: 300
+# PenaltyBreakFirstLessLess: 120
+# PenaltyBreakString: 1000
+# PenaltyExcessCharacter: 1000000
+# PenaltyReturnTypeOnItsOwnLine: 60
+# PointerAlignment: Right
+# RawStringFormats:
+# - Delimiter: pb
+# Language: TextProto
+# BasedOnStyle: google
+# ReflowComments: true
+# SortIncludes: true
+# SortUsingDeclarations: true
+# SpaceAfterCStyleCast: false
+# SpaceAfterTemplateKeyword: true
+# SpaceBeforeAssignmentOperators: true
+# SpaceBeforeParens: ControlStatements
+# SpaceInEmptyParentheses: false
+# SpacesBeforeTrailingComments: 1
+# SpacesInAngles: false
+# SpacesInContainerLiterals: true
+# SpacesInCStyleCastParentheses: false
+# SpacesInParentheses: false
+# SpacesInSquareBrackets: false
+TabWidth: 4
+UseTab: Always
+---
+### C++ specific config ###
+Language: Cpp
+Standard: Cpp11
+---
+### ObjC specific config ###
+Language: ObjC
+Standard: Cpp11
+ObjCBlockIndentWidth: 4
+# ObjCSpaceAfterProperty: false
+# ObjCSpaceBeforeProtocolList: true
+---
+### Java specific config ###
+Language: Java
+# BreakAfterJavaFieldAnnotations: false
+JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax']
+...
diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml
index 0205afa..19a59c9 100644
--- a/.github/workflows/build_release.yml
+++ b/.github/workflows/build_release.yml
@@ -2,9 +2,36 @@ name: 🔧 Build -> Package 📦
on: [push, pull_request]
jobs:
+ static-checks:
+ name: 📊 Static Checks (clang-format, black format, file format)
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+
+ - 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
+ sudo pip3 install black==20.8b1 pygments
+
+ - name: File formatting checks (file_format.sh)
+ run: |
+ bash ./misc/scripts/file_format.sh
+
+ - name: Style checks via clang-format (clang_format.sh)
+ run: |
+ bash ./misc/scripts/clang_format.sh
+
+ - name: Python style checks via black (black_format.sh)
+ run: |
+ bash ./misc/scripts/black_format.sh
+
build:
runs-on: ${{ matrix.os }}
name: 🔧 Build
+ needs: static-checks
strategy:
matrix:
include:
diff --git a/misc/scripts/black_format.sh b/misc/scripts/black_format.sh
new file mode 100755
index 0000000..f6b7925
--- /dev/null
+++ b/misc/scripts/black_format.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+# This script runs black on all Python files in the repo.
+
+set -uo pipefail
+
+# Apply black.
+echo -e "Formatting Python files..."
+PY_FILES=$(find \( -path "./.git" \
+ -o -path "./webrtc" \
+ -o -path "./godot-cpp" \
+ \) -prune \
+ -o \( -name "SConstruct" \
+ -o -name "SCsub" \
+ -o -name "*.py" \
+ \) -print)
+black -l 120 $PY_FILES
+
+git diff > patch.patch
+
+# If no patch has been generated all is OK, clean up, and exit.
+if [ ! -s patch.patch ] ; then
+ printf "Files in this commit comply with the black style rules.\n"
+ rm -f patch.patch
+ exit 0
+fi
+
+# A patch has been created, notify the user, clean up, and exit.
+printf "\n*** The following differences were found between the code "
+printf "and the formatting rules:\n\n"
+cat patch.patch
+printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
+rm -f patch.patch
+exit 1
diff --git a/misc/scripts/clang_format.sh b/misc/scripts/clang_format.sh
new file mode 100755
index 0000000..63c66d4
--- /dev/null
+++ b/misc/scripts/clang_format.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+
+# This script runs clang-format and fixes copyright headers on all relevant files in the repo.
+# This is the primary script responsible for fixing style violations.
+
+set -uo pipefail
+IFS=$'\n\t'
+
+CLANG_FORMAT_FILE_EXTS=(".c" ".h" ".cpp" ".hpp" ".cc" ".hh" ".cxx" ".m" ".mm" ".inc" ".java" ".glsl")
+
+# Loops through all text files tracked by Git.
+git grep -zIl '' |
+while IFS= read -rd '' f; do
+ # Exclude some files.
+ if [[ "$f" == "thirdparty"* ]]; then
+ continue
+ elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
+ continue
+ elif [[ "$f" == *"-so_wrap."* ]]; then
+ continue
+ fi
+
+ for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do
+ if [[ "$f" == *"$extension" ]]; then
+ # Run clang-format.
+ clang-format -i "$f"
+ # Fix copyright headers, but not all files get them.
+ if [[ "$f" == *"inc" ]]; then
+ continue 2
+ elif [[ "$f" == *"glsl" ]]; then
+ continue 2
+ elif [[ "$f" == *"theme_data.h" ]]; then
+ continue 2
+ elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/input/InputManager"* ]]; then
+ continue 2
+ fi
+ python misc/scripts/copyright_headers.py "$f"
+ continue 2
+ fi
+ done
+done
+
+git diff > patch.patch
+
+# If no patch has been generated all is OK, clean up, and exit.
+if [ ! -s patch.patch ] ; then
+ printf "Files in this commit comply with the clang-format style rules.\n"
+ rm -f patch.patch
+ exit 0
+fi
+
+# A patch has been created, notify the user, clean up, and exit.
+printf "\n*** The following differences were found between the code "
+printf "and the formatting rules:\n\n"
+cat patch.patch
+printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
+rm -f patch.patch
+exit 1
diff --git a/misc/scripts/copyright_headers.py b/misc/scripts/copyright_headers.py
new file mode 100755
index 0000000..2f3e4a1
--- /dev/null
+++ b/misc/scripts/copyright_headers.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+
+header = """\
+/*************************************************************************/
+/* $filename */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+"""
+
+fname = sys.argv[1]
+
+# Handle replacing $filename with actual filename and keep alignment
+fsingle = fname.strip()
+if fsingle.find("/") != -1:
+ fsingle = fsingle[fsingle.rfind("/") + 1 :]
+rep_fl = "$filename"
+rep_fi = fsingle
+len_fl = len(rep_fl)
+len_fi = len(rep_fi)
+# Pad with spaces to keep alignment
+if len_fi < len_fl:
+ for x in range(len_fl - len_fi):
+ rep_fi += " "
+elif len_fl < len_fi:
+ for x in range(len_fi - len_fl):
+ rep_fl += " "
+if header.find(rep_fl) != -1:
+ text = header.replace(rep_fl, rep_fi)
+else:
+ text = header.replace("$filename", fsingle)
+text += "\n"
+
+# We now have the proper header, so we want to ignore the one in the original file
+# and potentially empty lines and badly formatted lines, while keeping comments that
+# come after the header, and then keep everything non-header unchanged.
+# To do so, we skip empty lines that may be at the top in a first pass.
+# In a second pass, we skip all consecutive comment lines starting with "/*",
+# then we can append the rest (step 2).
+
+fileread = open(fname.strip(), "r")
+line = fileread.readline()
+header_done = False
+
+while line.strip() == "": # Skip empty lines at the top
+ line = fileread.readline()
+
+if line.find("/**********") == -1: # Godot header starts this way
+ # Maybe starting with a non-Godot comment, abort header magic
+ header_done = True
+
+while not header_done: # Handle header now
+ if line.find("/*") != 0: # No more starting with a comment
+ header_done = True
+ if line.strip() != "":
+ text += line
+ line = fileread.readline()
+
+while line != "": # Dump everything until EOF
+ text += line
+ line = fileread.readline()
+
+fileread.close()
+
+# Write
+filewrite = open(fname.strip(), "w")
+filewrite.write(text)
+filewrite.close()
diff --git a/misc/scripts/file_format.sh b/misc/scripts/file_format.sh
new file mode 100755
index 0000000..e6e1fe2
--- /dev/null
+++ b/misc/scripts/file_format.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+# This script ensures proper POSIX text file formatting and a few other things.
+# This is supplementary to clang_format.sh and black_format.sh, but should be
+# run before them.
+
+# We need dos2unix and recode.
+if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
+ printf "Install 'dos2unix' and 'recode' to use this script.\n"
+fi
+
+set -uo pipefail
+IFS=$'\n\t'
+
+# Loops through all text files tracked by Git.
+git grep -zIl '' |
+while IFS= read -rd '' f; do
+ # Exclude some types of files.
+ if [[ "$f" == "webrtc"* ]]; then
+ continue
+ elif [[ "$f" == "godot-cpp"* ]]; then
+ continue
+ fi
+ # Ensure that files are UTF-8 formatted.
+ recode UTF-8 "$f" 2> /dev/null
+ # Ensure that files have LF line endings and do not contain a BOM.
+ dos2unix "$f" 2> /dev/null
+ # Remove trailing space characters and ensures that files end
+ # with newline characters. -l option handles newlines conveniently.
+ perl -i -ple 's/\s*$//g' "$f"
+done
+
+git diff > patch.patch
+
+# If no patch has been generated all is OK, clean up, and exit.
+if [ ! -s patch.patch ] ; then
+ printf "Files in this commit comply with the formatting rules.\n"
+ rm -f patch.patch
+ exit 0
+fi
+
+# A patch has been created, notify the user, clean up, and exit.
+printf "\n*** The following differences were found between the code "
+printf "and the formatting rules:\n\n"
+cat patch.patch
+printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
+rm -f patch.patch
+exit 1