From 1f7f66d09e251fb5b3b2c1d6af43b738425f890f Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Mon, 1 Feb 2021 00:15:22 +0000 Subject: [PATCH] Re-added clang-format checks to the CI --- .github/workflows/ci.yml | 15 +++++++++++ include/core/CameraMatrix.hpp | 4 +-- include/core/GodotProfiling.hpp | 3 +-- misc/scripts/clang_format.sh | 43 +++++++++++++++++++++++++++++ misc/travis/clang-format.sh | 48 --------------------------------- 5 files changed, 60 insertions(+), 53 deletions(-) create mode 100644 misc/scripts/clang_format.sh delete mode 100755 misc/travis/clang-format.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90001616..54a4bccb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,3 +124,18 @@ jobs: name: godot-cpp-macos-x86_64-release path: bin/libgodot-cpp.osx.release.64.a if-no-files-found: error + + static-checks: + name: Static Checks (clang-format) + runs-on: ubuntu-16.04 + steps: + - name: Checkout + uses: actions/checkout@v2.3.4 + + - name: Install dependencies + run: | + sudo apt-get install clang-format-8 + + - name: Style checks via clang-format + run: | + bash ./misc/scripts/clang_format.sh diff --git a/include/core/CameraMatrix.hpp b/include/core/CameraMatrix.hpp index dc6b7274..c90bc516 100644 --- a/include/core/CameraMatrix.hpp +++ b/include/core/CameraMatrix.hpp @@ -2,10 +2,10 @@ #define CAMERA_MATRIX_H #include "Defs.hpp" +#include "Math.hpp" #include "Plane.hpp" #include "Rect2.hpp" #include "Transform.hpp" -#include "Math.hpp" #include @@ -39,12 +39,10 @@ struct CameraMatrix { void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false); static real_t get_fovy(real_t p_fovx, real_t p_aspect) { - return Math::rad2deg(atan(p_aspect * tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0); } static inline double absd(double g) { - union { double d; uint64_t i; diff --git a/include/core/GodotProfiling.hpp b/include/core/GodotProfiling.hpp index 0862d0ba..92b010ed 100644 --- a/include/core/GodotProfiling.hpp +++ b/include/core/GodotProfiling.hpp @@ -3,7 +3,6 @@ #include "OS.hpp" - namespace godot { class FunctionProfiling { @@ -23,7 +22,7 @@ public: } }; -} +} // namespace godot #ifdef DEBUG_ENABLED #define GODOT_PROFILING_FUNCTION FunctionProfiling __function_profiling(__FUNCTION__, __LINE__); diff --git a/misc/scripts/clang_format.sh b/misc/scripts/clang_format.sh new file mode 100644 index 00000000..0d1511eb --- /dev/null +++ b/misc/scripts/clang_format.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# This script runs clang-format 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 + fi + + for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do + if [[ "$f" == *"$extension" ]]; then + # Run clang-format. + clang-format -i "$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 '\n" +rm -f patch.patch +exit 1 diff --git a/misc/travis/clang-format.sh b/misc/travis/clang-format.sh deleted file mode 100755 index 5a41fccf..00000000 --- a/misc/travis/clang-format.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/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. - if [ -z "$(git remote | grep upstream)" ]; then - git remote add upstream https://github.com/godotengine/godot-cpp \ - --no-tags -f -t $TRAVIS_BRANCH - fi - 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 -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