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/.gitlab-ci-checkcommit.sh b/.ci/.gitlab-ci-checkcommit.sh
similarity index 88%
rename from .gitlab-ci-checkcommit.sh
rename to .ci/.gitlab-ci-checkcommit.sh
index 17fdbcc..314238f 100755
--- a/.gitlab-ci-checkcommit.sh
+++ b/.ci/.gitlab-ci-checkcommit.sh
@@ -50,9 +50,9 @@
exit 1
fi
- git show "$h" -- | clang-format-diff-11 -p 1 -style=file > format-fixup.patch
- if [ -s format-fixup.patch ]; then
- cat format-fixup.patch >&2
+ 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
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..0bb7bf0
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,42 @@
+# fuchsia: Conflicts with other checks
+# llvm-header-guard: Does not match drm_hwc header gusrd style
+# Allow using ALOGE
+
+Checks: >
+ *,
+ -fuchsia*,
+ -llvm*,
+ -cppcoreguidelines-pro-type-vararg, -hicpp-vararg,
+ -hicpp-signed-bitwise,
+
+# Turn all the warnings from the checks above into errors.
+WarningsAsErrors: "*"
+
+#HeaderFilterRegex: "^.*external/drm_hwcomposer/.*.h$"
+
+FormatStyle: google
+
+CheckOptions:
+ - { key: readability-identifier-naming.NamespaceCase, value: lower_case }
+ - { key: readability-identifier-naming.ClassCase, value: CamelCase }
+ - { key: readability-identifier-naming.StructCase, value: CamelCase }
+ - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
+ - { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
+ - { key: readability-identifier-naming.VariableCase, value: lower_case }
+ - { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
+ - { key: readability-identifier-naming.ClassMemberSuffix, value: _ }
+ - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
+ - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
+ - { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
+ - { key: readability-identifier-naming.EnumConstantPrefix, value: k }
+ - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
+ - { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
+ - { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
+ - { key: readability-identifier-naming.GlobalConstantPrefix, value: k }
+ - { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
+ - { key: readability-identifier-naming.MemberConstantPrefix, value: k }
+ - { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
+ - { key: readability-identifier-naming.StaticConstantPrefix, value: k }
+ - { key: readability-implicit-bool-conversion.AllowIntegerConditions, value: 1 }
+ - { key: readability-implicit-bool-conversion.AllowPointerConditions, value: 1 }
+ - { key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic, value: 1 }
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 79b053c..63cedb6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,14 +2,36 @@
before_script:
- apt-get --quiet update --yes >/dev/null
- - apt-get --quiet install --yes clang-11 clang-tidy-11 clang-format-11 git >/dev/null
+ - apt-get --quiet install --yes clang-11 clang-tidy-11 clang-format-11 git libdrm-dev >/dev/null
stages:
+ - build
- style
+build:
+ stage: build
+ script: "./.ci/.gitlab-ci-clang-build.sh"
+ artifacts:
+ when: on_failure
+ untracked: true
+
checkstyle:
stage: style
- script: "./.gitlab-ci-checkcommit.sh"
+ script: "./.ci/.gitlab-ci-checkcommit.sh"
+ artifacts:
+ when: on_failure
+ untracked: true
+
+tidy-coarse:
+ stage: style
+ script: "./.ci/.gitlab-ci-clang-tidy-coarse.sh"
+ artifacts:
+ when: on_failure
+ untracked: true
+
+tidy-fine:
+ stage: style
+ script: "./.ci/.gitlab-ci-clang-tidy-fine.sh"
artifacts:
when: on_failure
untracked: true
diff --git a/drm/DrmConnector.cpp b/drm/DrmConnector.cpp
index f1b6c1b..11c2bd2 100644
--- a/drm/DrmConnector.cpp
+++ b/drm/DrmConnector.cpp
@@ -19,7 +19,6 @@
#include "DrmConnector.h"
#include <errno.h>
-#include <log/log.h>
#include <stdint.h>
#include <xf86drmMode.h>
@@ -27,6 +26,7 @@
#include <sstream>
#include "DrmDevice.h"
+#include "utils/log.h"
namespace android {
diff --git a/drm/DrmCrtc.cpp b/drm/DrmCrtc.cpp
index 4ce8cfc..3c05ba8 100644
--- a/drm/DrmCrtc.cpp
+++ b/drm/DrmCrtc.cpp
@@ -18,8 +18,8 @@
#include "DrmCrtc.h"
-#include <log/log.h>
#include <stdint.h>
+#include <utils/log.h>
#include <xf86drmMode.h>
#include "DrmDevice.h"
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index 4e750f8..818261d 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -18,10 +18,8 @@
#include "DrmDevice.h"
-#include <cutils/properties.h>
#include <errno.h>
#include <fcntl.h>
-#include <log/log.h>
#include <stdint.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
@@ -32,6 +30,9 @@
#include <sstream>
#include <string>
+#include "utils/log.h"
+#include "utils/properties.h"
+
static void trim_left(std::string &str) {
str.erase(std::begin(str),
std::find_if(std::begin(str), std::end(str),
diff --git a/drm/DrmEventListener.cpp b/drm/DrmEventListener.cpp
index 3d95e28..6cfa37d 100644
--- a/drm/DrmEventListener.cpp
+++ b/drm/DrmEventListener.cpp
@@ -20,14 +20,17 @@
#include <assert.h>
#include <errno.h>
-#include <hardware/hardware.h>
-#include <hardware/hwcomposer.h>
#include <linux/netlink.h>
-#include <log/log.h>
#include <sys/socket.h>
#include <xf86drm.h>
+#include <cstring>
+
#include "DrmDevice.h"
+#include "utils/log.h"
+
+/* Originally defined in system/core/libsystem/include/system/graphics.h */
+#define HAL_PRIORITY_URGENT_DISPLAY (-8)
namespace android {
diff --git a/drm/DrmMode.cpp b/drm/DrmMode.cpp
index 6de671a..6a879e8 100644
--- a/drm/DrmMode.cpp
+++ b/drm/DrmMode.cpp
@@ -16,6 +16,8 @@
#include "DrmMode.h"
+#include <cstring>
+
#include "DrmDevice.h"
namespace android {
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index 65bd8be..1cc6ee0 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -17,15 +17,15 @@
#define LOG_TAG "hwc-drm-plane"
#include "DrmPlane.h"
-#include "bufferinfo/BufferInfoGetter.h"
#include <errno.h>
-#include <log/log.h>
#include <stdint.h>
#include <cinttypes>
#include "DrmDevice.h"
+#include "bufferinfo/BufferInfoGetter.h"
+#include "utils/log.h"
namespace android {
diff --git a/drm/DrmProperty.cpp b/drm/DrmProperty.cpp
index b60a76e..b8ce680 100644
--- a/drm/DrmProperty.cpp
+++ b/drm/DrmProperty.cpp
@@ -17,9 +17,10 @@
#include "DrmProperty.h"
#include <errno.h>
-#include <stdint.h>
#include <xf86drmMode.h>
+#include <cstdint>
+#include <cstring>
#include <string>
#include "DrmDevice.h"
diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp
index fc24aea..efd5de1 100644
--- a/drm/ResourceManager.cpp
+++ b/drm/ResourceManager.cpp
@@ -19,12 +19,12 @@
#include "ResourceManager.h"
#include <cutils/properties.h>
-#include <log/log.h>
#include <sys/stat.h>
#include <sstream>
#include "bufferinfo/BufferInfoGetter.h"
+#include "utils/log.h"
namespace android {
diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp
index b2f7e5f..7f8882d 100644
--- a/drm/VSyncWorker.cpp
+++ b/drm/VSyncWorker.cpp
@@ -18,12 +18,13 @@
#include "VSyncWorker.h"
-#include <log/log.h>
#include <stdlib.h>
#include <time.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
+#include "utils/log.h"
+
namespace android {
VSyncWorker::VSyncWorker()
diff --git a/presubmit.sh b/presubmit.sh
new file mode 100755
index 0000000..249aaf5
--- /dev/null
+++ b/presubmit.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+set -e
+
+echo "Run native build:"
+
+./.ci/.gitlab-ci-clang-build.sh
+
+echo "Run style check:"
+
+./.ci/.gitlab-ci-checkcommit.sh
+
+echo "Run coarse clang-tidy check:"
+
+./.ci/.gitlab-ci-clang-tidy-coarse.sh
+
+echo "Run fine clang-tidy check:"
+
+./.ci/.gitlab-ci-clang-tidy-fine.sh
+
+echo -e "\n\e[32m --- SUCCESS ---"
diff --git a/utils/log.h b/utils/log.h
new file mode 100644
index 0000000..1fe4713
--- /dev/null
+++ b/utils/log.h
@@ -0,0 +1,23 @@
+#ifndef UTILS_LOG_H_
+#define UTILS_LOG_H_
+
+#ifdef ANDROID
+
+#include <log/log.h>
+
+#else
+
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define ALOGE(args...) printf("ERR: " args)
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define ALOGW(args...) printf("WARN: " args)
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define ALOGI(args...) printf("INFO: " args)
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define ALOGD(args...) printf("DBG:" args)
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define ALOGV(args...) printf("VERBOSE: " args)
+
+#endif
+
+#endif
\ No newline at end of file
diff --git a/utils/properties.h b/utils/properties.h
new file mode 100644
index 0000000..607cbc5
--- /dev/null
+++ b/utils/properties.h
@@ -0,0 +1,28 @@
+#ifndef UTILS_PROPERTIES_H_
+#define UTILS_PROPERTIES_H_
+
+#ifdef ANDROID
+
+#include <cutils/properties.h>
+
+#else
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+// NOLINTNEXTLINE(readability-identifier-naming)
+constexpr int PROPERTY_VALUE_MAX = 92;
+
+auto inline property_get(const char *name, char *value,
+ const char *default_value) -> int {
+ char *prop = std::getenv(name);
+ if (prop == nullptr) {
+ snprintf(value, PROPERTY_VALUE_MAX, "%s", default_value);
+ }
+ return strlen(value);
+}
+
+#endif
+
+#endif
\ No newline at end of file