gamesdk: add repohooks

Add repohooks to prevent breaking Swappy ABI without updating
the minor/major version macros.

The script simply checks if one of the public headers of swappy changed
and errors if the minor/major version macros were not updated together
with the change.

Test: manual
Change-Id: I3ebdc2c4f785f1e94162333af0ac454396854f81
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..942a5ec
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,10 @@
+[Hook Scripts]
+
+swappy_abi_hook = ${REPO_ROOT}/gamesdk/hooks/check_swappy_abi_version.sh ${PREUPLOAD_COMMIT} ${PREUPLOAD_FILES}
+
+[Builtin Hooks]
+commit_msg_changeid_field = true
+commit_msg_test_field = true
+pylint = true
+
+
diff --git a/hooks/check_swappy_abi_version.sh b/hooks/check_swappy_abi_version.sh
new file mode 100755
index 0000000..12d4db0
--- /dev/null
+++ b/hooks/check_swappy_abi_version.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+SWAPPY_GL_H="include/swappy/swappyGL.h"
+SWAPPY_GL_EXTRA_H="include/swappy/swappyGL_extra.h"
+SWAPPY_VK_H="include/swappy/swappyVk.h"
+SWAPPY_VK_EXTRA_H="include/swappy/swappyVk_extra.h"
+SWAPPY_COMMON_H="include/swappy/swappy_common.h"
+
+SWAPPY_HEADERS=($SWAPPY_GL_H $SWAPPY_GL_EXTRA_H $SWAPPY_VK_H $SWAPPY_VK_EXTRA_H $SWAPPY_COMMON_H)
+
+files=$2
+headerChanged=0
+for file in ${files[@]}; do
+    for header in ${SWAPPY_HEADERS[@]}; do
+      if [[ $file =~ $header ]]; then
+        headerChanged=1
+        break
+      fi
+    done
+    if [ $headerChanged -eq "0" ]; then
+      break
+    fi
+
+    majorVersion=`git show $1 $SWAPPY_COMMON_H | grep "#define SWAPPY_MAJOR_VERSION" | wc -l`
+    minorVersion=`git show $1 $SWAPPY_COMMON_H | grep "#define SWAPPY_MINOR_VERSION" | wc -l`
+    # echo "version_files $version_files"
+    if [[ $majorVersion -eq "0" && $minorVersion -eq "0" ]]; then
+      echo "Did you break ABI without changing SWAPPY_MAJOR_VERSION/SWAPPY_MINOR_VERSION ?"
+      exit 1
+    fi
+
+done
+exit 0