generated from userver-framework/pg_service_template
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile
93 lines (75 loc) · 3.46 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
PROJECT_NAME = service_template
NPROCS ?= $(shell nproc)
CLANG_FORMAT ?= clang-format
DOCKER_COMPOSE ?= docker-compose
PRESETS ?= debug release debug-custom release-custom
.PHONY: all
all: test-debug test-release
# Run cmake
.PHONY: $(addprefix cmake-, $(PRESETS))
$(addprefix cmake-, $(PRESETS)): cmake-%:
cmake --preset $*
$(addsuffix /CMakeCache.txt, $(addprefix build-, $(PRESETS))): build-%/CMakeCache.txt: cmake-%
# Build using cmake
.PHONY: $(addprefix build-, $(PRESETS))
$(addprefix build-, $(PRESETS)): build-%: build-%/CMakeCache.txt
cmake --build build-$* -j $(NPROCS) --target $(PROJECT_NAME)
# Test
.PHONY: $(addprefix test-, $(PRESETS))
$(addprefix test-, $(PRESETS)): test-%: build-%/CMakeCache.txt
cmake --build build-$* -j $(NPROCS)
cd build-$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V)
pycodestyle tests
# Start the service (via testsuite service runner)
.PHONY: $(addprefix start-, $(PRESETS))
$(addprefix start-, $(PRESETS)): start-%:
cmake --build build-$* -v --target start-$(PROJECT_NAME)
.PHONY: service-start-debug service-start-release
service-start-debug service-start-release: service-start-%: start-%
# Cleanup data
.PHONY: $(addprefix clean-, $(PRESETS))
$(addprefix clean-, $(PRESETS)): clean-%:
cmake --build build-$* --target clean
.PHONY: dist-clean
dist-clean:
rm -rf build*
rm -rf tests/__pycache__/
rm -rf tests/.pytest_cache/
rm -rf .ccache
rm -rf .vscode/.cache
rm -rf .vscode/compile_commands.json
# Install
.PHONY: $(addprefix install-, $(PRESETS))
$(addprefix install-, $(PRESETS)): install-%: build-%
cmake --install build-$* -v --component $(PROJECT_NAME)
.PHONY: install
install: install-release
# Format the sources
.PHONY: format
format:
find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
find tests -name '*.py' -type f | xargs autopep8 -i
# Set environment for --in-docker-start
export DB_CONNECTION := postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@service-postgres:5432/${POSTGRES_DB}
# Internal hidden targets that are used only in docker environment
.PHONY: $(addprefix --in-docker-start-, $(PRESETS))
$(addprefix --in-docker-start-, $(PRESETS)): --in-docker-start-%: install-%
psql ${DB_CONNECTION} -f ./postgresql/data/initial_data.sql
/home/user/.local/bin/$(PROJECT_NAME) \
--config /home/user/.local/etc/$(PROJECT_NAME)/static_config.yaml \
--config_vars /home/user/.local/etc/$(PROJECT_NAME)/config_vars.docker.yaml
# Build and run service in docker environment
.PHONY: $(addprefix docker-start-, $(PRESETS))
$(addprefix docker-start-, $(PRESETS)): docker-start-%:
$(DOCKER_COMPOSE) run -p 8080:8080 -p 8081:8081 --rm $(PROJECT_NAME)-container make -- --in-docker-start-$*
.PHONY: docker-start-service-debug docker-start-service-release
docker-start-service-debug docker-start-service-release: docker-start-service-%: docker-start-%
# Start targets makefile in docker environment
.PHONY: $(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) $(addprefix docker-install-, $(PRESETS))
$(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) $(addprefix docker-install-, $(PRESETS)): docker-%:
$(DOCKER_COMPOSE) run --rm $(PROJECT_NAME)-container make $*
# Stop docker container and remove PG data
.PHONY: docker-clean-data
docker-clean-data:
$(DOCKER_COMPOSE) down -v
rm -rf ./.pgdata