diff --git a/.gen/benchs.txt b/.gen/benchs.txt new file mode 100644 index 00000000..0efe48d1 --- /dev/null +++ b/.gen/benchs.txt @@ -0,0 +1 @@ +benchs/hello_benchmark.cpp diff --git a/.gen/objs.txt b/.gen/objs.txt new file mode 100644 index 00000000..35bcec7c --- /dev/null +++ b/.gen/objs.txt @@ -0,0 +1,30 @@ +src/views/register/view.hpp +src/views/register/view.cpp +src/views/register/Request.hpp +src/views/register/Request.cpp +src/views/login/view.hpp +src/views/login/view.cpp +src/views/login/Request.hpp +src/views/login/Request.cpp +src/views/hello/view.hpp +src/views/hello/view.cpp +src/utils/json_type.hpp +src/utils/json_type.cpp +src/utils/component_list_fwd.hpp +src/models/user_type/type.hpp +src/models/user_type/postgre.hpp +src/models/user_type/parse.hpp +src/models/user_type/parse.cpp +src/models/user/type.hpp +src/models/user/postgre.hpp +src/models/auth_token/type.hpp +src/models/auth_token/serialize.hpp +src/http/handler_parsed.hpp +src/components/controllers/user_controller_fwd.hpp +src/components/controllers/user_controller_fwd.cpp +src/components/controllers/user_controller.hpp +src/components/controllers/user_controller.cpp +src/components/controllers/token_controller_fwd.hpp +src/components/controllers/token_controller_fwd.cpp +src/components/controllers/token_controller.hpp +src/components/controllers/token_controller.cpp diff --git a/.gen/service.txt b/.gen/service.txt new file mode 100644 index 00000000..d24bf269 --- /dev/null +++ b/.gen/service.txt @@ -0,0 +1 @@ +service/main.cpp diff --git a/.gen/unittest.txt b/.gen/unittest.txt new file mode 100644 index 00000000..72ba6f85 --- /dev/null +++ b/.gen/unittest.txt @@ -0,0 +1 @@ +utests/hello_test.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da2ab60f..3ede11c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,13 @@ jobs: with: submodules: true + - name: Check format sources + run: | + make check-format + - name: Gen list of source and check diffs with commit + run: | + make gen + make check-git-status - name: Reuse ccache directory uses: actions/cache@v2 with: diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index f13003d4..5cc1678b 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -15,7 +15,13 @@ jobs: - uses: actions/checkout@v2 with: submodules: true - + - name: Check format sources + run: | + make check-format + - name: Check git status + run: | + make gen + make check-git-status - name: Reuse ccache directory uses: actions/cache@v2 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c3f7f1e..22fc24f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,50 +9,28 @@ include(GNUInstallDirs) add_subdirectory(third_party/userver) +#make gen +#source lists are generated in the .gen folder +file(STRINGS ${PROJECT_SOURCE_DIR}/.gen/benchs.txt benchs_src) +file(STRINGS ${PROJECT_SOURCE_DIR}/.gen/objs.txt objs_src) +file(STRINGS ${PROJECT_SOURCE_DIR}/.gen/service.txt service_src) +file(STRINGS ${PROJECT_SOURCE_DIR}/.gen/unittest.txt unittest_src) # Common sources add_library(${PROJECT_NAME}_objs OBJECT - src/views/hello/view.hpp - src/views/hello/view.cpp - src/components/controllers/user_controller.cpp - src/components/controllers/user_controller.hpp - src/components/controllers/user_controller_fwd.hpp - src/components/controllers/user_controller_fwd.cpp - src/components/controllers/token_controller_fwd.cpp - src/components/controllers/user_controller_fwd.cpp - src/components/controllers/token_controller.hpp - src/components/controllers/token_controller.cpp - src/models/auth_token/type.hpp - src/models/auth_token/serialize.hpp - src/http/handler_parsed.hpp - src/models/user/type.hpp - src/models/user_type/parse.cpp - src/models/user_type/parse.hpp - src/models/user_type/postgre.hpp - src/models/user_type/type.hpp - src/utils/component_list_fwd.hpp - src/utils/json_type.cpp - src/utils/json_type.hpp - src/views/login/Request.cpp - src/views/login/Request.hpp - src/views/login/view.cpp - src/views/login/view.hpp - src/views/register/Request.cpp - src/views/register/Request.hpp - src/views/register/view.cpp - src/views/register/view.hpp + ${objs_src} ) target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver-core userver-postgresql) # The Service -add_executable(${PROJECT_NAME} service/main.cpp) +add_executable(${PROJECT_NAME} ${service_src}) target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objs) # Unit Tests add_executable(${PROJECT_NAME}_unittest - utests/hello_test.cpp + ${unittest_src} ) target_link_libraries(${PROJECT_NAME}_unittest PRIVATE ${PROJECT_NAME}_objs userver-utest) add_google_tests(${PROJECT_NAME}_unittest) @@ -60,7 +38,7 @@ add_google_tests(${PROJECT_NAME}_unittest) # Benchmarks add_executable(${PROJECT_NAME}_benchmark - benchs/hello_benchmark.cpp + ${benchs_src} ) target_link_libraries(${PROJECT_NAME}_benchmark PRIVATE ${PROJECT_NAME}_objs userver-ubench) add_google_benchmark_tests(${PROJECT_NAME}_benchmark) diff --git a/Makefile b/Makefile index e5591a57..2fa55cd9 100644 --- a/Makefile +++ b/Makefile @@ -68,12 +68,58 @@ install-debug install-release: install-%: build-% .PHONY: install install: install-release -# Format the sources -.PHONY: format -format: +.PHONY: format-cpp +format-cpp: + @find benchs -name '*pp' -type f | xargs $(CLANG_FORMAT) -i + @find service -name '*pp' -type f | xargs $(CLANG_FORMAT) -i @find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i + @find utests -name '*pp' -type f | xargs $(CLANG_FORMAT) -i + +# Format the sources +.PHONY: format-all +format: format-cpp @find tests -name '*.py' -type f | xargs autopep8 -i +# Check format the sources +.PHONY: check-format +check-format: check-format-cpp + +.PHONY: check-git-status +check-git-status: + @echo "Checking if all files are committed to git..." + @if [ -n "$$(git status --porcelain)" ]; then \ + echo "The following files are not committed:"; \ + git status --short; \ + echo "Please commit all changes and try again."; \ + git diff --color | cat; \ + exit 1; \ + else \ + echo "All files are committed to git."; \ + fi + +.PHONY: check-format-cpp +check-format-cpp: + @find benchs -name '*pp' -type f | xargs $(CLANG_FORMAT) -i --dry-run --Werror + @find service -name '*pp' -type f | xargs $(CLANG_FORMAT) -i --dry-run --Werror + @find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i --dry-run --Werror + @find utests -name '*pp' -type f | xargs $(CLANG_FORMAT) -i --dry-run --Werror +.PHONY: gen +gen: + @rm -rf .gen + @mkdir -p .gen + + @find benchs -name '*pp' > .gen/benchs.txt + @LC_COLLATE=C sort .gen/benchs.txt -r -o .gen/benchs.txt + + @find src -name '*pp' > .gen/objs.txt + @LC_COLLATE=C sort .gen/objs.txt -r -o .gen/objs.txt + + @find service -name '*pp' > .gen/service.txt + @LC_COLLATE=C sort .gen/service.txt -r -o .gen/service.txt + + @find utests -name '*pp' > .gen/unittest.txt + @LC_COLLATE=C sort .gen/unittest.txt -r -o .gen/unittest.txt + # Internal hidden targets that are used only in docker environment --in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-% @sed -i 's/config_vars.yaml/config_vars.docker.yaml/g' /home/user/.local/etc/timetable_vsu_backend/static_config.yaml diff --git a/benchs/hello_benchmark.cpp b/benchs/hello_benchmark.cpp index 22109938..b2d61f05 100644 --- a/benchs/hello_benchmark.cpp +++ b/benchs/hello_benchmark.cpp @@ -14,7 +14,8 @@ void HelloBenchmark(benchmark::State& state) { for (auto _ : state) { const auto name = kNames[i++ % std::size(kNames)]; - auto result = service_template::SayHelloTo(name, service_template::UserType::kKnown); + auto result = service_template::SayHelloTo( + name, service_template::UserType::kKnown); benchmark::DoNotOptimize(result); } }); diff --git a/service/main.cpp b/service/main.cpp index 4e0d8639..acde29c0 100644 --- a/service/main.cpp +++ b/service/main.cpp @@ -1,58 +1,57 @@ -#include #include #include +#include #include #include #include #include +#include +#include +#include +#include +#include "../src/components/controllers/token_controller_fwd.hpp" +#include "../src/components/controllers/user_controller_fwd.hpp" #include "../src/views/hello/view.hpp" +#include "../src/views/login/view.hpp" +#include "../src/views/register/view.hpp" #include "userver/formats/json/value.hpp" #include "userver/logging/log.hpp" #include "userver/storages/postgres/component.hpp" -#include "../src/views/login/view.hpp" -#include "../src/views/register/view.hpp" -#include "../src/components/controllers/token_controller_fwd.hpp" -#include "../src/components/controllers/user_controller_fwd.hpp" -#include -#include -#include -#include namespace fs = std::filesystem; -void LogAllFiles(fs::path path){ +void LogAllFiles(fs::path path) { std::stringstream buffer; LOG_ERROR() << path; - for (const auto & entry : fs::directory_iterator(path)) - buffer << entry.path() << ' '; + for (const auto& entry : fs::directory_iterator(path)) + buffer << entry.path() << ' '; LOG_ERROR() << buffer.str(); } -void LogCommands(int argc, char** argv){ +void LogCommands(int argc, char** argv) { std::stringstream buffer; - if (argc == 0){ + if (argc == 0) { LOG_ERROR() << "No commands"; } - for (int i = 0; i < argc; i++){ + for (int i = 0; i < argc; i++) { buffer << argv[i] << ' '; } LOG_ERROR() << fmt::format("Commands is {}", buffer.str()); } -void LogFile(std::string_view path){ +void LogFile(std::string_view path) { std::string path_str(path); std::ifstream file(path_str); std::string temp; - if (!file.is_open()){ + if (!file.is_open()) { std::stringstream buffer; buffer << strerror(errno); LOG_ERROR() << fmt::format("{} ifstream fail: {} ", path, buffer.str()); - } - else if (file.eof()){ + } else if (file.eof()) { LOG_ERROR() << fmt::format("{} is empty", path); } - while (std::getline(file, temp)){ + while (std::getline(file, temp)) { LOG_ERROR() << temp; } file.close(); @@ -68,13 +67,14 @@ int main(int argc, char* argv[]) { // LogFile("config_vars.docker.yaml"); using namespace timetable_vsu_backend::components; using namespace timetable_vsu_backend::views; - auto component_list = userver::components::MinimalServerComponentList() - .Append() - .Append() - .Append() - .Append() - .Append("postgres-db-1") - .Append(); + auto component_list = + userver::components::MinimalServerComponentList() + .Append() + .Append() + .Append() + .Append() + .Append("postgres-db-1") + .Append(); service_template::AppendHello(component_list); timetable_vsu_backend::views::login::Append(component_list); timetable_vsu_backend::views::register_::Append(component_list); diff --git a/utests/hello_test.cpp b/utests/hello_test.cpp index 415e8eb7..c3cf58be 100644 --- a/utests/hello_test.cpp +++ b/utests/hello_test.cpp @@ -1,10 +1,15 @@ -#include "../src/views/hello/view.hpp" -#include #include - +#include +#include "../src/views/hello/view.hpp" UTEST(SayHelloTo, Basic) { - EXPECT_EQ(service_template::SayHelloTo("Developer", service_template::UserType::kKnown), "Hi again, Developer!\n"); - EXPECT_EQ(service_template::SayHelloTo("", service_template::UserType::kFirstTime), "Hello, unknown user!\n"); - EXPECT_EQ(service_template::SayHelloTo("Developer", service_template::UserType::kFirstTime), "Hello, Developer!\n"); + EXPECT_EQ(service_template::SayHelloTo("Developer", + service_template::UserType::kKnown), + "Hi again, Developer!\n"); + EXPECT_EQ( + service_template::SayHelloTo("", service_template::UserType::kFirstTime), + "Hello, unknown user!\n"); + EXPECT_EQ(service_template::SayHelloTo( + "Developer", service_template::UserType::kFirstTime), + "Hello, Developer!\n"); } diff --git a/.vscode/vsu_timetable.code-workspace b/vsu_timetable.code-workspace similarity index 96% rename from .vscode/vsu_timetable.code-workspace rename to vsu_timetable.code-workspace index fe5d49e3..a29499af 100644 --- a/.vscode/vsu_timetable.code-workspace +++ b/vsu_timetable.code-workspace @@ -1,7 +1,7 @@ { "folders": [ { - "path": "../", + "path": ".", "name" : "vsu_timetable" }, ],