forked from jconway/plr
-
Notifications
You must be signed in to change notification settings - Fork 27
/
build_script.sh
283 lines (242 loc) · 9.21 KB
/
build_script.sh
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
cd "$(dirname "$0")"
. ./init.sh
logok "BEGIN build_script.sh"
set -v -x -e
# set -e
# which R msys2 and cygwin
# /c/RINSTALL/bin/x64/R
# /usr/bin/R
loginfo "which R $(which R)"
# just needed for the "make"
#
# so perl can use better regular expressions
export PATH=$(echo $(cygpath "c:\\${betterperl}\perl\bin")):${PATH}
#
# also, so I need "pexports", that is needed when,
# I try to use "postresql source code from git" to build postgres
# ("pexports" is not needed when I use the "downloadable postgrsql" source code)
export PATH=${PATH}:$(echo $(cygpath "c:\\${betterperl}\c\bin"))
if [ "${pggithubbincacheextracted}" == "false" ] && [ ! "${pg}" == "none" ]
then
loginfo "BEGIN PostgreSQL EXTRACT XOR CONFIGURE+BUILD+INSTALL"
if [ ! -f "pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z" ]
then
loginfo "BEGIN PostgreSQL CONFIGURE"
cd ${pgsource}
if [ "${Configuration}" == "Release" ]
then
./configure --enable-depend --disable-rpath --without-icu --prefix=${pgroot}
fi
if [ "${Configuration}" == "Debug" ]
then
./configure --enable-depend --disable-rpath --without-icu --enable-debug --enable-cassert CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer" --prefix=${pgroot}
fi
loginfo "END PostgreSQL CONFIGURE"
loginfo "BEGIN PostgreSQL BUILD"
make
loginfo "END PostgreSQL BUILD"
loginfo "BEGIN PostgreSQL INSTALL"
make install
loginfo "END PostgreSQL INSTALL"
cd ${APPVEYOR_BUILD_FOLDER}
loginfo "END PostgreSQL BUILD + INSTALL"
else
loginfo "BEGIN 7z EXTRACTION"
cd ${pgroot}
7z l "${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z"
7z x "${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z"
ls -alrt ${pgroot}
cd ${APPVEYOR_BUILD_FOLDER}
loginfo "END 7z EXTRACTION"
fi
loginfo "END PostgreSQL EXTRACT XOR CONFIGURE+BUILD+INSTALL"
fi
# put this in all non-init.sh scripts - pgroot is empty, if using an msys2 binary
# but psql is already in the path
if [ -f "${pgroot}/bin/psql" ]
then
export PATH=${pgroot}/bin:${PATH}
fi
#
# cygwin # pgroot: /usr - is the general location of binaries (psql) and already in the PATH
#
# $ echo $(cygpath "C:\cygwin\bin")
# /usr/bin
#
# cygwin # initdb, postgres, and pg_ctl are here "/usr/sbin"
if [ -f "${pgroot}/sbin/postgres" ]
then
export PATH=${pgroot}/sbin:${PATH}
fi
# # Later I get this information from pgconfig variables PKGLIBDIR SHAREDIR.
# # Therefore, I do not need this variable "dirpostgresql" anymore.
#
# # helps determine where to extract the plr files . .
# #
# # Uses the "/postgresql" directory if the plr files are found in the
# # default cygwin-package-management shared install folders
# #
# if [ -d "${pgroot}/share/postgresql" ]
# then
# export dirpostgresql=/postgresql
# fi
# build from source
# psql: error: could not connect to server: FATAL: role "appveyor" does not exist
# psql: error: could not connect to server: FATAL: database "appveyor" does not exist
#
# # loginfo "BEGIN MY ENV VARIABLES"
# export
# # loginfo "END MY ENV VARIABLES"
#
loginfo "BEGIN verify that PLR will link to the correct PostgreSQL"
loginfo "which psql : $(which psql)"
loginfo "which pg_ctl: $(which pg_ctl)"
loginfo "which initdb: $(which initdb)"
loginfo "which postgres: $(which postgres)"
loginfo "which pg_config: $(which pg_config)"
logok "pg_config . . ."
pg_config
loginfo "END verify that PLR will link to the correct PostgreSQL"
#
# ls -alrt /usr/sbin
# ls -alrt ${pgroot}/sbin
# which postgres
#
# PostgreSQL on msys2 (maybe also cygwin?) does not use(read) PG* variables [always] [correctly] (strange!)
# so, e.g. in psql, I do not rely on environment variables
# build from source
# psql: error: could not connect to server: FATAL: role "appveyor" does not exist
# psql: error: could not connect to server: FATAL: database "appveyor" does not exist
#
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty initdb --pgdata="${PGDATA}" --auth=trust --encoding=utf8 --locale=C
else
initdb --pgdata="${PGDATA}" --auth=trust --encoding=utf8 --locale=C
fi
# Success. You can now start the database server using:
# C:/msys64/mingw64/bin/pg_ctl -D C:/msys64//home/appveyor/mingw64/postgresql/Data -l logfile start
# C:/msys64/mingw64/bin/pg_ctl -D ${PGDATA} -l logfile start
# first
pg_ctl -D ${PGDATA} -l logfile start
pg_ctl -D ${PGDATA} -l logfile stop
# do again
pg_ctl -D ${PGDATA} -l logfile start
pg_ctl -D ${PGDATA} -l logfile stop
# leave it up
pg_ctl -D ${PGDATA} -l logfile start
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty psql -d postgres -c 'SELECT version();'
else
psql -d postgres -c 'SELECT version();'
fi
pg_ctl -D ${PGDATA} -l logfile stop
#
# not yet tried/tested in cygwin
# # cygwin case
if [ "${githubcache}" == "true" ] && [ "${pggithubbincachefound}" == "false" ] && ([ -f "${pgroot}/bin/postgres" ] || [ -f "${pgroot}/sbin/postgres" ])
then
loginfo "BEGIN pg 7z CREATION"
cd ${pgroot}
ls -alrt
loginfo "pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z"
7z a -t7z -mmt24 -mx7 -r ${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z *
7z l ${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z
ls -alrt ${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z
export pg_7z_size=$(find "${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z" -printf "%s")
loginfo "pg_7z_size $pg_7z_size"
# 96m
if [ ${pg_7z_size} -gt 100663296 ]
then
rm -f ${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z
loginfo "${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z is TOO BIG so removed."
fi
#
if [ -f "${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z" ]
then
if [ "${compiler}" == "cygwin" ]
then
# workaround of an Appveyor-using-cygwin bug - command will automatically pre-prepend A DIRECTORY (strange!)
# e.g.
pushd ${APPVEYOR_BUILD_FOLDER}
#
# NOTE FTP Deploy will automatically PushArtifact, so I will not do that HERE.
#
# loginfo "appveyor PushArtifact pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z"
# appveyor PushArtifact pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z
popd
# bash if-then-else-fi # inside bodies can not be empty
# else
#
# NOTE FTP Deploy will automatically PushArtifact, so I will not do that HERE.
#
# loginfo "appveyor PushArtifact ${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z"
# appveyor PushArtifact ${APPVEYOR_BUILD_FOLDER}/pg-pg${pgversion}-${Platform}-${Configuration}-${compiler}.7z
fi
fi
#
cd ${APPVEYOR_BUILD_FOLDER}
loginfo "END pg 7z CREATION"
fi
# do again
pg_ctl -D ${PGDATA} -l logfile start
# -g3 because of the many macros
#
if [ "${Configuration}" = "Debug" ]
then
echo "" >> Makefile
echo "override CFLAGS += -ggdb -Og -g3 -fno-omit-frame-pointer" >> Makefile
echo "" >> Makefile
fi
loginfo "BEGIN plr BUILDING"
USE_PGXS=1 make
loginfo "END plr BUILDING"
loginfo "BEGIN plr INSTALLING"
USE_PGXS=1 make install
loginfo "END plr INSTALLING"
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty psql -d postgres -c 'CREATE EXTENSION plr;'
else
psql -d postgres -c 'CREATE EXTENSION plr;'
fi
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty psql -d postgres -c 'SELECT plr_version();'
else
psql -d postgres -c 'SELECT plr_version();'
fi
# R 4.2.+ (on Windows utf8) sanity check
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty psql -d postgres -c '\l template[01]'
else
psql -d postgres -c '\l template[01]'
fi
# How to escape single quotes within single quoted strings
# 2009 - MULTIPLE SOLUTIONS
# https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty psql -d postgres -c 'SELECT * FROM pg_available_extensions WHERE name = '\''plr'\'';'
else
psql -d postgres -c 'SELECT * FROM pg_available_extensions WHERE name = '\''plr'\'';'
fi
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty psql -d postgres -c 'SELECT r_version();'
else
psql -d postgres -c 'SELECT r_version();'
fi
if [ "${compiler}" == "msys2" ]
then
winpty -Xallow-non-tty psql -d postgres -c 'DROP EXTENSION plr;'
else
psql -d postgres -c 'DROP EXTENSION plr;'
fi
# must stop, else Appveyor job will hang.
pg_ctl -D ${PGDATA} -l logfile stop
set +v +x +e
# set +e
logok "BEGIN build_script.sh"