-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
231 lines (186 loc) · 8.74 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Makefile for PL/.NET
UNAME = $(shell uname)
PYTHON ?= python3
SED ?= sed
DBUSER ?= postgres
# General
# Get installed dotnet host host
DOTNET_VER = $(shell dotnet --info | grep 'Host' -A 3 | $(SED) -n 's/Version: \(.*\)/\1/p' | xargs)
PLDOTNET_ENGINE_DIR = -DPLDOTNET_ENGINE_DIR=$(PLDOTNET_ENGINE_ROOT)/PlDotNET
PLDOTNET_TEMPLATE_DIR = $(PLDOTNET_ENGINE_ROOT)/PlDotNET/Templates
# Linux support
ifeq ($(UNAME), Linux)
DOTNET_HOSTDIR ?= $(shell dpkg -L dotnet-apphost-pack-6.0 | grep hostfxr.h | head -1 | xargs dirname)
DOTNET_LIBDIR ?= $(shell dpkg -L dotnet-apphost-pack-6.0 | grep hostfxr.h | head -1 | xargs dirname)
DOTNET_HOSTLIB ?= -L$(DOTNET_LIBDIR) -lnethost -Wl,-rpath $(DOTNET_LIBDIR)
PLDOTNET_ENGINE_ROOT ?= /var/lib
PG_CONFIG = pg_config
PKG_LIBDIR = $(shell $(PG_CONFIG) --pkglibdir)
PG_INCDIR = $(shell $(PG_CONFIG) --includedir-server )
endif
# OSX support
ifeq ($(UNAME), Darwin)
SED=gsed
DBUSER=$(USER)
DOTNET_HOSTDIR ?= $(shell find /usr/local/share/dotnet -name hostfxr.h | head -1 | xargs dirname)
DOTNET_LIBDIR ?= $(shell find /usr/local/share/dotnet -name hostfxr.h | head -1 | xargs dirname)
DOTNET_HOSTLIB ?= -L$(DOTNET_LIBDIR) -Wl,-rpath,$(DOTNET_LIBDIR) -lglib-2.0 -lnethost
PLDOTNET_ENGINE_ROOT = $(HOME)/dev/pldotnet/tmp/dotnet_install
PG_CONFIG = $(HOME)/postgresql-15/bin/pg_config
PKG_LIBDIR = $(HOME)/postgresql-15/lib/
PG_INCDIR = $(HOME)/postgresql-15/include/server
endif
GLIB_INC := `pkg-config --cflags --libs glib-2.0`
ifeq ("$(shell echo $(USE_DOTNETBUILD) | tr A-Z a-z)", "true")
DEFINE_DOTNET_BUILD := -DUSE_DOTNETBUILD
else
BUILD_PLDOTNET_PROJECT := dotnet build $(PLDOTNET_ENGINE_ROOT)/PlDotNET -c Release
endif
PG_VER = $(shell pg_config --version | grep -Po '(?<=SQL )[0-9]+')
PG_10_OR_12PLUS = $(shell if [ ${PG_VER} -lt "12" ]; then echo '10'; else echo '12plus'; fi)
MODULE_big = pldotnet
EXTENSION = pldotnet
DATA = pldotnet--0.9.sql
OBJS = src/pldotnet_hostfxr.o src/pldotnet.o src/pldotnet_conversions.o src/pldotnet_main.o src/pldotnet_spi.o
PG_CPPFLAGS = -I$(DOTNET_HOSTDIR) -I$(PG_INCDIR) $(GLIB_INC) \
-Iinc -DLINUX $(DEFINE_DOTNET_BUILD) $(PLDOTNET_ENGINE_DIR) \
-DPKG_LIBDIR=$(PKG_LIBDIR)
PGXS = $(shell $(PG_CONFIG) --pgxs)
ifeq ($(UNAME), Darwin)
PG_CPPFLAGS = -isystem $(DOTNET_HOSTDIR) -isystem $(PG_INCDIR) $(GLIB_INC) \
-Iinc -DLINUX $(DEFINE_DOTNET_BUILD) $(PLDOTNET_ENGINE_DIR) \
-DPKG_LIBDIR=$(PKG_LIBDIR)
PGXS = $(HOME)/postgresql-15/lib/pgxs/src/makefiles/pgxs.mk
endif
SHLIB_LINK = $(DOTNET_HOSTLIB) $(GLIB_INC)
CURRENT_DIR = $(shell pwd)
include $(PGXS)
CP_CHOWN = cp -R dotnet_src $(PLDOTNET_ENGINE_ROOT)/PlDotNET
ifeq ($(UNAME), Linux)
CP_CHOWN += && chown -R postgres $(PLDOTNET_ENGINE_ROOT)/PlDotNET
endif
pldotnet-install: pldotnet-uninstall install
$(CP_CHOWN)
$(SED) -i 's/@PKG_LIBDIR/$(shell echo $(PKG_LIBDIR) | $(SED) 's/\//\\\//g')/' $(PLDOTNET_ENGINE_ROOT)/PlDotNET/*.cs
$(SED) -i 's/@PKG_LIBDIR/$(shell echo $(PKG_LIBDIR) | $(SED) 's/\//\\\//g')/' $(PLDOTNET_ENGINE_ROOT)/PlDotNET/Common/*.cs
$(SED) -i 's/@PKG_LIBDIR/$(shell echo $(PKG_LIBDIR) | $(SED) 's/\//\\\//g')/' $(PLDOTNET_ENGINE_ROOT)/PlDotNET/TypeHandlers/*.cs
$(SED) -i 's/@PKG_LIBDIR/$(shell echo $(PKG_LIBDIR) | $(SED) 's/\//\\\//g')/' $(PLDOTNET_ENGINE_ROOT)/PlDotNET/npgsql/src/Npgsql/PlDotNET/*.cs
$(SED) -i 's/@PLDOTNET_TEMPLATE_DIR/$(shell echo $(PLDOTNET_TEMPLATE_DIR) | $(SED) 's/\//\\\//g')/' $(PLDOTNET_ENGINE_ROOT)/PlDotNET/CodeGenerator.cs
$(SED) -i 's/@PLDOTNET_TEMPLATE_DIR/$(shell echo $(PLDOTNET_TEMPLATE_DIR) | $(SED) 's/\//\\\//g')/' $(PLDOTNET_ENGINE_ROOT)/PlDotNET/Engine.cs
$(BUILD_PLDOTNET_PROJECT)
pldotnet-uninstall: uninstall
rm -rf $(PLDOTNET_ENGINE_ROOT)/PlDotNET
pldotnet-build-debian-packages:
$(MAKE) documentation
rm -f debian/packages/postgresql-*-pldotnet_*.deb
pg_buildext updatecontrol
debuild -b -uc -us --lintian-opts --suppress-tags=initial-upload-closes-no-bugs,custom-library-search-path --profile debian
mkdir -p debian/packages
cp ../postgresql-*-pldotnet_*.deb debian/packages/
rm -rf ../postgresql-*-pldotnet_*.deb
cpplint:
cpplint --filter=-readability/casting,-build/include_subdir,-runtime/int,-runtime/printf,-build/header_guard src/*.c src/*.h
documentation:
doxygen docs/Doxyfile
clean-docker:
# These might fail if there are no containers and/or images
# first you remove the containers
-docker ps -a|grep -v CREATED|awk '{print $$1}'| xargs docker rm
# second, you remove the images
-docker images|grep -v CREATED|awk '{print $$3}'| xargs docker rmi
rm -rf postgres-data
pldotnet-ubuntu:
docker-compose run --rm pldotnet-ubuntu22 bash
pldotnet-postgres:
$(MAKE) clean
$(MAKE)
$(MAKE) pldotnet-install
sudo -u $(DBUSER) psql
build-package:
docker-compose up pldotnet-build | tee package-build-log.txt
build-package-bash:
$(MAKE) build-package
docker-compose run --rm pldotnet-build bash
build-package-arm:
docker-compose up pldotnet-build-arm | tee package-build-arm-log.txt
build-package-arm-bash:
$(MAKE) build-package-arm
docker-compose run --rm pldotnet-build-arm bash
pre-tests-script:
dotnet build $(CURRENT_DIR)/tests/csharp/DotNetTestProject -c Release
dotnet build $(CURRENT_DIR)/tests/fsharp/DotNetTestProject -c Release
mkdir -p automated_test_results
find automated_test_results -mindepth 1 -delete
echo 'DROP TABLE IF EXISTS automated_test_results;CREATE TABLE automated_test_results(ID SERIAL PRIMARY KEY, FEATURE TEXT, TEST_NAME TEXT, RESULT boolean);' | (sudo -u $(DBUSER) psql)
post-tests-script:
cd $(CURRENT_DIR)/tests/csharp/DotNetTestProject/ && rm -rf bin obj
cd $(CURRENT_DIR)/tests/fsharp/DotNetTestProject/ && rm -rf bin obj
cd $(CURRENT_DIR)/
echo 'SELECT FEATURE, TEST_NAME, RESULT from automated_test_results;' | (sudo -u $(DBUSER) psql 2>&1) | tee automated_test_results/automated_test_results.out
echo 'SELECT RESULT, COUNT(1) FROM automated_test_results GROUP BY RESULT;' | (sudo -u $(DBUSER) psql)
# xUnit test directory
XUNIT_TEST_DIR := $(CURRENT_DIR)/tests/xUnit
# Command to run xUnit tests
RUN_XUNIT_TESTS = cd $(XUNIT_TEST_DIR) && dotnet test
pldotnet-tests:
$(MAKE) pre-tests-script
$(RUN_XUNIT_TESTS)
csharp-tests:
$(MAKE) pre-tests-script
$(RUN_XUNIT_TESTS) --filter Language=CSharp
fsharp-tests:
$(MAKE) pre-tests-script
$(RUN_XUNIT_TESTS) --filter Language=FSharp
csharp-tests-cats:
for sqlfile in tests/csharp/*.sql; do \
echo "Running $$sqlfile"; \
cat $$sqlfile | (sudo -u postgres psql 2>&1) | tee automated_test_results/`basename $$sqlfile .sql`.out; \
done
fsharp-tests-cats:
for sqlfile in tests/fsharp/*.sql; do \
echo "Running $$sqlfile"; \
cat $$sqlfile | (sudo -u postgres psql 2>&1) | tee automated_test_results/`basename $$sqlfile .sql`.out; \
done
pldotnet-tests-sql:
$(MAKE) pre-tests-script
$(MAKE) csharp-tests-cats
$(MAKE) fsharp-tests-cats
$(MAKE) post-tests-script
csharp-tests-sql:
$(MAKE) pre-tests-script
$(MAKE) csharp-tests-cats
$(MAKE) post-tests-script
fsharp-tests-sql:
$(MAKE) pre-tests-script
$(MAKE) fsharp-tests-cats
$(MAKE) post-tests-script
stress-test:
mkdir -p automated_test_results
find automated_test_results -mindepth 1 -delete
echo 'DROP TABLE automated_test_results;CREATE TABLE automated_test_results(ID SERIAL PRIMARY KEY, FEATURE TEXT, TEST_NAME TEXT, RESULT boolean);' | (sudo -u $(DBUSER) psql)
sudo bash tests/stress_test/stress_test.sh
benchmark-tests:
mkdir -p automated_test_results
cat tests/benchmark/python/init-extension.sql | (sudo -u $(DBUSER) psql)
echo "ALTER DATABASE postgres SET pljava.libjvm_location TO '$$(sudo find /usr -name libjvm.so | head -n 1)';" | sudo -u $(DBUSER) psql
cat tests/benchmark/java/init-extension.sql | (sudo -u $(DBUSER) psql)
cat tests/benchmark/perl/init-extension.sql | (sudo -u $(DBUSER) psql)
cat tests/benchmark/lua/init-extension.sql | (sudo -u $(DBUSER) psql)
cat tests/benchmark/tcl/init-extension.sql | (sudo -u $(DBUSER) psql)
cat tests/benchmark/r/init-extension.sql | (sudo -u $(DBUSER) psql)
cat tests/benchmark/v8javascript/init-extension.sql | (sudo -u $(DBUSER) psql)
cd $(CURRENT_DIR)/tests/benchmark/java/test-suite && mvn install && cd $(CURRENT_DIR)/
echo "select sqlj.install_jar('file:$(CURRENT_DIR)/tests/benchmark/java/test-suite/target/test-suite-1.0.0.jar', 'testsuite', true);" | (sudo -u $(DBUSER) psql)
echo "select sqlj.set_classpath('public', 'testsuite');" | (sudo -u $(DBUSER) psql)
bash tests/benchmark/benchmark.sh
spi-tests:
$(MAKE) pre-tests-script
cat tests/csharp/testspi.sql | (sudo -u postgres psql 2>&1) | tee automated_test_results/testspi.out
cat tests/fsharp/testfsspi.sql | (sudo -u postgres psql 2>&1) | tee automated_test_results/testfsspi.out
$(MAKE) post-tests-script
npgsql-tests:
bash tests/npgsql/run_tests.sh
$(PYTHON) tests/npgsql/process_npgsql_results.py
npgsql-working-tests:
bash tests/npgsql/run_working_tests.sh
$(PYTHON) tests/npgsql/process_npgsql_results.py