From 9487dd477808e206e3107d3d66e26b054562669b Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Fri, 5 Jun 2026 13:26:33 -0400 Subject: [PATCH] Something from adversarial review --- cmake/dbGenZod.cmake | 2 +- .../scripts/cppbessotOdbHeaderDiscovery.cmake | 20 +++++++++++++++++++ cmake/scripts/run_odb_logic.cmake | 8 +++----- cmake/scripts/run_odb_migrations.cmake | 18 ++--------------- cmake/scripts/run_odb_sql_ddl.cmake | 8 +++----- 5 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 cmake/scripts/cppbessotOdbHeaderDiscovery.cmake diff --git a/cmake/dbGenZod.cmake b/cmake/dbGenZod.cmake index 179ada9..ac566fc 100644 --- a/cmake/dbGenZod.cmake +++ b/cmake/dbGenZod.cmake @@ -20,7 +20,7 @@ function(cppbessot_add_db_gen_zod_target schema_dir) add_custom_target(db_gen_zod COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_dir}" - COMMAND "${CPPBESSOT_NPX_EXECUTABLE}" --no-install openapi-zod-client + COMMAND "${CPPBESSOT_NPX_EXECUTABLE}" --yes openapi-zod-client "${_openapi_file}" --output "${_output_file}" --export-schemas diff --git a/cmake/scripts/cppbessotOdbHeaderDiscovery.cmake b/cmake/scripts/cppbessotOdbHeaderDiscovery.cmake new file mode 100644 index 0000000..cf14c0c --- /dev/null +++ b/cmake/scripts/cppbessotOdbHeaderDiscovery.cmake @@ -0,0 +1,20 @@ +function(cppbessot_odb_find_object_headers out_var include_dir) + file(GLOB _headers "${include_dir}/*/model/*.h") + if(NOT _headers) + message(FATAL_ERROR "No model headers found under ${include_dir}") + endif() + + set(_object_headers "") + foreach(_header IN LISTS _headers) + file(READ "${_header}" _header_contents) + if(_header_contents MATCHES "#pragma db object") + list(APPEND _object_headers "${_header}") + endif() + endforeach() + + if(NOT _object_headers) + message(FATAL_ERROR "No ODB object headers found under ${include_dir}") + endif() + + set(${out_var} "${_object_headers}" PARENT_SCOPE) +endfunction() diff --git a/cmake/scripts/run_odb_logic.cmake b/cmake/scripts/run_odb_logic.cmake index b117493..5378fb6 100644 --- a/cmake/scripts/run_odb_logic.cmake +++ b/cmake/scripts/run_odb_logic.cmake @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.16) +include("${CMAKE_CURRENT_LIST_DIR}/cppbessotOdbHeaderDiscovery.cmake") if(NOT DEFINED CPPBESSOT_ODB_EXECUTABLE OR CPPBESSOT_ODB_EXECUTABLE STREQUAL "") message(FATAL_ERROR "CPPBESSOT_ODB_EXECUTABLE is required") @@ -8,10 +9,7 @@ if(NOT DEFINED CPPBESSOT_VERSION_DIR OR CPPBESSOT_VERSION_DIR STREQUAL "") endif() set(_include_dir "${CPPBESSOT_VERSION_DIR}/generated-cpp-source/include") -file(GLOB _headers "${_include_dir}/*/model/*.h") -if(NOT _headers) - message(FATAL_ERROR "No model headers found under ${_include_dir}") -endif() +cppbessot_odb_find_object_headers(_object_headers "${_include_dir}") foreach(_backend IN ITEMS sqlite pgsql) if(_backend STREQUAL "sqlite") @@ -25,7 +23,7 @@ foreach(_backend IN ITEMS sqlite pgsql) execute_process( COMMAND "${CPPBESSOT_ODB_EXECUTABLE}" -I "${_include_dir}" --std c++11 -d "${_backend}" -q - -o "${_out_dir}" --changelog-dir "${_out_dir}" ${_headers} + -o "${_out_dir}" --changelog-dir "${_out_dir}" ${_object_headers} RESULT_VARIABLE _result OUTPUT_VARIABLE _stdout ERROR_VARIABLE _stderr diff --git a/cmake/scripts/run_odb_migrations.cmake b/cmake/scripts/run_odb_migrations.cmake index a496664..7e22a15 100644 --- a/cmake/scripts/run_odb_migrations.cmake +++ b/cmake/scripts/run_odb_migrations.cmake @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.16) +include("${CMAKE_CURRENT_LIST_DIR}/cppbessotOdbHeaderDiscovery.cmake") if(NOT DEFINED CPPBESSOT_ODB_EXECUTABLE OR CPPBESSOT_ODB_EXECUTABLE STREQUAL "") message(FATAL_ERROR "CPPBESSOT_ODB_EXECUTABLE is required") @@ -89,22 +90,7 @@ endfunction() cppbessot_migration_resolve_backends(_migration_backends) set(_to_include_dir "${CPPBESSOT_TO_VERSION_DIR}/generated-cpp-source/include") -file(GLOB _to_headers "${_to_include_dir}/*/model/*.h") -if(NOT _to_headers) - message(FATAL_ERROR "No target-version headers found under ${_to_include_dir}") -endif() - -set(_object_headers "") -foreach(_header IN LISTS _to_headers) - file(READ "${_header}" _header_contents) - if(_header_contents MATCHES "#pragma db object") - list(APPEND _object_headers "${_header}") - endif() -endforeach() - -if(NOT _object_headers) - message(FATAL_ERROR "No ODB object headers found under ${_to_include_dir}") -endif() +cppbessot_odb_find_object_headers(_object_headers "${_to_include_dir}") set(_empty_changelog_dir "${CPPBESSOT_MIGRATION_DIR}/.empty-baseline") file(MAKE_DIRECTORY "${_empty_changelog_dir}") diff --git a/cmake/scripts/run_odb_sql_ddl.cmake b/cmake/scripts/run_odb_sql_ddl.cmake index b68ea94..d4b75d5 100644 --- a/cmake/scripts/run_odb_sql_ddl.cmake +++ b/cmake/scripts/run_odb_sql_ddl.cmake @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.16) +include("${CMAKE_CURRENT_LIST_DIR}/cppbessotOdbHeaderDiscovery.cmake") if(NOT DEFINED CPPBESSOT_ODB_EXECUTABLE OR CPPBESSOT_ODB_EXECUTABLE STREQUAL "") message(FATAL_ERROR "CPPBESSOT_ODB_EXECUTABLE is required") @@ -8,10 +9,7 @@ if(NOT DEFINED CPPBESSOT_VERSION_DIR OR CPPBESSOT_VERSION_DIR STREQUAL "") endif() set(_include_dir "${CPPBESSOT_VERSION_DIR}/generated-cpp-source/include") -file(GLOB _headers "${_include_dir}/*/model/*.h") -if(NOT _headers) - message(FATAL_ERROR "No model headers found under ${_include_dir}") -endif() +cppbessot_odb_find_object_headers(_object_headers "${_include_dir}") foreach(_backend IN ITEMS sqlite pgsql) if(_backend STREQUAL "sqlite") @@ -28,7 +26,7 @@ foreach(_backend IN ITEMS sqlite pgsql) execute_process( COMMAND "${CPPBESSOT_ODB_EXECUTABLE}" -I "${_include_dir}" --std c++11 -d "${_backend}" --generate-schema --schema-format sql -q - -o "${_ddl_dir}" --changelog-dir "${_changelog_dir}" ${_headers} + -o "${_ddl_dir}" --changelog-dir "${_changelog_dir}" ${_object_headers} RESULT_VARIABLE _result OUTPUT_VARIABLE _stdout ERROR_VARIABLE _stderr