Skip to content

Commit

Permalink
CI tidy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bgs99 committed May 11, 2024
1 parent 9e863d5 commit 65f5174
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 19 deletions.
5 changes: 2 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ BasedOnStyle: LLVM

IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<pfr-orm/'
- Regex: "^<pfr-orm/"
CaseSensitive: true
Priority: 1
- Regex: '^<(fmt/|boost/|libpq-fe.h>)'
- Regex: "^<(fmt/|boost/|libpq-fe\\.h>)"
CaseSensitive: true
Priority: 3
- Priority: 2


ForEachMacros: []
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ Checks:
- concurrency-*
- cert-*
- bugprone-*
- -misc-include-cleaner # not reliable
- -llvm-header-guard # #pragma once
- -llvm-include-order # managed by clang-format
- -modernize-use-trailing-return-type # TODO
- -misc-no-recursion # simplifies code

CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ jobs:
- name: Check formatting
run: python ${{ github.workspace }}/scripts/check_format.py --clang-format=clang-format-18

check-tidy:
runs-on: ubuntu-22.04
env:
build_dir: ${{ github.workspace }}/build
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Add LLVM apt key
run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/llvm-toolchain-focal-18.asc

- name: Add LLVM repo
run: sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-18 main'

- name: Install dependencies
run: sudo apt-get install libfmt-dev libpq-dev clang-tidy-18

- name: Configure CMake
run: cmake -B ${{ env.build_dir }} -S ${{ github.workspace }}

- name: Run clang-tidy
run: python ${{ github.workspace }}/scripts/tidy.py --clang-tidy=run-clang-tidy-18 --compile-commands=${{ env.build_dir }}

test:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
3 changes: 2 additions & 1 deletion include/pfr-orm/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string_view>

#include <boost/pfr.hpp>
#include <boost/pfr/config.hpp>

static_assert(BOOST_PFR_ENABLED, "Boost.PFR is not supported, cannot build");
static_assert(BOOST_PFR_CORE_NAME_ENABLED,
Expand All @@ -18,7 +19,7 @@ static_assert(BOOST_PFR_CORE_NAME_ENABLED,
namespace pfrorm {

/// Identifier mode
enum class IdMode {
enum class IdMode : std::uint8_t {
Auto, ///< Automatically generated by database
Manual, ///< Provided when persisting
};
Expand Down
1 change: 1 addition & 0 deletions include/pfr-orm/definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <pfr-orm/detail/span.hpp>
#include <pfr-orm/detail/type_name.hpp>

#include <array>
#include <cstddef>
#include <string>
#include <string_view>
Expand Down
3 changes: 3 additions & 0 deletions include/pfr-orm/detail/field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include <pfr-orm/detail/pfr.hpp>

#include <algorithm>
#include <array>
#include <cstddef>
#include <stdexcept>
#include <string>
#include <string_view>

#include <boost/pfr/core_name.hpp>
Expand Down
3 changes: 0 additions & 3 deletions include/pfr-orm/postges-helpers.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#pragma once

#include <arpa/inet.h>
#include <cstdint>
#include <memory>
#include <postgres_ext.h>
#include <stdexcept>
#include <string>
#include <string_view>

#include <fmt/core.h>
#include <fmt/format.h>
#include <libpq-fe.h>

namespace pfrorm::postgres {
Expand Down
9 changes: 4 additions & 5 deletions lib/detail/operations.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <pfr-orm/api.hpp>
#include <pfr-orm/definitions.hpp>
#include <pfr-orm/postges-helpers.hpp>

#include "multilambda.hpp"
#include "pfr-orm/api.hpp"
#include "pfr-orm/definitions.hpp"
#include "pfr-orm/postges-helpers.hpp"
#include <cstddef>
#include <string_view>
#include <type_traits>
Expand All @@ -25,7 +26,6 @@ std::string_view toString(const NativeType type) {
}
}

// NOLINTNEXTLINE(misc-no-recursion): by design
void createTableFields(const FieldDescription &description,
const bool isPrimaryKey, PGconn &connection,
fmt::appender &appender,
Expand All @@ -44,7 +44,6 @@ void createTableFields(const FieldDescription &description,
};

const auto createCompositeField =
// NOLINTNEXTLINE(misc-no-recursion): by design
[&prefixes, &connection, &appender,
&first](const CompositeFieldDescription &descr) {
for (const FieldDescription &field : descr.fields) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

if __name__ == '__main__':
parser = argparse.ArgumentParser(add_help=True)
parser.add_argument('--clang-format',
help='clang-format executable to use',
parser.add_argument('--clang-tidy',
help='clang-tidy executable to use',
type=str,
default='clang-format')
default='run-clang-tidy')
parser.add_argument('--compile-commands',
help='Path to the directory with compile commands',
type=Path,
default='build')

args = parser.parse_args()

subprocess.run(['run-clang-tidy', '-quiet', '-p', args.compile_commands.as_posix(),
subprocess.run([args.clang_tidy, '-quiet', '-p', args.compile_commands.as_posix(),
*[file.as_posix() for file in cpp_files()]])
7 changes: 4 additions & 3 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <pfr-orm/api.hpp>
#include <pfr-orm/definitions.hpp>
#include <pfr-orm/operations.hpp>
#include <pfr-orm/postges-helpers.hpp>

Expand Down Expand Up @@ -36,18 +37,18 @@ int main(int argc, char **argv) {
const std::span<char *> args{argv, static_cast<std::size_t>(argc)};

try {
pg_orm::Connection conn = pg_orm::connect(args.at(1));
pg_orm::Connection conn = pg_orm::connect(args[1]);

pg_orm::createTable<Person>(*conn);

assert(!pg_orm::exists<Person>(*conn));

return 0;
} catch (const std::exception &ex) {
fmt::println("{}", ex.what());
fmt::print("{}\n", ex.what());
return 1;
} catch (...) {
fmt::println("Unknown exception");
fmt::print("Unknown exception\n");
return 1;
}
}

0 comments on commit 65f5174

Please sign in to comment.