Skip to content

Commit

Permalink
adds hooks, newlines and github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaJunge committed Sep 2, 2024
1 parent 8c1a992 commit 392701a
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 30 deletions.
38 changes: 13 additions & 25 deletions .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,15 @@ jobs:
# for android, run generate bindings python script
- name: Generate bindings (Android)
run: |
cd $GITHUB_WORKSPACE/plugin/libs/godot-cpp
python ../../../generate.py
cd $GITHUB_WORKSPACE/godot-cpp
scons platform=android target=template_debug
scons platform=android target=template_release
if: matrix.platform == 'android'

# then run gradlew to build aar
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b

- name: Run the build for godot_arcore
run: |
cd $GITHUB_WORKSPACE
./gradlew :generatePluginBinary
# for android, copy aar
- name: Upload build files (artifacts)
uses: actions/upload-artifact@v2
with:
name: build-files-arcore
path: |
plugin/build/outputs/pluginBin/*.aar
plugin/gdarcore.gdap
./gradlew :assemble
# This job collects the build output and assembles the final asset (artifact)
asset:
Expand All @@ -80,15 +68,15 @@ jobs:
path: godot_arcore
- name: Download all workflow run artifacts
uses: actions/download-artifact@v2
- name: Copy files to destination
run: |
mkdir godot_arcore_plugin
mkdir godot_arcore_plugin/addons
mkdir godot_arcore_plugin/android
mkdir godot_arcore_plugin/android/plugins
cp -r godot_arcore/demo/addons/godot_arcore godot_arcore_plugin/addons
cp build-files-arcore/*.aar godot_arcore_plugin/android/plugins/
cp build-files-arcore/gdarcore.gdap godot_arcore_plugin/android/plugins/godot_openxr.gdap
#- name: Copy files to destination
# run: |
# mkdir godot_arcore_plugin
# mkdir godot_arcore_plugin/addons
# mkdir godot_arcore_plugin/android
# mkdir godot_arcore_plugin/android/plugins
# cp -r godot_arcore/demo/addons/godot_arcore godot_arcore_plugin/addons
# cp build-files-arcore/*.aar godot_arcore_plugin/android/plugins/
# cp build-files-arcore/gdarcore.gdap godot_arcore_plugin/android/plugins/godot_openxr.gdap
- name: Calculate GIT short ref
run: |
cd godot_arcore
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ To fix that, navigate to the folder where the `gradlew` script is and enter the
dos2unix ./gradlew
```

This will convert the line endings to LF.
This will convert the line endings to LF.
18 changes: 18 additions & 0 deletions hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.
48 changes: 48 additions & 0 deletions hooks/canonicalize_filename.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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, [email protected]

###########################################################
# 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"
}
50 changes: 50 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/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, [email protected]


###########################################################
# 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
150 changes: 150 additions & 0 deletions hooks/pre-commit-clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#!/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 [email protected]

# 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, [email protected]

# 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
if grep -q "openxr_loader" <<< $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
2 changes: 1 addition & 1 deletion plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/build
/build
2 changes: 1 addition & 1 deletion plugin/export_scripts_template/ARCoreInterface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func start():
get_viewport().use_xr = true

func get_tracking_status():
return arcore.get_tracking_status()
return arcore.get_tracking_status()
2 changes: 1 addition & 1 deletion plugin/src/main/cpp/arcore_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ jobject ARCoreWrapper::get_global_context()
jmethodID getApplication = env->GetMethodID(activityThread, "getApplication", "()Landroid/app/Application;");
jobject context = env->CallObjectMethod(activityThreadObj, getApplication);
return context;
}
}
2 changes: 1 addition & 1 deletion plugin/src/main/cpp/plugin_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ extern "C" {
JNIEXPORT void JNICALL JNI_METHOD(uninitializeEnvironment)(JNIEnv *env, jobject) {
ARCoreWrapper::uninitialize_environment(env);
}
};
};

0 comments on commit 392701a

Please sign in to comment.