Roman Stratiienko | 3295719 | 2022-12-15 10:12:31 +0200 | [diff] [blame] | 1 | #!/usr/bin/make |
| 2 | |
| 3 | DOCKER_BIN := $(shell command -v docker 2> /dev/null) |
| 4 | NPROCS:=$(shell grep -c ^processor /proc/cpuinfo) |
| 5 | |
| 6 | DOCKERFILE := .ci/Dockerfile |
| 7 | IMAGE_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. |
| 11 | GIT_IS_SYMLINK:=$(shell test -L .git && echo true) |
| 12 | |
| 13 | define 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...) |
| 19 | endef |
| 20 | |
| 21 | .PHONY : help prepare shell ci ci_cleanup local_presubmit local_cleanup |
| 22 | .DEFAULT_GOAL := help |
| 23 | |
| 24 | help: ## Show this help |
| 25 | @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) |
| 26 | |
| 27 | PREPARE:=.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 | |
| 37 | prepare: $(PREPARE) |
| 38 | prepare: ## Build and run Docker image |
| 39 | |
| 40 | shell: $(PREPARE) |
| 41 | shell: ## Start shell into a container |
| 42 | $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash |
| 43 | |
| 44 | ci: $(PREPARE) |
| 45 | ci: ## 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 | |
| 54 | ci_cleanup: ## Cleanup after 'make ci' |
| 55 | $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make local_cleanup" |
| 56 | |
| 57 | local_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 | |
| 64 | local_cleanup: ## Cleanup after 'make local_presubmit' |
| 65 | make -f .ci/Makefile clean |