drm_hwcomposer: CI: Initial build and clang-tidy checks

Build android-agnostic code in linux environment.
Enable static code analysis using clang-tidy.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/.ci/.common.sh b/.ci/.common.sh
new file mode 100644
index 0000000..7fa5a88
--- /dev/null
+++ b/.ci/.common.sh
@@ -0,0 +1,8 @@
+INCLUDE_DIRS="-I. -I../libdrm/include/drm -Iinclude -I/usr/include/libdrm"
+
+CLANG="clang++-11"
+CLANG_TIDY="clang-tidy-11"
+
+CXXARGS="-fPIC -Wall -Werror -DPLATFORM_SDK_VERSION=30 -Wsign-promo -Wimplicit-fallthrough"
+CXXARGS+=" -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -Wno-gnu-include-next "
+CXXARGS+=" -fvisibility-inlines-hidden -std=gnu++17 -DHWC2_USE_CPP11 -DHWC2_INCLUDE_STRINGIFICATION -fexceptions -fno-rtti"
diff --git a/.ci/.gitlab-ci-checkcommit.sh b/.ci/.gitlab-ci-checkcommit.sh
new file mode 100755
index 0000000..314238f
--- /dev/null
+++ b/.ci/.gitlab-ci-checkcommit.sh
@@ -0,0 +1,58 @@
+#! /usr/bin/env bash
+
+echoerr() {
+	printf "ERROR: %s\n" "$*" >&2
+}
+
+findtag() {
+	local commit_body tag person
+	commit_body=$1
+	tag=$2
+	person=$3
+
+	# trim duplicate spaces from commit body and person
+	match="$tag: $(echo $person | tr -s ' ')"
+
+	if [ -z "$(echo "$commit_body" | tr -s ' ' | grep -i "$match")" ]; then
+		echoerr "Tag is missing from commit body"
+		echoerr ""
+		echoerr "Looking for '"$match"' in: "
+		echoerr "-----------------------------------------------------"
+		echoerr "$commit_body"
+		echoerr "-----------------------------------------------------"
+		echoerr ""
+		return 0
+	fi
+
+	return 1
+}
+
+git fetch https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer.git
+
+git log --pretty='%h' FETCH_HEAD..HEAD | while read h; do
+	subject=$(git show -s --pretty='%s' "$h")
+	if [[ $subject != drm_hwcomposer:* ]]; then
+		echoerr "Invalid subject prefix: $subject"
+		exit 1
+	fi
+
+	commit_body=$(git show -s --pretty=%b "$h")
+
+	author=$(git show -s --format='%an <%ae>' "$h")
+	if findtag "$commit_body" "Signed-off-by" "$author"; then
+		echoerr "Author SoB tag is missing from commit $h"
+		exit 1
+	fi
+
+	committer=$(git show -s --format='%cn <%ce>' "$h")
+	if findtag "$commit_body" "Signed-off-by" "$committer"; then
+		echoerr "Committer SoB tag is missing from commit $h"
+		exit 1
+	fi
+
+	git show "$h" -- | clang-format-diff-11 -p 1 -style=file > /tmp/format-fixup.patch
+	if [ -s  /tmp/format-fixup.patch ]; then
+		cat /tmp/format-fixup.patch >&2
+		exit 1
+	fi
+done
diff --git a/.ci/.gitlab-ci-clang-build.sh b/.ci/.gitlab-ci-clang-build.sh
new file mode 100755
index 0000000..11dd817
--- /dev/null
+++ b/.ci/.gitlab-ci-clang-build.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+. ./.ci/.common.sh
+
+BUILD_FILES=(
+drm/DrmConnector.cpp
+drm/DrmCrtc.cpp
+drm/DrmDevice.cpp
+drm/DrmEncoder.cpp
+drm/DrmEventListener.cpp
+drm/DrmMode.cpp
+drm/DrmProperty.cpp
+utils/Worker.cpp
+)
+
+set -xe
+
+for source in "${BUILD_FILES[@]}"
+do
+    filename=$(basename -- "$source")
+    $CLANG $source $INCLUDE_DIRS $CXXARGS -c -o /tmp/"${filename%.*}.o"
+done
diff --git a/.ci/.gitlab-ci-clang-tidy-coarse.sh b/.ci/.gitlab-ci-clang-tidy-coarse.sh
new file mode 100755
index 0000000..bb7373c
--- /dev/null
+++ b/.ci/.gitlab-ci-clang-tidy-coarse.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+. ./.ci/.common.sh
+
+TIDY_FILES=(
+)
+
+set -xe
+
+for source in "${TIDY_FILES[@]}"
+do
+    $CLANG_TIDY $source -- -x c++ $INCLUDE_DIRS
+done
diff --git a/.ci/.gitlab-ci-clang-tidy-fine.sh b/.ci/.gitlab-ci-clang-tidy-fine.sh
new file mode 100755
index 0000000..f4c11de
--- /dev/null
+++ b/.ci/.gitlab-ci-clang-tidy-fine.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+. ./.ci/.common.sh
+
+TIDY_FILES=(
+utils/log.h
+utils/properties.h
+)
+
+set -xe
+
+for source in "${TIDY_FILES[@]}"
+do
+    $CLANG_TIDY $source -- -x c++ $INCLUDE_DIRS
+done