Skip to content

Commit

Permalink
With a script
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-- committed Nov 11, 2024
1 parent a8157ee commit b137db7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions scripts/generate-pg-include-guard.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit b137db7

Please sign in to comment.