drm_hwcomposer: Add meson build to CI

Now CI is building drm_hwcomposer for arm64 arch and generates
ready-to-deploy artifacts.

Dependencies for meson cross build were extracted from Android-13
using GloDroid/aospext project [1].

./build_deploy.sh script was migrated into Makefile and no longer
require AOSP to work. Usage example:

    make build_deploy

Only arm64 platform is supported at this moment.
Other platforms will be added later.

[1]: https://github.com/GloDroid/aospext
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/.ci/Dockerfile b/.ci/Dockerfile
index d0ecee2..32c348f 100644
--- a/.ci/Dockerfile
+++ b/.ci/Dockerfile
@@ -6,7 +6,8 @@
 
 # Taking into account layer structure, everything should be done within one layer.
 RUN apt-get update && apt-get upgrade -y && \
-    apt-get install -y clang-15 clang-tidy-15 clang-format-15 git libdrm-dev blueprint-tools libgtest-dev clang llvm make python3 python3-pip wget sudo && \
+    apt-get install -y clang-15 clang-tidy-15 clang-format-15 git libdrm-dev blueprint-tools libgtest-dev clang \
+    llvm make python3 python3-pip wget sudo rsync lld pkg-config ninja-build && \
     pip3 install mako meson jinja2 ply pyyaml
 
 ENV RUN_USER user
@@ -35,6 +36,13 @@
 # Pass control to a newly created user
 USER ${RUN_USER}
 
+# Install aospless package (produced by GloDroid/aospext)
+RUN wget -P ${USER_HOME} https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/uploads/28ef9379b1a0ec1ee19a17825b0f3f3f/aospless_drm_hwcomposer_arm64.tar.xz && \
+    cd ${USER_HOME} && \
+    (echo 96b2148d04c50cf36d4151ae022e665764b8ca3317712e9467a433b62c545a43 aospless_drm_hwcomposer_arm64.tar.xz | sha256sum --check) && \
+    tar xf aospless_drm_hwcomposer_arm64.tar.xz && \
+    rm -r ${USER_HOME}/aospless/src && ln -s ../drm_hwcomposer/ ${USER_HOME}/aospless/src
+
 # Create project path
 RUN mkdir -pv ${USER_HOME}/drm_hwcomposer
 WORKDIR ${USER_HOME}/drm_hwcomposer
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f7f9caa..bfc4ede 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,18 +6,35 @@
 before_script:
   - apt-get --quiet update --yes >/dev/null
   - apt-get --quiet install --yes clang-15 clang-tidy-15 clang-format-15 git libdrm-dev blueprint-tools libgtest-dev make >/dev/null
+  - apt-get --quiet install --yes clang llvm make python3 python3-pip wget sudo rsync lld pkg-config ninja-build >/dev/null
+  - pip3 install mako meson jinja2 ply pyyaml >/dev/null
 
 stages:
   - build
+  - tidy
   - style
 
 build:
   stage: build
   script:
-    - make -f .ci/Makefile
+    - mkdir -p install/arm64
+    - cd ..
+    - wget https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/uploads/28ef9379b1a0ec1ee19a17825b0f3f3f/aospless_drm_hwcomposer_arm64.tar.xz
+    - tar xf aospless_drm_hwcomposer_arm64.tar.xz
+    - rm -r aospless/src
+    - ln -s ../drm-hwcomposer/ aospless/src
+    - make -C ./aospless all
+    - cp -r aospless/install/* drm-hwcomposer/install/arm64
+
   artifacts:
-    when: on_failure
-    untracked: true
+    paths:
+      - install/
+    expire_in: 1 week
+
+tidy:
+  stage: tidy
+  script:
+    - make -f .ci/Makefile
 
 checkstyle:
   stage: style
diff --git a/Makefile b/Makefile
index 16269e2..98e33af 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
 $(error Aborting...)
 endef
 
-.PHONY : help prepare shell ci ci_cleanup local_presubmit local_cleanup
+.PHONY : help prepare shell ci_fast ci ci_cleanup build_deploy bd local_presubmit local_cleanup
 .DEFAULT_GOAL := help
 
 help: ## Show this help
@@ -41,10 +41,17 @@
 shell: ## Start shell into a container
 	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash
 
+ci_fast: $(PREPARE)
+ci_fast: ## Run meson build for arm64 in docker container
+	@echo "Run meson cross-build for Android:"
+	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make -C ~/aospless all"
+
 ci: $(PREPARE)
 ci: ## Run presubmit within the docker container
 	@echo "Run native build:"
 	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make -f .ci/Makefile -j$(NPROCS)"
+	@echo "Run meson cross-build for Android:"
+	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make -C ~/aospless all"
 	@echo "Run style check:"
 	$(if $(GIT_IS_SYMLINK), \
 		./.ci/.gitlab-ci-checkcommit.sh, \
@@ -53,6 +60,29 @@
 
 ci_cleanup: ## Cleanup after 'make ci'
 	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make local_cleanup"
+	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "rm -rf ~/aospless/build"
+	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "rm -rf ~/aospless/install"
+	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "rm -rf ~/aospless/out_src"
+
+build_deploy: $(PREPARE)
+build_deploy: ## Build for Andoid and deploy onto the target device (require active adb device connected)
+	$(if $(filter $(shell adb shell getprop ro.bionic.arch),arm64),,$(error arm64 only is supported at the moment))
+	adb root && adb remount vendor
+	mkdir -p .out/arm64
+	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make -C ~/aospless all"
+	$(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "cp -r ~/aospless/install/* ~/drm_hwcomposer/.out/arm64"
+	adb push .out/arm64/vendor/lib64/hw/hwcomposer.drm.so /vendor/lib64/hw/hwcomposer.drm.so
+	adb shell stop
+	adb shell stop vendor.hwcomposer-2-1 && adb shell start vendor.hwcomposer-2-1 || true
+	adb shell stop vendor.hwcomposer-2-2 && adb shell start vendor.hwcomposer-2-2 || true
+	adb shell stop vendor.hwcomposer-2-3 && adb shell start vendor.hwcomposer-2-3 || true
+	adb shell stop vendor.hwcomposer-2-4 && adb shell start vendor.hwcomposer-2-4 || true
+	bash -c '[[ "$$HWCLOG" -eq "1" ]] && adb logcat -c || true'
+	adb shell start
+	bash -c '[[ "$$HWCLOG" -eq "1" ]] && adb logcat | grep -i hwc || true'
+
+bd: build_deploy
+bd: ## Alias for build_deploy
 
 local_presubmit: ## Run local presubmit script (requires latest Ubuntu + additional packages). Consider 'make ci' instead
 	@echo "Run native build:"
diff --git a/build_deploy.sh b/build_deploy.sh
deleted file mode 100755
index ef25e5c..0000000
--- a/build_deploy.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/bash -e
-
-# To see logs after deploy run: $ HWCLOG=1 TESTDEV=<DEV> ./build_deploy.sh
-
-[ -z "$TESTDEV" ] && echo "Run $ TESTDEV=<Your lunch target> ./build_deploy.sh" && false
-
-cd ../..
-. build/envsetup.sh
-lunch $TESTDEV
-cd -
-
-mm
-
-adb root && adb remount && adb sync vendor
-
-adb shell stop
-adb shell stop vendor.hwcomposer-2-1 && adb shell start vendor.hwcomposer-2-1 || true
-adb shell stop vendor.hwcomposer-2-2 && adb shell start vendor.hwcomposer-2-2 || true
-adb shell stop vendor.hwcomposer-2-3 && adb shell start vendor.hwcomposer-2-3 || true
-adb shell stop vendor.hwcomposer-2-4 && adb shell start vendor.hwcomposer-2-4 || true
-
-[ $HWCLOG -eq "1" ] && adb logcat -c
-
-adb shell start
-
-[ $HWCLOG -eq "1" ] && adb logcat | grep -i hwc