From 2965f8e58209229ae104407cb369dd49f08b6103 Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sat, 28 Feb 2026 13:30:23 -0400 Subject: [PATCH] Add auto-generation notices for generated files This directs new devs to look for the source files instead of wasting time editing generated files. --- cmake/dbGenZod.cmake | 4 ++++ cmake/scripts/prepend_cppbessot_notice.cmake | 20 +++++++++++++++++++ .../cpp-odb-json/model-header.mustache | 5 +++++ .../cpp-odb-json/model-source.mustache | 5 +++++ 4 files changed, 34 insertions(+) create mode 100644 cmake/scripts/prepend_cppbessot_notice.cmake diff --git a/cmake/dbGenZod.cmake b/cmake/dbGenZod.cmake index 5194c3e..3bdc59a 100644 --- a/cmake/dbGenZod.cmake +++ b/cmake/dbGenZod.cmake @@ -16,6 +16,7 @@ function(cppbessot_add_db_gen_zod_target version) set(_openapi_file "${_version_dir}/openapi/openapi.yaml") set(_output_dir "${_version_dir}/generated-zod") set(_output_file "${_output_dir}/schemas.ts") + set(_prepend_notice_script "${CMAKE_CURRENT_LIST_DIR}/scripts/prepend_cppbessot_notice.cmake") add_custom_target(db_gen_zod COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_dir}" @@ -23,6 +24,9 @@ function(cppbessot_add_db_gen_zod_target version) "${_openapi_file}" --output "${_output_file}" --export-schemas + COMMAND ${CMAKE_COMMAND} + -DCPPBESSOT_TARGET_FILE="${_output_file}" + -P "${_prepend_notice_script}" COMMENT "Generating Zod schemas for ${version}" VERBATIM ) diff --git a/cmake/scripts/prepend_cppbessot_notice.cmake b/cmake/scripts/prepend_cppbessot_notice.cmake new file mode 100644 index 0000000..f880d4b --- /dev/null +++ b/cmake/scripts/prepend_cppbessot_notice.cmake @@ -0,0 +1,20 @@ +if(NOT DEFINED CPPBESSOT_TARGET_FILE OR "${CPPBESSOT_TARGET_FILE}" STREQUAL "") + message(FATAL_ERROR "CPPBESSOT_TARGET_FILE is required") +endif() + +# Some CMake command invocations can pass wrapped quotes through -D values. +set(_target_file "${CPPBESSOT_TARGET_FILE}") +string(REGEX REPLACE "^\"(.*)\"$" "\\1" _target_file "${_target_file}") + +if(NOT EXISTS "${_target_file}") + message(FATAL_ERROR "Target file does not exist: ${_target_file}") +endif() + +file(READ "${_target_file}" _content) + +if(_content MATCHES "AUTO-GENERATED BY CppBeSsot") + return() +endif() + +set(_notice "/*\n * AUTO-GENERATED BY CppBeSsot.\n * Direct edits are pointless: this file is regenerated.\n * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs.\n */\n\n") +file(WRITE "${_target_file}" "${_notice}${_content}") diff --git a/openapi/templates/cpp-odb-json/model-header.mustache b/openapi/templates/cpp-odb-json/model-header.mustache index b1ff9f0..3b30073 100644 --- a/openapi/templates/cpp-odb-json/model-header.mustache +++ b/openapi/templates/cpp-odb-json/model-header.mustache @@ -1,5 +1,10 @@ {{#models}} {{#model}} +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ #pragma once #include diff --git a/openapi/templates/cpp-odb-json/model-source.mustache b/openapi/templates/cpp-odb-json/model-source.mustache index c5df73e..7f88b19 100644 --- a/openapi/templates/cpp-odb-json/model-source.mustache +++ b/openapi/templates/cpp-odb-json/model-source.mustache @@ -1,5 +1,10 @@ {{#models}} {{#model}} +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ #include "{{packageName}}/model/{{classname}}.h" namespace models {