diff --git a/Makefile b/Makefile index 6f119cf..e80c47c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +PROJECT_NAME = service_template NPROCS ?= $(shell nproc) CLANG_FORMAT ?= clang-format DOCKER_COMPOSE ?= docker-compose @@ -16,20 +17,19 @@ $(addsuffix /CMakeCache.txt, $(addprefix build-, $(PRESETS))): build-%/CMakeCach # Build using cmake .PHONY: $(addprefix build-, $(PRESETS)) $(addprefix build-, $(PRESETS)): build-%: build-%/CMakeCache.txt - cmake --build build-$* -j $(NPROCS) --target service_template + cmake --build build-$* -j $(NPROCS) --target $(PROJECT_NAME) # Test .PHONY: $(addprefix test-, $(PRESETS)) -$(addprefix test-, $(PRESETS)): test-%: build-% - cmake --build build-$* -j $(NPROCS) --target service_template_unittest - cmake --build build-$* -j $(NPROCS) --target service_template_benchmark +$(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-service_template + cmake --build build-$* -v --target start-$(PROJECT_NAME) # Cleanup data .PHONY: $(addprefix clean-, $(PRESETS)) @@ -48,7 +48,7 @@ dist-clean: # Install .PHONY: $(addprefix install-, $(PRESETS)) $(addprefix install-, $(PRESETS)): install-%: build-% - cmake --install build-$* -v --component service_template + cmake --install build-$* -v --component $(PROJECT_NAME) .PHONY: install install: install-release @@ -62,19 +62,19 @@ format: # 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-% - /home/user/.local/bin/service_template \ - --config /home/user/.local/etc/service_template/static_config.yaml \ - --config_vars /home/user/.local/etc/service_template/config_vars.yaml + /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.yaml # Build and run service in docker environment .PHONY: $(addprefix docker-start-, $(PRESETS)) docker-start-debug docker-start-release: docker-start-%: - $(DOCKER_COMPOSE) run -p 8080:8080 --rm service_template-container make -- --in-docker-start-$* + $(DOCKER_COMPOSE) run -p 8080:8080 --rm $(PROJECT_NAME)-container make -- --in-docker-start-$* # Start specific target 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 service_template-container make $* + $(DOCKER_COMPOSE) run --rm $(PROJECT_NAME)-container make $* # Stop docker container and cleanup data .PHONY: docker-clean-data diff --git a/README.md b/README.md index e25c0cd..6d5ce97 100644 --- a/README.md +++ b/README.md @@ -7,37 +7,28 @@ Template of a C++ service that uses [userver framework](https://github.com/userv To create your own userver-based service follow the following steps: -1. Press the green "Use this template button" at the top of this github page +1. Press the "Use this template button" at the top right of this GitHub page 2. Clone the service `git clone your-service-repo && cd your-service-repo && git submodule update --init` -3. Give a proper name to your service and replace all the occurences of "service_template" string with that name +3. Give a proper name to your service and replace all the occurrences of "service_template" string with that name 4. Feel free to tweak, adjust or fully rewrite the source code of your service. ## Makefile -Makefile contains typicaly useful targets for development: - -* `make build-debug` - debug build of the service with all the assertions and sanitizers enabled -* `make build-release` - release build of the service with LTO -* `make test-debug` - does a `make build-debug` and runs all the tests on the result -* `make test-release` - does a `make build-release` and runs all the tests on the result -* `make start-debug` - builds the service in debug mode and starts it -* `make start-release` - builds the service in release mode and starts it -* `make` or `make all` - builds and runs all the tests in release and debug modes -* `make format` - autoformat all the C++ and Python sources -* `make clean-` - cleans the object files -* `make dist-clean` - clean all, including the CMake cached configurations -* `make install` - does a `make build-release` and run install in directory set in environment `PREFIX` -* `make install-debug` - does a `make build-debug` and runs install in directory set in environment `PREFIX` +`PRESET` is either `debug`, `release`, or if you've added custom presets in `CMakeUserPresets.json`, it +can also be `debug-custom`, `release-custom`. + +* `make cmake-PRESET` - run cmake configure, update cmake options and source file lists +* `make build-PRESET` - build the service +* `make test-PRESET` - build the service and run all tests +* `make start-PRESET` - build the service, start it in testsuite environment and leave it running +* `make install-PRESET` - build the service and install it in directory set in environment `PREFIX` +* `make` or `make all` - build and run all tests in `debug` and `release` modes +* `make format` - reformat all C++ and Python sources +* `make dist-clean` - clean build files and cmake cache * `make docker-COMMAND` - run `make COMMAND` in docker environment -* `make docker-build-debug` - debug build of the service with all the assertions and sanitizers enabled in docker environment -* `make docker-test-debug` - does a `make build-debug` and runs all the tests on the result in docker environment -* `make docker-start-release` - does a `make install-release` and runs service in docker environment -* `make docker-start-debug` - does a `make install-debug` and runs service in docker environment * `make docker-clean-data` - stop docker containers -Edit `Makefile.local` to change the default configuration and build options. - ## License