From 62fda215d86cd19631cb698885aa96b39eef6082 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Sun, 24 May 2020 11:35:21 -0700 Subject: [PATCH] Cleanup project indentation and formatting --- .clang-format | 118 +++++------------------ .editorconfig | 8 +- .travis.yml | 44 +++++++++ demo/.clang-format | 2 + hooks/README.md | 18 ---- hooks/canonicalize_filename.sh | 48 ---------- hooks/pre-commit | 50 ---------- hooks/pre-commit-clang-format | 147 ----------------------------- plugin/src/main/java/.clang-format | 2 + travis/clang-format.sh | 46 +++++++++ 10 files changed, 119 insertions(+), 364 deletions(-) create mode 100644 .travis.yml create mode 100644 demo/.clang-format delete mode 100644 hooks/README.md delete mode 100644 hooks/canonicalize_filename.sh delete mode 100644 hooks/pre-commit delete mode 100644 hooks/pre-commit-clang-format create mode 100644 plugin/src/main/java/.clang-format create mode 100644 travis/clang-format.sh diff --git a/.clang-format b/.clang-format index 3a2c39a..b828c2d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,67 +1,24 @@ -# 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). +# Clang format 8 - https://releases.llvm.org/8.0.1/tools/clang/docs/ClangFormatStyleOptions.html --- ### General config, applies to all languages ### BasedOnStyle: LLVM -AccessModifierOffset: -4 -AlignAfterOpenBracket: DontAlign -# AlignConsecutiveAssignments: false -# AlignConsecutiveDeclarations: false -# AlignEscapedNewlines: Right -# AlignOperands: true +AlignAfterOpenBracket: Align AlignTrailingComments: false AllowAllParametersOfDeclarationOnNextLine: false -# AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: true -AllowShortFunctionsOnASingleLine: Inline +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: true -# 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 +ColumnLimit: 100 +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 +DisableFormat: false +FixNamespaceComments: true +IncludeBlocks: Regroup IncludeCategories: - Regex: '".*"' Priority: 1 @@ -69,58 +26,25 @@ IncludeCategories: Priority: 2 - Regex: '^<.*' Priority: 3 -# IncludeIsMainRegex: '(Test)?$' IndentCaseLabels: true -# IndentPPDirectives: None IndentWidth: 4 -# IndentWrappedFunctionNames: false -# JavaScriptQuotes: Leave -# JavaScriptWrapImports: true -# KeepEmptyLinesAtTheStartOfBlocks: true -# 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 +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PointerAlignment: Right +SortIncludes: true +SortUsingDeclarations: true TabWidth: 4 -UseTab: Always +UseTab: Never --- ### C++ specific config ### Language: Cpp -Standard: Cpp03 ---- -### ObjC specific config ### -Language: ObjC -ObjCBlockIndentWidth: 4 -# ObjCSpaceAfterProperty: false -# ObjCSpaceBeforeProtocolList: true +Standard: Auto +AccessModifierOffset: -4 +AllowShortFunctionsOnASingleLine: Inline --- ### Java specific config ### Language: Java -# BreakAfterJavaFieldAnnotations: false +AllowShortFunctionsOnASingleLine: None +JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax'] ... diff --git a/.editorconfig b/.editorconfig index 25ffb6d..1143c77 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,14 +3,14 @@ root = true [*] charset = utf-8 end_of_line = lf +indent_size = 4 indent_style = space insert_final_newline = true max_line_length = 100 trim_trailing_whitespace = true [*.{cpp,hpp,c,h,mm}] -indent_size = 4 -ij_c_indent_namespace_members = 4 +ij_c_indent_namespace_members = 0 -[{*.gradle,AndroidManifest.xml}] -indent_size = 4 +[*.gd] +indent_style = tab diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..95b2f44 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,44 @@ +language: cpp + +# OS config, depends on actual 'os' in build matrix +dist: xenial + +stages: +- check +# - build + +matrix: + include: + - name: "Clang-format" + stage: check + addons: + apt: + sources: + - llvm-toolchain-xenial-8 + packages: + - clang-format-8 + script: + - sh ./travis/clang-format.sh +# - name: "Build windows" +# stage: build +# os: windows +# install: +# # we need to add python3 in for scons +# - choco install python +# # add our scripts folder to our path +# - export PATH=/c/users/travis/appdata/roaming/python/python38/Scripts/:/C/Python38/Scripts:$PATH +# # make sure we have the latest version of pip +# - py -m pip install --upgrade pip +# # scons we need +# - py -m pip install scons +# # just so we can verify they were installed +# - py -m pip list -v +# # and check if scons is up and running +# - scons --version +# script: +# # first compile godot-cpp +# - cd godot-cpp +# - scons platform=windows target=release bits=64 generate_bindings=yes +# - cd .. +# # now compile our plugin +# - scons platform=windows target=release diff --git a/demo/.clang-format b/demo/.clang-format new file mode 100644 index 0000000..5392cfe --- /dev/null +++ b/demo/.clang-format @@ -0,0 +1,2 @@ +DisableFormat: true +SortIncludes: false diff --git a/hooks/README.md b/hooks/README.md deleted file mode 100644 index 6ec90fc..0000000 --- a/hooks/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Git hooks for Godot Engine - -This folder contains git hooks meant to be installed locally by Godot Engine -contributors to make sure they comply with our requirements. - -## List of hooks - -- Pre-commit hook for clang-format: Applies clang-format to the staged files - before accepting a commit; blocks the commit and generates a patch if the - style is not respected. - Should work on Linux and macOS. You may need to edit the file if your - clang-format binary is not in the $PATH, or if you want to enable colored - output with pygmentize. - -## Installation - -Copy all the files from this folder into your .git/hooks folder, and make sure -the hooks and helper scripts are executable. diff --git a/hooks/canonicalize_filename.sh b/hooks/canonicalize_filename.sh deleted file mode 100644 index 5eecabf..0000000 --- a/hooks/canonicalize_filename.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -# Provide the canonicalize filename (physical filename with out any symlinks) -# like the GNU version readlink with the -f option regardless of the version of -# readlink (GNU or BSD). - -# This file is part of a set of unofficial pre-commit hooks available -# at github. -# Link: https://github.com/githubbrowser/Pre-commit-hooks -# Contact: David Martin, david.martin.mailbox@googlemail.com - -########################################################### -# There should be no need to change anything below this line. - -# Canonicalize by recursively following every symlink in every component of the -# specified filename. This should reproduce the results of the GNU version of -# readlink with the -f option. -# -# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac -canonicalize_filename () { - local target_file="$1" - local physical_directory="" - local result="" - - # Need to restore the working directory after work. - local working_dir="`pwd`" - - cd -- "$(dirname -- "$target_file")" - target_file="$(basename -- "$target_file")" - - # Iterate down a (possible) chain of symlinks - while [ -L "$target_file" ] - do - target_file="$(readlink -- "$target_file")" - cd -- "$(dirname -- "$target_file")" - target_file="$(basename -- "$target_file")" - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - physical_directory="`pwd -P`" - result="$physical_directory/$target_file" - - # restore the working directory after work. - cd -- "$working_dir" - - echo "$result" -} diff --git a/hooks/pre-commit b/hooks/pre-commit deleted file mode 100644 index fc50ed7..0000000 --- a/hooks/pre-commit +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh -# Git pre-commit hook that runs multiple hooks specified in $HOOKS. -# Make sure this script is executable. Bypass hooks with git commit --no-verify. - -# This file is part of a set of unofficial pre-commit hooks available -# at github. -# Link: https://github.com/githubbrowser/Pre-commit-hooks -# Contact: David Martin, david.martin.mailbox@googlemail.com - - -########################################################### -# CONFIGURATION: -# pre-commit hooks to be executed. They should be in the same .git/hooks/ folder -# as this script. Hooks should return 0 if successful and nonzero to cancel the -# commit. They are executed in the order in which they are listed. -#HOOKS="pre-commit-compile pre-commit-uncrustify" -HOOKS="pre-commit-clang-format" -########################################################### -# There should be no need to change anything below this line. - -. "$(dirname -- "$0")/canonicalize_filename.sh" - -# exit on error -set -e - -# Absolute path to this script, e.g. /home/user/bin/foo.sh -SCRIPT="$(canonicalize_filename "$0")" - -# Absolute path this script is in, thus /home/user/bin -SCRIPTPATH="$(dirname -- "$SCRIPT")" - - -for hook in $HOOKS -do - echo "Running hook: $hook" - # run hook if it exists - # if it returns with nonzero exit with 1 and thus abort the commit - if [ -f "$SCRIPTPATH/$hook" ]; then - "$SCRIPTPATH/$hook" - if [ $? != 0 ]; then - exit 1 - fi - else - echo "Error: file $hook not found." - echo "Aborting commit. Make sure the hook is in $SCRIPTPATH and executable." - echo "You can disable it by removing it from the list in $SCRIPT." - echo "You can skip all pre-commit hooks with --no-verify (not recommended)." - exit 1 - fi -done diff --git a/hooks/pre-commit-clang-format b/hooks/pre-commit-clang-format deleted file mode 100644 index db241ad..0000000 --- a/hooks/pre-commit-clang-format +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/env bash - -# git pre-commit hook that runs a clang-format stylecheck. -# Features: -# - abort commit when commit does not comply with the style guidelines -# - create a patch of the proposed style changes -# Modifications for clang-format by rene.milk@wwu.de - -# This file is part of a set of unofficial pre-commit hooks available -# at github. -# Link: https://github.com/githubbrowser/Pre-commit-hooks -# Contact: David Martin, david.martin.mailbox@googlemail.com - -# Some quality of life modifications made for Godot Engine. - -################################################################## -# SETTINGS -# Set path to clang-format binary -# CLANG_FORMAT="/usr/bin/clang-format" -CLANG_FORMAT=`which clang-format` - -# Remove any older patches from previous commits. Set to true or false. -# DELETE_OLD_PATCHES=false -DELETE_OLD_PATCHES=false - -# Only parse files with the extensions in FILE_EXTS. Set to true or false. -# If false every changed file in the commit will be parsed with clang-format. -# If true only files matching one of the extensions are parsed with clang-format. -# PARSE_EXTS=true -PARSE_EXTS=true - -# File types to parse. Only effective when PARSE_EXTS is true. -# FILE_EXTS=".c .h .cpp .hpp" -FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc .java .glsl" - -# Use pygmentize instead of cat to parse diff with highlighting. -# Install it with `pip install pygments` (Linux) or `easy_install Pygments` (Mac) -# READER="pygmentize -l diff" -READER=cat - -################################################################## -# There should be no need to change anything below this line. - -. "$(dirname -- "$0")/canonicalize_filename.sh" - -# exit on error -set -e - -# check whether the given file matches any of the set extensions -matches_extension() { - local filename=$(basename "$1") - local extension=".${filename##*.}" - local ext - - for ext in $FILE_EXTS; do [[ "$ext" == "$extension" ]] && return 0; done - - return 1 -} - -# necessary check for initial commit -if git rev-parse --verify HEAD >/dev/null 2>&1 ; then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -if [ ! -x "$CLANG_FORMAT" ] ; then - printf "Error: clang-format executable not found.\n" - printf "Set the correct path in $(canonicalize_filename "$0").\n" - exit 1 -fi - -# create a random filename to store our generated patch -prefix="pre-commit-clang-format" -suffix="$(date +%s)" -patch="/tmp/$prefix-$suffix.patch" - -# clean up any older clang-format patches -$DELETE_OLD_PATCHES && rm -f /tmp/$prefix*.patch - -# create one patch containing all changes to the files -git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file; -do - # ignore thirdparty files - if grep -q "thirdparty" <<< $file; then - continue; - fi - - # ignore file if we do check for file extensions and the file - # does not match any of the extensions specified in $FILE_EXTS - if $PARSE_EXTS && ! matches_extension "$file"; then - continue; - fi - - # clang-format our sourcefile, create a patch with diff and append it to our $patch - # The sed call is necessary to transform the patch from - # --- $file timestamp - # +++ - timestamp - # to both lines working on the same file and having a/ and b/ prefix. - # Else it can not be applied with 'git apply'. - "$CLANG_FORMAT" -style=file "$file" | \ - diff -u "$file" - | \ - sed -e "1s|--- |--- a/|" -e "2s|+++ -|+++ b/$file|" >> "$patch" -done - -# if no patch has been generated all is ok, clean up the file stub and exit -if [ ! -s "$patch" ] ; then - printf "Files in this commit comply with the clang-format rules.\n" - rm -f "$patch" - exit 0 -fi - -# a patch has been created, notify the user and exit -printf "\nThe following differences were found between the code to commit " -printf "and the clang-format rules:\n\n" -$READER "$patch" -printf "\n" - -# Allows us to read user input below, assigns stdin to keyboard -exec < /dev/tty - -while true; do - read -p "Do you want to apply that patch (Y - Apply, N - Do not apply, S - Apply and stage files)? [Y/N/S] " yn - case $yn in - [Yy] ) git apply $patch; - printf "The patch was applied. You can now stage the changes and commit again.\n\n"; - break - ;; - [Nn] ) printf "\nYou can apply these changes with:\n git apply $patch\n"; - printf "(may need to be called from the root directory of your repository)\n"; - printf "Aborting commit. Apply changes and commit again or skip checking with"; - printf " --no-verify (not recommended).\n\n"; - break - ;; - [Ss] ) git apply $patch; - git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file; - do git add $file; - done - printf "The patch was applied and the changed files staged. You can now commit.\n\n"; - break - ;; - * ) echo "Please answer yes or no." - ;; - esac -done -exit 1 # we don't commit in any case diff --git a/plugin/src/main/java/.clang-format b/plugin/src/main/java/.clang-format new file mode 100644 index 0000000..5392cfe --- /dev/null +++ b/plugin/src/main/java/.clang-format @@ -0,0 +1,2 @@ +DisableFormat: true +SortIncludes: false diff --git a/travis/clang-format.sh b/travis/clang-format.sh new file mode 100644 index 0000000..df9a3ef --- /dev/null +++ b/travis/clang-format.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +CLANG_FORMAT=clang-format-8 + +if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + # Travis only clones the PR branch and uses its HEAD commit as detached HEAD, + # so it's problematic when we want an exact commit range for format checks. + # We fetch upstream to ensure that we have the proper references to resolve. + # Ideally we would use $TRAVIS_COMMIT_RANGE but it doesn't play well with PR + # updates, as it only includes changes since the previous state of the PR. + git remote add upstream https://github.com/GodotVR/godot_oculus_mobile \ + --no-tags -f -t $TRAVIS_BRANCH + RANGE="upstream/$TRAVIS_BRANCH HEAD" +else + # Test only the last commit, since $TRAVIS_COMMIT_RANGE wouldn't support + # force pushes. + RANGE=HEAD +fi + +FILES=$(git diff-tree --no-commit-id --name-only -r $RANGE | grep -v godot-cpp/ | grep -v ovr_sdk_mobile/ | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc|java|glsl)$") +echo "Checking files:\n$FILES" + +# create a random filename to store our generated patch +prefix="static-check-clang-format" +suffix="$(date +%s)" +patch="/tmp/$prefix-$suffix.patch" + +for file in $FILES; do + "$CLANG_FORMAT" -style=file "$file" | \ + diff -u "$file" - | \ + sed -e "1s|--- |--- a/|" -e "2s|+++ -|+++ b/$file|" >> "$patch" +done + +# if no patch has been generated all is ok, clean up the file stub and exit +if [ ! -s "$patch" ] ; then + printf "Files in this commit comply with the clang-format rules.\n" + rm -f "$patch" + exit 0 +fi + +# a patch has been created, notify the user and exit +printf "\n*** The following differences were found between the code to commit " +printf "and the clang-format rules:\n\n" +cat "$patch" +printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i '\n" +exit 1