-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
212 lines (187 loc) · 7.72 KB
/
Makefile
File metadata and controls
212 lines (187 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
MODULE_big = sql_saga
EXTENSION = sql_saga
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
# The main extension script, built from the source files.
# It is listed in DATA so that `make install` will copy it.
DATA = $(EXTENSION)--$(EXTVERSION).sql
# Add the generated script to EXTRA_CLEAN so it's removed on `make clean`.
EXTRA_CLEAN = $(EXTENSION)--$(EXTVERSION).sql
DOCS = README.md
#README.html: README.md
# jq --slurp --raw-input '{"text": "\(.)", "mode": "markdown"}' < README.md | curl --data @- https://api.github.com/markdown > README.html
SQL_FILES = $(wildcard sql/[0-9][0-9][0-9]_*.sql)
REGRESS_ALL = $(patsubst sql/%.sql,%,$(SQL_FILES))
BENCHMARK_TESTS = $(foreach test,$(REGRESS_ALL),$(if $(findstring benchmark,$(test)),$(test)))
REGRESS_FAST_LIST = $(filter-out $(BENCHMARK_TESTS),$(REGRESS_ALL))
# By default, run all tests. If 'fast' or 'benchmark' are goals, run the respective subset.
REGRESS_TO_RUN = $(REGRESS_ALL)
ifeq (fast,$(filter fast,$(MAKECMDGOALS)))
REGRESS_TO_RUN = $(REGRESS_FAST_LIST)
endif
ifeq (benchmark,$(filter benchmark,$(MAKECMDGOALS)))
REGRESS_TO_RUN = $(BENCHMARK_TESTS)
endif
REGRESS = $(if $(TESTS),$(patsubst sql/%,%,$(TESTS)),$(REGRESS_TO_RUN))
override CONTRIB_TESTDB = sql_saga_regress
REGRESS_OPTS += --create-role=$(CONTRIB_TESTDB)
# Conditionally add pg_stat_monitor if it's available.
# We connect to template1 as it's guaranteed to exist.
# The `psql` command will return an empty string if the extension is not found or if psql fails,
# in which case the option will not be added.
PG_STAT_MONITOR_AVAILABLE = $(shell psql -d template1 --quiet -t -c "SELECT 1 FROM pg_available_extensions WHERE name = 'pg_stat_monitor'" 2>/dev/null | grep -q 1 && echo yes)
ifeq ($(PG_STAT_MONITOR_AVAILABLE),yes)
REGRESS_OPTS += --load-extension=pg_stat_monitor
endif
OBJS = src/sql_saga.o src/covers_without_gaps.o $(WIN32RES)
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
# Redefine the `all` target to build both the C library (SHLIB) and our
# generated SQL script. PGXS provides the rule to build SHLIB.
all: $(SHLIB) $(EXTENSION)--$(EXTVERSION).sql
# Add the generated SQL file as a direct dependency of the `install` target.
# This ensures it is always rebuilt if its source files have changed before
# tests are run.
install: $(EXTENSION)--$(EXTVERSION).sql
# Build the main extension script from component files.
# The source files use Na_ pattern (e.g., 0a_, 1b_, 2c_) to ensure correct concatenation order.
# This provides 26 positions per digit group instead of 10 with pure numeric prefixes.
$(EXTENSION)--$(EXTVERSION).sql: $(wildcard src/[0-9][a-z]_*.sql)
cat $^ > $@
# test is a convenient alias for installcheck.
# To run all tests: `make test`
# To run fast tests (excluding benchmarks): `make test fast`
# To run benchmark tests: `make test benchmark`
# To run a single test: `make test TESTS=001_install`
# To run a subset of tests: `make test TESTS="001_install 002_era"`
.PHONY: test setup_test_files
test: setup_test_files installcheck
# expected updates the .out files for the last run test suite.
# It parses regression.out to find which tests were run, or uses TESTS if provided.
# Usage: `make test [fast|benchmark|TESTS=...]; make expected`
# or: `make expected TESTS="test1 test2"`
.PHONY: expected
expected:
@if [ -n "$(TESTS)" ]; then \
TESTS_TO_UPDATE="$(TESTS)"; \
elif [ ! -f regression.out ]; then \
echo "All tests passed. Nothing to update."; \
exit 0; \
else \
TESTS_TO_UPDATE=$$(awk -F ' - ' '/^(not )?ok/ {print $$2}' regression.out | awk '{print $$1}'); \
fi; \
if [ -z "$$TESTS_TO_UPDATE" ]; then \
echo "No tests found in regression.out. Nothing to update."; \
exit 0; \
fi; \
for test in $$TESTS_TO_UPDATE; do \
if [ -f "results/$$test.out" ]; then \
echo "Updating expected output for: $$test"; \
cp "results/$$test.out" "expected/$$test.out"; \
else \
echo "Warning: result file for '$$test' not found. Skipping."; \
fi; \
done
# Create empty expected files for new tests if they don't exist.
setup_test_files:
@mkdir -p expected
@for test in $(REGRESS); do \
if [ ! -f expected/$$test.out ]; then \
mkdir -p `dirname "expected/$$test.out"`; \
touch "expected/$$test.out"; \
fi; \
done
# 'fast' and 'benchmark' are dummy targets. Their presence in the command line
# (e.g., `make test fast`) is used to trigger the conditional logic that
# selects the desired test suite.
.PHONY: fast benchmark
fast:
@:
benchmark:
@:
# Target to show diff for failing tests. Use with 'vim' for vimdiff.
# `make diff-fail-all`: shows all failures.
# `make diff-fail-first`: shows the first failure.
.PHONY: diff-fail-all diff-fail-first vim vimo nvim nvimo
diff-fail-all diff-fail-first:
@FAILED_TESTS=$$(grep 'not ok' regression.out 2>/dev/null | awk -F ' - ' '{print $$2}' | awk '{print $$1}'); \
if [ "$@" = "diff-fail-first" ]; then \
FAILED_TESTS=`echo "$$FAILED_TESTS" | head -n 1`; \
fi; \
if [ -n "$(filter vim vimo nvim nvimo,$(MAKECMDGOALS))" ]; then \
EDITOR_CMD="vim"; \
if [ -n "$(filter nvim nvimo,$(MAKECMDGOALS))" ]; then \
EDITOR_CMD="nvim"; \
fi; \
EDITOR_OPTS="-d"; \
if [ -n "$(filter vimo nvimo,$(MAKECMDGOALS))" ]; then \
EDITOR_OPTS="-d -o"; \
fi; \
VIM_CMD="$$EDITOR_CMD $$EDITOR_OPTS"; \
for test in $$FAILED_TESTS; do \
if [ "$@" = "diff-fail-all" ]; then \
echo "Next test: $$test"; \
echo "Press C to continue, s to skip, or b to break (default: C)"; \
read -n 1 -s input < /dev/tty; \
if [ "$$input" = "b" ]; then \
break; \
elif [ "$$input" = "s" ]; then \
continue; \
fi; \
fi; \
echo "Running $$VIM_CMD for test: $$test"; \
$$VIM_CMD "expected/$$test.out" "results/$$test.out" < /dev/tty; \
done; \
else \
for test in $$FAILED_TESTS; do \
echo "Showing diff for test: $$test"; \
diff -u "expected/$$test.out" "results/$$test.out" || true; \
done; \
fi; \
if [ -n "$$FAILED_TESTS" ]; then exit 1; fi
vim vimo nvim nvimo:
@:
# Renumber test files to make room for a new test at a specific slot.
# Usage: make renumber-tests-from SLOT=066
# This shifts 066->067, 067->068, etc. in both sql/ and expected/ directories.
# After running, create your new 066_*.sql file.
.PHONY: renumber-tests-from
renumber-tests-from:
@if [ -z "$(SLOT)" ]; then \
echo "Usage: make renumber-tests-from SLOT=066"; \
exit 1; \
fi; \
echo "Renumbering tests from $(SLOT) onwards..."; \
for num in $$(seq 99 -1 $(SLOT)); do \
padded=$$(printf "%03d" $$num); \
next=$$(printf "%03d" $$((num + 1))); \
for dir in sql expected; do \
for f in $$dir/$${padded}_*; do \
[ -e "$$f" ] || continue; \
newname=$$(echo "$$f" | sed "s/$${padded}_/$${next}_/"); \
echo "git mv $$f $$newname"; \
git mv "$$f" "$$newname"; \
done; \
done; \
done; \
echo "Done. Slot $(SLOT) is now available."
# Generate compile_commands.json for LSP (clangd) support.
# Usage: make compile_commands.json
compile_commands.json:
@echo '[' > $@
@echo ' {' >> $@
@echo ' "directory": "$(CURDIR)",' >> $@
@echo ' "command": "gcc -I$(shell $(PG_CONFIG) --includedir-server) -I$(shell $(PG_CONFIG) --includedir) -c src/sql_saga.c",' >> $@
@echo ' "file": "src/sql_saga.c"' >> $@
@echo ' },' >> $@
@echo ' {' >> $@
@echo ' "directory": "$(CURDIR)",' >> $@
@echo ' "command": "gcc -I$(shell $(PG_CONFIG) --includedir-server) -I$(shell $(PG_CONFIG) --includedir) -c src/covers_without_gaps.c",' >> $@
@echo ' "file": "src/covers_without_gaps.c"' >> $@
@echo ' }' >> $@
@echo ']' >> $@
@echo "Generated $@ for PostgreSQL at $(shell $(PG_CONFIG) --bindir)"
#release:
# git archive --format zip --prefix=$(EXTENSION)-$(EXTENSION_VERSION)/ --output $(EXTENSION)-$(EXTENSION_VERSION).zip master
#
#.PHONY: release