-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
210 lines (161 loc) · 7.67 KB
/
Makefile
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
# contrib/spock/Makefile
MODULE_big = spock
EXTENSION = spock
PGFILEDESC = "spock - multi-master replication"
MODULES = spock_output
DATA = spock--3.3.sql spock--3.2--3.3.sql
OBJS = spock_apply.o spock_conflict.o spock_manager.o \
spock.o spock_node.o spock_relcache.o \
spock_repset.o spock_rpc.o spock_functions.o \
spock_queue.o spock_fe.o spock_worker.o \
spock_sync.o spock_sequences.o spock_executor.o \
spock_dependency.o spock_apply_heap.o spock_apply_spi.o \
spock_output_config.o spock_output_plugin.o \
spock_output_proto.o spock_proto_json.o \
spock_proto_native.o spock_monitoring.o spock_failover_slots.o \
spock_readonly.o spock_common.o
SCRIPTS_built = spock_create_subscriber
REGRESS = preseed infofuncs init_fail init preseed_check basic conflict_secondary_unique \
toasted replication_set matview bidirectional primary_key \
interfaces foreign_key copy sequence triggers parallel row_filter \
row_filter_sampling att_list column_filter apply_delay multiple_upstreams \
node_origin_cascade drop
# Disabled following tests:
# extended add_table functions
# The following test cases are disabled while developing.
#
# Ideally, we should run all test cases listed in $(REGRESS),
# but occassionaly it is helpful to disable one or more
# cases while developing.
REGRESS := $(filter-out apply_delay, $(REGRESS))
EXTRA_CLEAN += compat17/spock_compat.o compat17/spock_compat.bc \
compat16/spock_compat.o compat16/spock_compat.bc \
compat15/spock_compat.o compat15/spock_compat.bc \
compat14/spock_compat.o compat14/spock_compat.bc \
spock_create_subscriber.o
spock_version=$(shell awk '/\#define SPOCK_VERSION[ \t]+\".*\"/ { print substr($$3,2,length($$3)-2) }' $(realpath $(srcdir)/spock.h) )
# For regression checks
# this makes "make check" give a useful error
abs_top_builddir = .
NO_TEMP_INSTALL = yes
PG_CONFIG ?= pg_config
PGVER := $(shell $(PG_CONFIG) --version | sed 's/[^0-9]//g' | cut -c 1-2)
PG_CPPFLAGS += -I$(libpq_srcdir) -I$(realpath $(srcdir)/compat$(PGVER)) -Werror=implicit-function-declaration
ifdef NO_LOG_OLD_VALUE
PG_CPPFLAGS += -DNO_LOG_OLD_VALUE
endif
SHLIB_LINK += $(libpq) $(filter -lintl, $(LIBS))
OBJS += $(srcdir)/compat$(PGVER)/spock_compat.o
requires =
control_path = $(abspath $(srcdir))/spock.control
EXTRA_CLEAN += $(control_path)
PGXS = $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
# We can't do a normal 'make check' because PGXS doesn't support
# creating a temp install. We don't want to use a normal PGXS
# 'installcheck' though, because it's a pain to set up a temp install
# manually, with the config overrides needed.
#
# We compromise by using the install we're building against, installing
# glogical into it, then making a temp instance. This means that 'check'
# affects the target DB install. Nobody with any sense runs 'make check'
# under a user with write permissions to their production PostgreSQL
# install (right?)
# But this is still not ideal.
regresscheck:
$(MKDIR_P) regression_output
$(pg_regress_check) \
--temp-config ./regress-postgresql.conf \
--temp-instance=./tmp_check \
--outputdir=./regression_output \
--create-role=logical \
$(REGRESS)
check: install regresscheck
spock_create_subscriber: spock_create_subscriber.o spock_fe.o
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(libpq_pgport) $(filter-out -lreadline, $(LIBS)) -o $@$(X)
spock.control: spock.control.in spock.h
sed 's/__SPOCK_VERSION__/$(spock_version)/;s/__REQUIRES__/$(requires)/' $(realpath $(srcdir)/spock.control.in) > $(control_path)
all: spock.control
GITHASH=$(shell if [ -e .distgitrev ]; then cat .distgitrev; else git rev-parse --short HEAD; fi)
dist-common: clean
@if test "$(wanttag)" -eq 1 -a "`git name-rev --tags --name-only $(GITHASH)`" = "undefined"; then echo "cannot 'make dist' on untagged tree; tag it or use make git-dist"; exit 1; fi
@rm -f .distgitrev .distgittag
@if ! git diff-index --quiet HEAD; then echo >&2 "WARNING: git working tree has uncommitted changes to tracked files which were INCLUDED"; fi
@if [ -n "`git ls-files --exclude-standard --others`" ]; then echo >&2 "WARNING: git working tree has unstaged files which were IGNORED!"; fi
@echo $(GITHASH) > .distgitrev
@git name-rev --tags --name-only `cat .distgitrev` > .distgittag
@(git ls-tree -r -t --full-tree HEAD --name-only \
&& cd spock_dump\
&& git ls-tree -r -t --full-tree HEAD --name-only | sed 's/^/spock_dump\//'\
) |\
tar cjf "${distdir}.tar.bz2" --transform="s|^|${distdir}/|" --no-recursion \
-T - .distgitrev .distgittag
@echo >&2 "Prepared ${distdir}.tar.bz2 for rev=`cat .distgitrev`, tag=`cat .distgittag`"
@rm -f .distgitrev .distgittag
@md5sum "${distdir}.tar.bz2" > "${distdir}.tar.bz2.md5"
@if test -n "$(GPGSIGNKEYS)"; then gpg -q -a -b $(shell for x in $(GPGSIGNKEYS); do echo -u $$x; done) "${distdir}.tar.bz2"; else echo "No GPGSIGNKEYS passed, not signing tarball. Pass space separated keyid list as make var to sign."; fi
dist: distdir=spock-$(spock_version)
dist: wanttag=1
dist: dist-common
git-dist: distdir=spock-$(spock_version)_git$(GITHASH)
git-dist: wanttag=0
git-dist: dist-common
# runs TAP tests
# PGXS doesn't support TAP tests yet.
# Copy perl modules in postgresql_srcdir/src/test/perl
# to postgresql_installdir/lib/pgxs/src/test/perl
define prove_check
rm -rf $(CURDIR)/tmp_check/log
cd $(srcdir) && TESTDIR='$(CURDIR)' $(with_temp_install) PGPORT='6$(DEF_PGPORT)' PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' $(PROVE) --verbose $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(or $(PROVE_TESTS),t/*.pl)
endef
check_prove:
$(prove_check)
.PHONY: all check regresscheck spock.control
define _spk_create_recursive_target
.PHONY: $(1)-$(2)-recurse
$(1): $(1)-$(2)-recurse
$(1)-$(2)-recurse: $(if $(filter check, $(3)), temp-install)
$(MKDIR_P) $(2)
$$(MAKE) -C $(2) -f $(abspath $(srcdir))/$(2)/Makefile VPATH=$(abspath $(srcdir))/$(2) $(3)
endef
$(foreach target,$(if $1,$1,$(standard_targets)),$(foreach subdir,$(if $2,$2,$(SUBDIRS)),$(eval $(call _spk_create_recursive_target,$(target),$(subdir),$(if $3,$3,$(target))))))
define VALGRIND_WRAPPER
#!/bin/bash
set -e -u -x
# May also want --expensive-definedness-checks=yes
#
# Quicker runs without --track-origins=yes --read-var-info=yes
#
# If you don't want leak checking, use --leak-check=no
#
# When just doing leak checking and not looking for detailed memory error reports you don't need:
# --track-origins=yes --read-var-info=yes --malloc-fill=8f --free-fill=9f
#
SUPP=$(POSTGRES_SRC)/src/tools/valgrind.supp
# Pop top two elements from path; the first is added by pg_regress
# and the next is us.
function join_by { local IFS="$$1"; shift; echo "$$*"; }
IFS=':' read -r -a PATHA <<< "$$PATH"
export PATH=$$(join_by ":" "$${PATHA[@]:2}")
NEXT_POSTGRES=$$(which postgres)
if [ "$${NEXT_POSTGRES}" -ef "./valgrind/postgres" ]; then
echo "ERROR: attempt to execute self"
exit 1
fi
echo "Running $${NEXT_POSTGRES} under Valgrind"
valgrind --leak-check=full --show-leak-kinds=definite,possible,reachable --gen-suppressions=all \
--suppressions="$${SUPP}" --suppressions=`pwd`/spock.supp --verbose \
--time-stamp=yes --log-file=valgrind-$$$$-%p.log --trace-children=yes \
--track-origins=yes --read-var-info=yes --malloc-fill=8f --free-fill=9f \
--num-callers=30 \
postgres "$$@"
endef
export VALGRIND_WRAPPER
valgrind-check:
$(if $(POSTGRES_SRC),,$(error set Make variable POSTGRES_SRC to postgres source dir to find valgrind.supp))
$(if $(wildcard $(POSTGRES_SRC)/src/tools/valgrind.supp),,$(error missing valgrind suppressions at $(POSTGRES_SRC)/src/tools/valgrind.supp))
mkdir -p valgrind/
echo "$$VALGRIND_WRAPPER" > valgrind/postgres
chmod a+x valgrind/postgres
PATH=./valgrind/:$(PATH) $(MAKE) check
rm valgrind/postgres