Browse Source

Merge pull request #409 from akien-mga/travis-clang-format-8

Travis: Use clang-format 8.0, update script
Rémi Verschelde 5 years ago
parent
commit
1dc8feaeee
2 changed files with 17 additions and 10 deletions
  1. 3 4
      .travis.yml
  2. 14 6
      misc/travis/clang-format.sh

+ 3 - 4
.travis.yml

@@ -19,10 +19,9 @@ matrix:
       env: TARGET=debug STATIC_CHECKS=yes
       addons:
         apt:
-          sources:
-            - llvm-toolchain-xenial-6.0
           packages:
-            [scons, pkg-config, build-essential, p7zip-full, clang-format-6.0]
+            - clang-format-8
+            - [scons, pkg-config, build-essential, p7zip-full]
 
     - name: Linux Release
       os: linux
@@ -30,7 +29,7 @@ matrix:
       addons:
         apt:
           packages:
-            [scons, pkg-config, build-essential, p7zip-full]
+            - [scons, pkg-config, build-essential, p7zip-full]
       env: TARGET=release
 
     - name: macOS Debug

+ 14 - 6
misc/travis/clang-format.sh

@@ -1,17 +1,25 @@
 #!/bin/sh
 
-CLANG_FORMAT=clang-format-6.0
+CLANG_FORMAT=clang-format-8
 
 if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
-    # Check the whole commit range against $TRAVIS_BRANCH, the base merge branch
-    # We could use $TRAVIS_COMMIT_RANGE but it doesn't play well with force pushes
-    RANGE="$(git rev-parse $TRAVIS_BRANCH) HEAD"
+    # 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
+    # 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 thirdparty/ | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc|java|glsl)$")
+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