mirror of
https://github.com/getml/sqlgen.git
synced 2026-05-12 10:58:36 -05:00
Added checks to make sure that the headers are self-contained (#84)
This commit is contained in:
committed by
GitHub
parent
86ee6e2bcc
commit
c4305f6a17
@@ -112,7 +112,7 @@ jobs:
|
||||
sudo ln -s $(which ccache) /usr/local/bin/$CC
|
||||
sudo ln -s $(which ccache) /usr/local/bin/$CXX
|
||||
$CXX --version
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_CHECK_HEADERS=ON
|
||||
cmake --build build
|
||||
- name: Compile
|
||||
if: matrix.db == 'mysql'
|
||||
@@ -127,7 +127,7 @@ jobs:
|
||||
sudo ln -s $(which ccache) /usr/local/bin/$CC
|
||||
sudo ln -s $(which ccache) /usr/local/bin/$CXX
|
||||
$CXX --version
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_MYSQL=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_SQLITE3=OFF -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=x64-linux-dynamic
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_MYSQL=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_SQLITE3=OFF -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=x64-linux-dynamic
|
||||
cmake --build build
|
||||
- name: Set up postgres
|
||||
if: matrix.db == 'postgres'
|
||||
|
||||
@@ -73,7 +73,7 @@ jobs:
|
||||
export CMAKE_GENERATOR=Ninja
|
||||
fi
|
||||
$CXX --version
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF
|
||||
cmake --build build -j 4
|
||||
- name: Compile
|
||||
if: matrix.db == 'mysql'
|
||||
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Compile
|
||||
if: matrix.db == 'sqlite'
|
||||
run: |
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF
|
||||
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_CHECK_HEADERS=ON
|
||||
cmake --build build --config Release -j4
|
||||
- name: Compile
|
||||
if: matrix.db == 'mysql'
|
||||
|
||||
+39
-7
@@ -12,12 +12,13 @@ option(SQLGEN_BUILD_TESTS "Build tests" OFF)
|
||||
|
||||
option(SQLGEN_BUILD_DRY_TESTS_ONLY "Build 'dry' tests only (those that do not require a database connection)" OFF)
|
||||
|
||||
option(SQLGEN_CHECK_HEADERS "Make sure that all headers are self-contained" OFF)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
if (NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
endif()
|
||||
|
||||
|
||||
set(SQLGEN_USE_VCPKG_DEFAULT ON)
|
||||
|
||||
option(SQLGEN_USE_VCPKG "Use VCPKG to download and build dependencies" ${SQLGEN_USE_VCPKG_DEFAULT})
|
||||
@@ -27,15 +28,15 @@ if (SQLGEN_USE_VCPKG)
|
||||
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
|
||||
endif()
|
||||
|
||||
if (SQLGEN_MYSQL)
|
||||
if (SQLGEN_MYSQL OR SQLGEN_CHECK_HEADERS)
|
||||
list(APPEND VCPKG_MANIFEST_FEATURES "mysql")
|
||||
endif()
|
||||
|
||||
if (SQLGEN_POSTGRES)
|
||||
if (SQLGEN_POSTGRES OR SQLGEN_CHECK_HEADERS)
|
||||
list(APPEND VCPKG_MANIFEST_FEATURES "postgres")
|
||||
endif()
|
||||
|
||||
if (SQLGEN_SQLITE3)
|
||||
if (SQLGEN_SQLITE3 OR SQLGEN_CHECK_HEADERS)
|
||||
list(APPEND VCPKG_MANIFEST_FEATURES "sqlite3")
|
||||
endif()
|
||||
|
||||
@@ -66,7 +67,7 @@ target_include_directories(
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
if(SQLGEN_MYSQL)
|
||||
if(SQLGEN_MYSQL OR SQLGEN_CHECK_HEADERS)
|
||||
list(APPEND SQLGEN_SOURCES src/sqlgen_mysql.cpp)
|
||||
if (SQLGEN_USE_VCPKG)
|
||||
if (NOT TARGET unofficial-libmariadb)
|
||||
@@ -81,7 +82,7 @@ if(SQLGEN_MYSQL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SQLGEN_POSTGRES)
|
||||
if (SQLGEN_POSTGRES OR SQLGEN_CHECK_HEADERS)
|
||||
list(APPEND SQLGEN_SOURCES src/sqlgen_postgres.cpp)
|
||||
if (NOT TARGET PostgreSQL)
|
||||
find_package(PostgreSQL REQUIRED)
|
||||
@@ -89,7 +90,7 @@ if (SQLGEN_POSTGRES)
|
||||
target_link_libraries(sqlgen PUBLIC PostgreSQL::PostgreSQL)
|
||||
endif()
|
||||
|
||||
if (SQLGEN_SQLITE3)
|
||||
if (SQLGEN_SQLITE3 OR SQLGEN_CHECK_HEADERS)
|
||||
list(APPEND SQLGEN_SOURCES src/sqlgen_sqlite.cpp)
|
||||
|
||||
if (SQLGEN_USE_VCPKG)
|
||||
@@ -119,6 +120,37 @@ if (SQLGEN_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif ()
|
||||
|
||||
if(SQLGEN_CHECK_HEADERS)
|
||||
file(GLOB_RECURSE PROJECT_HEADERS "include/*.hpp")
|
||||
find_package(reflectcpp CONFIG REQUIRED)
|
||||
|
||||
set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/self_contained_tests")
|
||||
file(MAKE_DIRECTORY "${TEST_DIR}")
|
||||
|
||||
foreach(HEADER_FILE ${PROJECT_HEADERS})
|
||||
string(MAKE_C_IDENTIFIER ${HEADER_FILE} HEADER_NAME)
|
||||
set(TEST_SOURCE_FILE "${TEST_DIR}/test_${HEADER_NAME}.cpp")
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT ${TEST_SOURCE_FILE}
|
||||
CONTENT "#include \"${HEADER_FILE}\"\n"
|
||||
)
|
||||
|
||||
add_library(check_header_${HEADER_NAME} "${TEST_SOURCE_FILE}")
|
||||
|
||||
target_include_directories(check_header_${HEADER_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${ADDITIONAL_INCLUDE_DIRS}
|
||||
)
|
||||
target_link_libraries(check_header_${HEADER_NAME} PUBLIC reflectcpp::reflectcpp)
|
||||
target_link_libraries(check_header_${HEADER_NAME} PUBLIC unofficial::libmariadb)
|
||||
target_link_libraries(check_header_${HEADER_NAME} PUBLIC PostgreSQL::PostgreSQL)
|
||||
target_link_libraries(check_header_${HEADER_NAME} PUBLIC unofficial::sqlite3::sqlite3)
|
||||
|
||||
add_custom_target(check_${HEADER_NAME} ALL DEPENDS check_header_${HEADER_NAME})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (PROJECT_IS_TOP_LEVEL)
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef SQLGEN_DYNAMIC_SELECT_HPP_
|
||||
#define SQLGEN_DYNAMIC_SELECT_HPP_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Column.hpp"
|
||||
#include "SelectFrom.hpp"
|
||||
#include "Table.hpp"
|
||||
|
||||
namespace sqlgen::dynamic {
|
||||
|
||||
SelectFrom select(const std::string& _table,
|
||||
const std::vector<std::string>& _columns) {
|
||||
std::vector<Column> columns;
|
||||
for (const auto& name : _columns) {
|
||||
columns.emplace_back(Column{.name = name});
|
||||
}
|
||||
return SelectFrom{
|
||||
.table =
|
||||
Table{.alias = std::nullopt, .name = _table, .schema = std::nullopt},
|
||||
.columns = columns};
|
||||
}
|
||||
|
||||
SelectFrom select(const std::string& _schema, const std::string& _table,
|
||||
const std::vector<std::string>& _columns) {
|
||||
std::vector<Column> columns;
|
||||
for (const auto& name : _columns) {
|
||||
columns.emplace_back(Column{.name = name});
|
||||
}
|
||||
return SelectFrom{
|
||||
.table = Table{.alias = std::nullopt, .name = _table, .schema = _schema},
|
||||
.columns = columns};
|
||||
}
|
||||
} // namespace sqlgen::dynamic
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SQLGEN_INTERNAL_COLLECT_VECTOR_HPP_
|
||||
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
namespace sqlgen::internal::collect {
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../dynamic/Type.hpp"
|
||||
#include "../dynamic/types.hpp"
|
||||
#include "Parser_base.hpp"
|
||||
#include "Parser_default.hpp"
|
||||
|
||||
namespace sqlgen::parsing {
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../dynamic/Type.hpp"
|
||||
#include "../dynamic/types.hpp"
|
||||
#include "Parser_base.hpp"
|
||||
#include "Parser_default.hpp"
|
||||
|
||||
namespace sqlgen::parsing {
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "Ref.hpp"
|
||||
#include "Result.hpp"
|
||||
#include "Transaction.hpp"
|
||||
#include "is_connection.hpp"
|
||||
|
||||
namespace sqlgen {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "../Literal.hpp"
|
||||
#include "../Result.hpp"
|
||||
#include "../dynamic/JoinType.hpp"
|
||||
#include "TableWrapper.hpp"
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <rfl.hpp>
|
||||
|
||||
#include "has_reflection_method.hpp"
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../dynamic/Insert.hpp"
|
||||
#include "../dynamic/Table.hpp"
|
||||
#include "../internal/collect/vector.hpp"
|
||||
#include "../internal/remove_auto_incr_primary_t.hpp"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Result.hpp"
|
||||
#include "is_connection.hpp"
|
||||
#include "transpilation/to_update.hpp"
|
||||
#include "where.hpp"
|
||||
|
||||
namespace sqlgen {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user