diff --git a/Makefile b/Makefile index 165295fe..7b72d8e5 100644 --- a/Makefile +++ b/Makefile @@ -103,12 +103,7 @@ clean-all: clean clean-regression clean-duckdb $(CPP_ONLY_FILE): @rm -f $(CPP_ONLY_FILE) - @echo "// Auto-generated file, run 'make update_cpp_guard' to update" > $(CPP_ONLY_FILE) - @echo "#if \\" >> $(CPP_ONLY_FILE) - for m in $$(grep -R '_H$$' "$(INCLUDEDIR)" | grep define | cut -d \: -f 2 | cut -d \ -f 2 | sort); do echo "defined($$m) || \\"; done >> $(CPP_ONLY_FILE) - @echo "false" >> $(CPP_ONLY_FILE) - @echo "static_assert(false, \"No Postgres header should be included in this file.\");" >> $(CPP_ONLY_FILE) - @echo "#endif" >> $(CPP_ONLY_FILE) + ./scripts/generate-pg-include-guard.sh $(CPP_ONLY_FILE) $(INCLUDEDIR) lintcheck: clang-tidy $(SRCS) -- -I$(INCLUDEDIR) -I$(INCLUDEDIR_SERVER) -Iinclude $(CPPFLAGS) -std=c++17 diff --git a/scripts/generate-pg-include-guard.sh b/scripts/generate-pg-include-guard.sh new file mode 100755 index 00000000..0a75192b --- /dev/null +++ b/scripts/generate-pg-include-guard.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -euo pipefail + +CPP_ONLY_FILE=$1 +PG_INCLUDE_DIR=$2 + +OUTPUT_DIR=$(dirname "${CPP_ONLY_FILE}") + +mkdir -p "${OUTPUT_DIR}" + +echo "Will generate: $(pwd)/${CPP_ONLY_FILE}" + +echo "// Auto-generated file, run 'make update_cpp_guard' to update" > "${CPP_ONLY_FILE}" +echo "#if \\" >> "${CPP_ONLY_FILE}" + + +grep -R '_H$' "${PG_INCLUDE_DIR}" | grep define | cut -d: -f 2 | cut -d \ -f 2 | sort | while read -r m; +do + echo "defined($m) || \\"; +done >> "${CPP_ONLY_FILE}" + +echo "false" >> "${CPP_ONLY_FILE}" +echo "static_assert(false, \"No Postgres header should be included in this file.\");" >> "${CPP_ONLY_FILE}" +echo "#endif" >> "${CPP_ONLY_FILE}" + +NB_DEFINED=$(grep defined "${CPP_ONLY_FILE}" | wc -l) +echo "Used $NB_DEFINED macros in ${CPP_ONLY_FILE}"