Skip to content

Commit

Permalink
Magic convert (#7)
Browse files Browse the repository at this point in the history
1) Docker workflow выключен из-за того, что в Dockerfile userver используется g++ 9.4, который сегфолтится
2) Добавлены автостоп ранов и очистка старых ранов
3) Пофикшен CMake проекта: инклуды прокидываются по таргетам
4) Добавлены шаблонные парсеры, сериализаторы для json/http
  • Loading branch information
sabudilovskiy authored Apr 8, 2023
1 parent e4837f9 commit b7226dd
Show file tree
Hide file tree
Showing 58 changed files with 1,342 additions and 469 deletions.
16 changes: 14 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
BasedOnStyle: google
# Описание настроек форматирования для clang-format 14

BasedOnStyle: Google
IndentWidth: 4
TabWidth: 4
UseTab: Never
BreakBeforeBraces: Attach
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
ColumnLimit: 80
PointerAlignment: Left
SpaceAfterCStyleCast: true
DerivePointerAlignment: false
IncludeBlocks: Preserve
AlignTrailingComments: true
15 changes: 14 additions & 1 deletion .gen/objs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ src/views/register/Request.hpp
src/views/register/Request.cpp
src/views/login/view.hpp
src/views/login/view.cpp
src/views/login/Responses.hpp
src/views/login/Request.hpp
src/views/login/Request.cpp
src/views/hello/view.hpp
src/views/hello/view.cpp
src/utils/meta.hpp
src/utils/json_type.hpp
src/utils/json_type.cpp
src/utils/convert/json_serialize.hpp
src/utils/convert/json_parse.hpp
src/utils/convert/http_response_serialize.hpp
src/utils/convert/http_response_base.hpp
src/utils/convert/http_request_parse.hpp
src/utils/convert/detail/serialize/converter_json.hpp
src/utils/convert/detail/serialize/converter_http_response.hpp
src/utils/convert/detail/parse/converter_json.hpp
src/utils/convert/detail/parse/converter_http_request.hpp
src/utils/convert/base.hpp
src/utils/constexpr_string.hpp
src/utils/component_list_fwd.hpp
src/models/user_type/type.hpp
src/models/user_type/postgre.hpp
Expand All @@ -19,6 +31,7 @@ src/models/user/type.hpp
src/models/user/postgre.hpp
src/models/auth_token/type.hpp
src/models/auth_token/serialize.hpp
src/http/legacy_handler_parsed.hpp
src/http/handler_parsed.hpp
src/components/controllers/user_controller_fwd.hpp
src/components/controllers/user_controller_fwd.cpp
Expand Down
1 change: 1 addition & 0 deletions .gen/unittest.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
utests/hello_test.cpp
utests/convert_test.cpp
31 changes: 20 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,37 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-22.04
make: test-debug
info: g++-9 + test-debug
info: g++-11 + test-debug

- os: ubuntu-20.04
- os: ubuntu-22.04
make: test-release
info: g++-9 + test-release
info: g++-11 + test-release

name: '${{matrix.os}}: ${{matrix.info}}'
runs-on: ${{matrix.os}}

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
- uses: actions/checkout@v2
with:
submodules: true

- name: add Postgres package repository
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
- name: Install packages
run: |
sudo apt update
sudo apt install --allow-downgrades -y pep8 $(cat dependencies/${{matrix.os}}.md | tr '\n' ' ')
sudo apt install clang-format-11
sudo pip install $(cat dependencies/python.md) | tr '\n' ' '
- name: install g++11
run: |
sudo apt install g++-11
export CXX=/usr/bin/g++-11
- name: Check format sources
run: |
make check-format
Expand All @@ -47,12 +62,6 @@ jobs:
${{matrix.os}} ${{matrix.info}} ccache-dir ${{github.ref}} run-'
${{matrix.os}} ${{matrix.info}} ccache-
- name: Install packages
run: |
sudo apt update
sudo apt install --allow-downgrades -y pep8 $(cat third_party/userver/scripts/docs/en/deps/${{matrix.os}}.md | tr '\n' ' ')
sudo pip install $(cat dependencies/python.md) | tr '\n' ' '
- name: Setup ccache
run: |
ccache -M 2.0GB
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/delete_old_runs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Delete old workflow runs
on:
workflow_dispatch:
inputs:
days:
description: 'Number of days.'
required: true
default: 0
minimum_runs:
description: 'The minimum runs to keep for each workflow.'
required: true
default: 0
delete_workflow_pattern:
description: 'The name or filename of the workflow. if not set then it will target all workflows.'
required: false
delete_workflow_by_state_pattern:
description: 'Remove workflow by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
required: true
default: "All"
type: choice
options:
- "All"
- active
- deleted
- disabled_inactivity
- disabled_manually
delete_run_by_conclusion_pattern:
description: 'Remove workflow by conclusion: action_required, cancelled, failure, skipped, success'
required: true
default: failure
type: choice
options:
- "All"
- action_required
- cancelled
- failure
- skipped
- success
dry_run:
description: 'Only log actions, do not perform any delete operations.'
required: false

jobs:
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
delete_run_by_conclusion_pattern: ${{ github.event.inputs.delete_run_by_conclusion_pattern }}
dry_run: ${{ github.event.inputs.dry_run }}
44 changes: 0 additions & 44 deletions .github/workflows/docker.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "third_party/userver"]
path = third_party/userver
url = https://github.com/userver-framework/userver.git
url = https://github.com/userver-framework/userver.git
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
cmake_minimum_required(VERSION 3.12)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)

project(timetable_vsu_backend CXX)
message("Compiler version: ${CMAKE_CXX_COMPILER_VERSION}")

include(third_party/userver/cmake/SetupEnvironment.cmake)
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)
Expand All @@ -20,18 +19,21 @@ file(STRINGS ${PROJECT_SOURCE_DIR}/.gen/unittest.txt unittest_src)
add_library(${PROJECT_NAME}_objs OBJECT
${objs_src}
)
target_include_directories(${PROJECT_NAME}_objs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver-core userver-postgresql)


# The Service
add_executable(${PROJECT_NAME} ${service_src})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/service)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objs)


# Unit Tests
add_executable(${PROJECT_NAME}_unittest
${unittest_src}
)
target_include_directories(${PROJECT_NAME}_unittest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/utests)
target_link_libraries(${PROJECT_NAME}_unittest PRIVATE ${PROJECT_NAME}_objs userver-utest)
add_google_tests(${PROJECT_NAME}_unittest)

Expand All @@ -40,6 +42,7 @@ add_google_tests(${PROJECT_NAME}_unittest)
add_executable(${PROJECT_NAME}_benchmark
${benchs_src}
)
target_include_directories(${PROJECT_NAME}_benchmark PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/benchs)
target_link_libraries(${PROJECT_NAME}_benchmark PRIVATE ${PROJECT_NAME}_objs userver-ubench)
add_google_benchmark_tests(${PROJECT_NAME}_benchmark)

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CMAKE_DEBUG_FLAGS ?= -DUSERVER_SANITIZE='addr ub'
CMAKE_RELEASE_FLAGS ?=
CMAKE_OS_FLAGS ?= -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 -DUSERVER_FEATURE_REDIS_HI_MALLOC=1
NPROCS ?= $(shell nproc)
CLANG_FORMAT ?= clang-format
CLANG_FORMAT ?= clang-format-11

# NOTE: use Makefile.local for customization
-include Makefile.local
Expand Down Expand Up @@ -99,6 +99,7 @@ check-git-status:

.PHONY: check-format-cpp
check-format-cpp:
@$(CLANG_FORMAT) --version
@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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Makefile contains typicaly useful targets for development:

Edit `Makefile.local` to change the default configuration and build options.

## Known issues

### Clangd doesn't working with project
Use `ln -s build_debug/compile_commands.json compile_commands.json`

## License

Expand Down
26 changes: 13 additions & 13 deletions benchs/hello_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include "../src/views/hello/view.hpp"
#include <benchmark/benchmark.h>

#include <cstdint> // for std::uint64_t
#include <iterator> // for std::size
#include <string_view>

#include <benchmark/benchmark.h>
#include <userver/engine/run_standalone.hpp>

#include "views/hello/view.hpp"

void HelloBenchmark(benchmark::State& state) {
userver::engine::RunStandalone([&] {
constexpr std::string_view kNames[] = {"userver", "is", "awesome", "!"};
std::uint64_t i = 0;
userver::engine::RunStandalone([&] {
constexpr std::string_view kNames[] = {"userver", "is", "awesome", "!"};
std::uint64_t i = 0;

for (auto _ : state) {
const auto name = kNames[i++ % std::size(kNames)];
auto result = service_template::SayHelloTo(
name, service_template::UserType::kKnown);
benchmark::DoNotOptimize(result);
}
});
for (auto _ : state) {
const auto name = kNames[i++ % std::size(kNames)];
auto result = service_template::SayHelloTo(
name, service_template::UserType::kKnown);
benchmark::DoNotOptimize(result);
}
});
}

BENCHMARK(HelloBenchmark);
43 changes: 43 additions & 0 deletions dependencies/ubuntu-22.04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake
libboost1.74-dev
libboost-program-options1.74-dev
libboost-filesystem1.74-dev
libboost-locale1.74-dev
libboost-regex1.74-dev
libboost-iostreams1.74-dev
libev-dev
zlib1g-dev
libcurl4-openssl-dev
libcrypto++-dev
libyaml-cpp-dev
libssl-dev
libfmt-dev
libcctz-dev
libhttp-parser-dev
libjemalloc-dev
libmongoc-dev
libbson-dev
libldap2-dev
libpq-dev
postgresql-server-dev-15
libkrb5-dev
libhiredis-dev
libgrpc-dev
libgrpc++-dev
libgrpc++1
protobuf-compiler-grpc
libprotoc-dev
python3-dev
python3-protobuf
python3-jinja2
python3-virtualenv
python3-voluptuous
libc-ares-dev
libspdlog-dev
libbenchmark-dev
libgmock-dev
libgtest-dev
ccache
git
postgresql-15
redis-server
Loading

0 comments on commit b7226dd

Please sign in to comment.