Skip to content

Commit 08f99f3

Browse files
authored
refactor build: unify target and directory names (#89)
1 parent c0532b2 commit 08f99f3

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

Makefile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
PROJECT_NAME = service_template
12
NPROCS ?= $(shell nproc)
23
CLANG_FORMAT ?= clang-format
34
DOCKER_COMPOSE ?= docker-compose
@@ -16,20 +17,19 @@ $(addsuffix /CMakeCache.txt, $(addprefix build-, $(PRESETS))): build-%/CMakeCach
1617
# Build using cmake
1718
.PHONY: $(addprefix build-, $(PRESETS))
1819
$(addprefix build-, $(PRESETS)): build-%: build-%/CMakeCache.txt
19-
cmake --build build-$* -j $(NPROCS) --target service_template
20+
cmake --build build-$* -j $(NPROCS) --target $(PROJECT_NAME)
2021

2122
# Test
2223
.PHONY: $(addprefix test-, $(PRESETS))
23-
$(addprefix test-, $(PRESETS)): test-%: build-%
24-
cmake --build build-$* -j $(NPROCS) --target service_template_unittest
25-
cmake --build build-$* -j $(NPROCS) --target service_template_benchmark
24+
$(addprefix test-, $(PRESETS)): test-%: build-%/CMakeCache.txt
25+
cmake --build build-$* -j $(NPROCS)
2626
cd build-$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V)
2727
pycodestyle tests
2828

2929
# Start the service (via testsuite service runner)
3030
.PHONY: $(addprefix start-, $(PRESETS))
3131
$(addprefix start-, $(PRESETS)): start-%:
32-
cmake --build build-$* -v --target start-service_template
32+
cmake --build build-$* -v --target start-$(PROJECT_NAME)
3333

3434
# Cleanup data
3535
.PHONY: $(addprefix clean-, $(PRESETS))
@@ -48,7 +48,7 @@ dist-clean:
4848
# Install
4949
.PHONY: $(addprefix install-, $(PRESETS))
5050
$(addprefix install-, $(PRESETS)): install-%: build-%
51-
cmake --install build-$* -v --component service_template
51+
cmake --install build-$* -v --component $(PROJECT_NAME)
5252

5353
.PHONY: install
5454
install: install-release
@@ -62,19 +62,19 @@ format:
6262
# Internal hidden targets that are used only in docker environment
6363
.PHONY: $(addprefix --in-docker-start-, $(PRESETS))
6464
$(addprefix --in-docker-start-, $(PRESETS)): --in-docker-start-%: install-%
65-
/home/user/.local/bin/service_template \
66-
--config /home/user/.local/etc/service_template/static_config.yaml \
67-
--config_vars /home/user/.local/etc/service_template/config_vars.yaml
65+
/home/user/.local/bin/$(PROJECT_NAME) \
66+
--config /home/user/.local/etc/$(PROJECT_NAME)/static_config.yaml \
67+
--config_vars /home/user/.local/etc/$(PROJECT_NAME)/config_vars.yaml
6868

6969
# Build and run service in docker environment
7070
.PHONY: $(addprefix docker-start-, $(PRESETS))
7171
docker-start-debug docker-start-release: docker-start-%:
72-
$(DOCKER_COMPOSE) run -p 8080:8080 --rm service_template-container make -- --in-docker-start-$*
72+
$(DOCKER_COMPOSE) run -p 8080:8080 --rm $(PROJECT_NAME)-container make -- --in-docker-start-$*
7373

7474
# Start specific target in docker environment
7575
.PHONY: $(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) $(addprefix docker-install-, $(PRESETS))
7676
$(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) $(addprefix docker-install-, $(PRESETS)): docker-%:
77-
$(DOCKER_COMPOSE) run --rm service_template-container make $*
77+
$(DOCKER_COMPOSE) run --rm $(PROJECT_NAME)-container make $*
7878

7979
# Stop docker container and cleanup data
8080
.PHONY: docker-clean-data

README.md

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,28 @@ Template of a C++ service that uses [userver framework](https://github.com/userv
77

88
To create your own userver-based service follow the following steps:
99

10-
1. Press the green "Use this template button" at the top of this github page
10+
1. Press the "Use this template button" at the top right of this GitHub page
1111
2. Clone the service `git clone your-service-repo && cd your-service-repo && git submodule update --init`
12-
3. Give a proper name to your service and replace all the occurences of "service_template" string with that name
12+
3. Give a proper name to your service and replace all the occurrences of "service_template" string with that name
1313
4. Feel free to tweak, adjust or fully rewrite the source code of your service.
1414

1515

1616
## Makefile
1717

18-
Makefile contains typicaly useful targets for development:
19-
20-
* `make build-debug` - debug build of the service with all the assertions and sanitizers enabled
21-
* `make build-release` - release build of the service with LTO
22-
* `make test-debug` - does a `make build-debug` and runs all the tests on the result
23-
* `make test-release` - does a `make build-release` and runs all the tests on the result
24-
* `make start-debug` - builds the service in debug mode and starts it
25-
* `make start-release` - builds the service in release mode and starts it
26-
* `make` or `make all` - builds and runs all the tests in release and debug modes
27-
* `make format` - autoformat all the C++ and Python sources
28-
* `make clean-` - cleans the object files
29-
* `make dist-clean` - clean all, including the CMake cached configurations
30-
* `make install` - does a `make build-release` and run install in directory set in environment `PREFIX`
31-
* `make install-debug` - does a `make build-debug` and runs install in directory set in environment `PREFIX`
18+
`PRESET` is either `debug`, `release`, or if you've added custom presets in `CMakeUserPresets.json`, it
19+
can also be `debug-custom`, `release-custom`.
20+
21+
* `make cmake-PRESET` - run cmake configure, update cmake options and source file lists
22+
* `make build-PRESET` - build the service
23+
* `make test-PRESET` - build the service and run all tests
24+
* `make start-PRESET` - build the service, start it in testsuite environment and leave it running
25+
* `make install-PRESET` - build the service and install it in directory set in environment `PREFIX`
26+
* `make` or `make all` - build and run all tests in `debug` and `release` modes
27+
* `make format` - reformat all C++ and Python sources
28+
* `make dist-clean` - clean build files and cmake cache
3229
* `make docker-COMMAND` - run `make COMMAND` in docker environment
33-
* `make docker-build-debug` - debug build of the service with all the assertions and sanitizers enabled in docker environment
34-
* `make docker-test-debug` - does a `make build-debug` and runs all the tests on the result in docker environment
35-
* `make docker-start-release` - does a `make install-release` and runs service in docker environment
36-
* `make docker-start-debug` - does a `make install-debug` and runs service in docker environment
3730
* `make docker-clean-data` - stop docker containers
3831

39-
Edit `Makefile.local` to change the default configuration and build options.
40-
4132

4233
## License
4334

0 commit comments

Comments
 (0)