blob: 16269e2a834127b466d922bc6f704298c96d26f2 [file] [log] [blame]
Roman Stratiienko32957192022-12-15 10:12:31 +02001#!/usr/bin/make
2
3DOCKER_BIN := $(shell command -v docker 2> /dev/null)
4NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
5
6DOCKERFILE := .ci/Dockerfile
7IMAGE_NAME := drmhwc_ci
8
9# We can't run style and bpfmt check in docker
10# when repo is within AOSP tree, will run it locally.
11GIT_IS_SYMLINK:=$(shell test -L .git && echo true)
12
13define print_no_docker_err
14$(warning Please install docker, e.g. for Ubuntu:)
15$(warning $$ sudo apt install docker.io)
16$(warning $$ sudo usermod -aG docker $$USER)
17$(warning and reboot your PC)
18$(error Aborting...)
19endef
20
21.PHONY : help prepare shell ci ci_cleanup local_presubmit local_cleanup
22.DEFAULT_GOAL := help
23
24help: ## Show this help
25 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
26
27PREPARE:=.out/prepare_docker.timestamp
28$(PREPARE): $(DOCKERFILE)
29 $(if $(DOCKER_BIN),,$(call print_no_docker_err))
30 mkdir -p $(dir $@)
31 $(DOCKER_BIN) build -t local/build-env -f $(DOCKERFILE) .;
32 $(DOCKER_BIN) stop $(IMAGE_NAME) || true
33 $(DOCKER_BIN) rm $(IMAGE_NAME) || true
34 $(DOCKER_BIN) run -itd --name $(IMAGE_NAME) --network="host" -v $(shell pwd):/home/user/drm_hwcomposer local/build-env
35 @touch $@
36
37prepare: $(PREPARE)
38prepare: ## Build and run Docker image
39
40shell: $(PREPARE)
41shell: ## Start shell into a container
42 $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash
43
44ci: $(PREPARE)
45ci: ## Run presubmit within the docker container
46 @echo "Run native build:"
47 $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make -f .ci/Makefile -j$(NPROCS)"
48 @echo "Run style check:"
49 $(if $(GIT_IS_SYMLINK), \
50 ./.ci/.gitlab-ci-checkcommit.sh, \
51 $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "./.ci/.gitlab-ci-checkcommit.sh")
52 @echo "\n\e[32m --- SUCCESS ---\n"
53
54ci_cleanup: ## Cleanup after 'make ci'
55 $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make local_cleanup"
56
57local_presubmit: ## Run local presubmit script (requires latest Ubuntu + additional packages). Consider 'make ci' instead
58 @echo "Run native build:"
59 make -f .ci/Makefile -j12
60 @echo "Run style check:"
61 ./.ci/.gitlab-ci-checkcommit.sh
62 @echo "\n\e[32m --- SUCCESS ---\n"
63
64local_cleanup: ## Cleanup after 'make local_presubmit'
65 make -f .ci/Makefile clean