-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathMakefile
More file actions
264 lines (221 loc) · 8.25 KB
/
Copy pathMakefile
File metadata and controls
264 lines (221 loc) · 8.25 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
BUILD_TYPE ?= Release
BUILD_DIR ?= build/$(BUILD_TYPE)
NPROC ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
CONAN_BUILD_ARGS ?= --build=missing
INSTALL_PREFIX ?=
INSTALL_PREFIX_ARG = $(if $(INSTALL_PREFIX),--prefix $(INSTALL_PREFIX),)
CPP_FILES = $(shell find include src tests examples -type f \( -name '*.h' -o -name '*.cpp' \) ! -name '*.inc.h' | sort)
PYTHON_FILES = conanfile.py api_codegen conan-center
DOCKER_IMAGE ?= reo7sp/tgbot-cpp
DOCKER_TEST_IMAGE ?= reo7sp/tgbot-cpp-test
DOCKER_PLATFORM ?= linux/amd64
EXAMPLE ?= echobot
EXAMPLE_IMAGE ?= tgbot-cpp-example-$(EXAMPLE)
EXAMPLE_CMAKE_ARGS = $(if $(filter echobot-submodule,$(EXAMPLE)),-DTGBOT_CPP_SOURCE_DIR=$(CURDIR),) \
$(if $(INSTALL_PREFIX),-DCMAKE_PREFIX_PATH=$(INSTALL_PREFIX),)
PORT ?= 8080
DOCS_WORKTREE := $(abspath build/gh-pages)
.PHONY: \
all \
dependencies \
dependencies-python \
dependencies-with-test \
configure \
configure-with-system \
configure-with-test \
build \
build-with-system \
build-with-test \
compile-commands \
example \
test \
test-only \
test-api-codegen \
install \
install-with-system \
install-only \
api-update \
api-generate \
format \
format-cpp \
format-python \
lint \
lint-cpp \
lint-python \
docker-image \
docker-test-image \
docker-test \
docker-test-only \
docker-test-api-codegen \
docker-push \
docker-example-image \
docker-run-example \
docker-run-example-webhook \
docker-compose-run-examples \
docker-compose-stop-examples \
docs \
docs-publish \
conan-publish \
list-includes \
list-srcs
all: build
dependencies:
conan profile detect --exist-ok
conan install . $(CONAN_BUILD_ARGS) -s build_type=$(BUILD_TYPE)
dependencies-python:
poetry install --no-interaction
dependencies-with-test: dependencies-python
conan profile detect --exist-ok
conan install . $(CONAN_BUILD_ARGS) -s build_type=$(BUILD_TYPE) -o '&:with_tests=True'
configure: dependencies
cmake -S . -B $(BUILD_DIR) \
-DCMAKE_TOOLCHAIN_FILE=$(abspath $(BUILD_DIR)/generators/conan_toolchain.cmake) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DENABLE_TESTS=OFF
configure-with-system:
cmake -S . -B $(BUILD_DIR) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DENABLE_TESTS=OFF
configure-with-test: dependencies-with-test
cmake -S . -B $(BUILD_DIR) \
-DCMAKE_TOOLCHAIN_FILE=$(abspath $(BUILD_DIR)/generators/conan_toolchain.cmake) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DENABLE_TESTS=ON
build: configure
cmake --build $(BUILD_DIR) --parallel $(NPROC)
build-with-system: configure-with-system
cmake --build $(BUILD_DIR) --parallel $(NPROC)
build-with-test: configure-with-test
cmake --build $(BUILD_DIR) --parallel $(NPROC)
compile-commands: configure-with-test
cmake -E copy_if_different $(BUILD_DIR)/compile_commands.json compile_commands.json
example:
cmake -S examples/$(EXAMPLE) -B $(BUILD_DIR)/examples/$(EXAMPLE) \
-DCMAKE_TOOLCHAIN_FILE=$(abspath $(BUILD_DIR)/generators/conan_toolchain.cmake) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DENABLE_TESTS=OFF \
$(EXAMPLE_CMAKE_ARGS)
cmake --build $(BUILD_DIR)/examples/$(EXAMPLE) --parallel $(NPROC)
test: build-with-test
$(MAKE) test-only
$(MAKE) test-api-codegen
test-only:
ctest --test-dir $(BUILD_DIR) --output-on-failure
test-api-codegen:
poetry run pytest -q api_codegen/tests
install: build
$(MAKE) install-only
install-with-system: build-with-system
$(MAKE) install-only
install-only:
cmake --install $(BUILD_DIR) $(INSTALL_PREFIX_ARG)
api-update: dependencies-python
poetry run python -m api_codegen.main update
api-generate: dependencies-python
poetry run python -m api_codegen.main generate
$(MAKE) format-cpp
format: format-cpp format-python
format-cpp:
clang-format -i $(CPP_FILES)
format-python:
poetry run ruff check --fix $(PYTHON_FILES)
poetry run ruff format $(PYTHON_FILES)
lint: lint-cpp lint-python
lint-cpp:
clang-format --dry-run --Werror $(CPP_FILES)
lint-python:
poetry run ruff check $(PYTHON_FILES)
poetry run ruff format --check $(PYTHON_FILES)
docker-image:
docker build --platform=$(DOCKER_PLATFORM) -t $(DOCKER_IMAGE) -f Dockerfile .
docker-test-image:
docker build --platform=$(DOCKER_PLATFORM) -t $(DOCKER_TEST_IMAGE) -f Dockerfile_test .
docker-test: docker-test-image
$(MAKE) docker-test-only
$(MAKE) docker-test-api-codegen
docker-test-only:
docker run --rm $(DOCKER_TEST_IMAGE) make test-only
docker-test-api-codegen:
docker run --rm $(DOCKER_TEST_IMAGE) make test-api-codegen
docker-push: docker-image
docker push $(DOCKER_IMAGE)
docker-example-image: docker-image
docker build --platform=$(DOCKER_PLATFORM) \
--build-arg TGBOT_CPP_IMAGE=$(DOCKER_IMAGE) \
-t $(EXAMPLE_IMAGE) \
-f examples/$(EXAMPLE)/Dockerfile \
$(if $(filter echobot-submodule,$(EXAMPLE)),.,examples/$(EXAMPLE))
docker-run-example: docker-example-image
@test -n "$$TOKEN" || (echo "TOKEN is required" >&2; exit 2)
docker run --rm -it --init -e TOKEN $(EXAMPLE_IMAGE)
docker-run-example-webhook: docker-example-image
@test -n "$$TOKEN" || (echo "TOKEN is required" >&2; exit 2)
@test -n "$$WEBHOOK_URL" || (echo "WEBHOOK_URL is required" >&2; exit 2)
docker run --rm -it --init -e TOKEN -e WEBHOOK_URL -p $(PORT):8080 $(EXAMPLE_IMAGE)
docker-compose-run-examples: docker-image
DOCKER_PLATFORM=$(DOCKER_PLATFORM) TGBOT_CPP_IMAGE=$(DOCKER_IMAGE) \
docker compose --env-file env -f docker-compose.test.yaml up --build
docker-compose-stop-examples:
docker compose --env-file env -f docker-compose.test.yaml down
docs:
rm -rf -- doc docs
doxygen
mv doc/html docs
touch docs/.nojekyll
docs-publish: docs
git fetch origin gh-pages
git worktree add --detach $(DOCS_WORKTREE) origin/gh-pages
find $(DOCS_WORKTREE) -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf -- {} +
cp -R docs/. $(DOCS_WORKTREE)/
git -C $(DOCS_WORKTREE) add -A
git -C $(DOCS_WORKTREE) diff --cached --quiet || \
git -C $(DOCS_WORKTREE) commit -m "Updated docs $$(date +%Y-%m-%d)"
git -C $(DOCS_WORKTREE) push origin HEAD:gh-pages
git worktree remove $(DOCS_WORKTREE)
conan-publish:
@command -v gh >/dev/null || (echo "gh is required to create the Conan Center pull request" >&2; exit 2)
@set -eu; \
version=$$(git describe --tags --exact-match --match 'v*' 2>/dev/null | sed 's/^v//'); \
test -n "$$version" || { echo "Run this target on a v* release tag" >&2; exit 2; }; \
index="$(abspath build/conan-center-index)"; \
branch="package/tgbot-$$version"; \
owner=$$(gh api user --jq .login); \
if test ! -d "$$index/.git"; then \
gh repo view "$$owner/conan-center-index" >/dev/null 2>&1 || \
gh repo fork conan-io/conan-center-index --clone=false; \
gh repo clone "$$owner/conan-center-index" "$$index" -- --filter=blob:none --sparse; \
fi; \
git -C "$$index" sparse-checkout set recipes/tgbot; \
git -C "$$index" remote get-url upstream >/dev/null 2>&1 || \
git -C "$$index" remote add upstream https://github.com/conan-io/conan-center-index.git; \
test -z "$$(git -C "$$index" status --porcelain)" || \
{ echo "The conan-center-index checkout must be clean" >&2; exit 2; }; \
git -C "$$index" fetch upstream master; \
git -C "$$index" switch -c "$$branch" upstream/master; \
recipe="$$index/recipes/tgbot"; \
tag="v$$version"; \
url="https://github.com/reo7sp/tgbot-cpp/archive/$$tag.tar.gz"; \
archive=$$(mktemp); \
trap 'rm -f "$$archive"' EXIT; \
grep -q "\"$$version\"" "$$recipe/config.yml" && \
{ echo "tgbot/$$version already exists in Conan Center index" >&2; exit 2; }; \
curl -fL "$$url" -o "$$archive"; \
sha256=$$(shasum -a 256 "$$archive" | cut -d ' ' -f 1); \
cp conan-center/conanfile.py "$$recipe/all/conanfile.py"; \
printf ' "%s":\n folder: all\n' "$$version" >> "$$recipe/config.yml"; \
printf ' "%s":\n url: "%s"\n sha256: "%s"\n' "$$version" "$$url" "$$sha256" >> "$$recipe/all/conandata.yml"; \
git -C "$$index" add recipes/tgbot; \
git -C "$$index" commit -m "tgbot/$$version"; \
git -C "$$index" push -u origin "$$branch"; \
gh pr create --repo conan-io/conan-center-index \
--head "$$owner:$$branch" \
--title "tgbot/$$version" \
--body "Updates tgbot to $$version."
list-includes:
@find include -type f -name '*.h' -print | sort | \
sed 's|^include/|#include "|; s|$$|"|'
list-srcs:
@find src -type f -name '*.cpp' -print | sort