-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
container-build.sh
293 lines (214 loc) · 6.2 KB
/
container-build.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
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# This file is part of the xPack distribution.
# (https://xpack.github.io)
# Copyright (c) 2020 Liviu Ionescu.
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose is hereby granted, under the terms of the MIT license.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
if [[ ! -z ${DEBUG} ]]
then
set ${DEBUG} # Activate the expand mode if DEBUG is anything but empty.
else
DEBUG=""
fi
set -o errexit # Exit if command failed.
set -o pipefail # Exit if pipe failed.
set -o nounset # Exit if variable not set.
# Remove the initial space and instead use '\n'.
IFS=$'\n\t'
# -----------------------------------------------------------------------------
# Identify the script location, to reach, for example, the helper scripts.
build_script_path="$0"
if [[ "${build_script_path}" != /* ]]
then
# Make relative path absolute.
build_script_path="$(pwd)/$0"
fi
script_folder_path="$(dirname "${build_script_path}")"
script_folder_name="$(basename "${script_folder_path}")"
# =============================================================================
scripts_folder_path="$(dirname $(dirname "${script_folder_path}"))/scripts"
helper_folder_path="${scripts_folder_path}/helper"
tests_folder_path="$(dirname "${scripts_folder_path}")/tests"
# -----------------------------------------------------------------------------
# Inner script to run inside Docker containers to build the
# xPack distribution packages.
# For native builds, it runs on the host (macOS build cases,
# and development builds for GNU/Linux).
# -----------------------------------------------------------------------------
source "${scripts_folder_path}/defs-source.sh"
# This file is generated by the host build script.
source "${scripts_folder_path}/host-defs-source.sh"
# Helper functions.
source "${helper_folder_path}/common-functions-source.sh"
source "${helper_folder_path}/container-functions-source.sh"
source "${helper_folder_path}/common-libs-functions-source.sh"
source "${helper_folder_path}/common-apps-functions-source.sh"
# The order is important, it may override helper defs.
if [ -f "${scripts_folder_path}/common-functions-source.sh" ]
then
source "${scripts_folder_path}/common-functions-source.sh"
fi
if [ -f "${scripts_folder_path}/common-libs-functions-source.sh" ]
then
source "${scripts_folder_path}/common-libs-functions-source.sh"
fi
if [ -f "${scripts_folder_path}/common-apps-functions-source.sh" ]
then
source "${scripts_folder_path}/common-apps-functions-source.sh"
fi
source "${scripts_folder_path}/common-versions-source.sh"
# -----------------------------------------------------------------------------
if [ ! -z "#{DEBUG}" ]
then
echo $@
fi
WITH_STRIP=${WITH_STRIP:-"y"}
WITH_PDF=${WITH_PDF:-"n"}
WITH_HTML=${WITH_HTML:-"n"}
WITH_TESTS="${WITH_TESTS:-"y"}"
WITHOUT_MULTILIB="${WITHOUT_MULTILIB:-""}"
IS_DEVELOP="${IS_DEVELOP:-"n"}"
IS_DEBUG="${IS_DEBUG:-"n"}"
TEST_ONLY="${TEST_ONLY:-""}"
USE_GITS="${USE_GITS:-""}"
LINUX_INSTALL_RELATIVE_PATH=""
if [ "$(uname)" == "Linux" ]
then
JOBS="$(nproc)"
elif [ "$(uname)" == "Darwin" ]
then
JOBS="$(sysctl hw.ncpu | sed 's/hw.ncpu: //')"
else
JOBS="1"
fi
while [ $# -gt 0 ]
do
case "$1" in
--disable-strip)
WITH_STRIP="n"
shift
;;
--disable-tests)
WITH_TESTS="n"
shift
;;
--without-pdf)
WITH_PDF="n"
shift
;;
--with-pdf)
WITH_PDF="y"
shift
;;
--without-html)
WITH_HTML="n"
shift
;;
--with-html)
WITH_HTML="y"
shift
;;
--jobs)
JOBS=$2
shift 2
;;
--develop)
IS_DEVELOP="y"
shift
;;
--debug)
IS_DEBUG="y"
shift
;;
--linux-install-relative-path)
LINUX_INSTALL_RELATIVE_PATH="$2"
shift 2
;;
--test-only|--tests-only)
TEST_ONLY="y"
shift
;;
--disable-multilib)
WITHOUT_MULTILIB="y"
shift
;;
--use-gits)
USE_GITS="y"
shift
;;
*)
echo "Unknown action/option $1"
exit 1
;;
esac
done
if [ "${IS_DEBUG}" == "y" ]
then
WITH_STRIP="n"
fi
if [ "${REQUESTED_TARGET_PLATFORM}" == "win32" ]
then
export WITH_TESTS="n"
fi
# -----------------------------------------------------------------------------
# Restore non-root rights at exit.
trap fix_ownership EXIT
start_timer
detect_container
SAVED_PATH="${PATH}"
set_xbb_env
set_compiler_env
# -----------------------------------------------------------------------------
echo
echo "Here we go..."
echo
tests_initialize
build_versions
# -----------------------------------------------------------------------------
if [ "${TEST_ONLY}" != "y" ]
then
(
if [ "${TARGET_PLATFORM}" == "win32" ]
then
# The Windows still has a reference to libgcc_s and libwinpthread
export DO_COPY_GCC_LIBS="y"
fi
prepare_app_folder_libraries
# strip_libs
strip_binaries
copy_distro_files
copy_custom_files
check_binaries
create_archive
) 2>&1 | tee "${LOGS_FOLDER_PATH}/post-actions-output-$(ndate).txt"
fi
# -----------------------------------------------------------------------------
# Final checks.
# To keep everything as pristine as possible, run tests
# only after the archive is packed.
prime_wine
unset_compiler_env
tests_run
# -----------------------------------------------------------------------------
if [ "${TEST_ONLY}" != "y" ]
then
(
run_verbose ls -l "${APP_PREFIX}"
run_verbose ls -l "${APP_PREFIX}/bin"
(
cd "${APP_PREFIX}/bin"
echo
echo "package.json xpack.bin definitions:"
ls -1 | sed -e 's|\.exe$||' | sed -e '/\.dll$/d' | sort | sed -e 's|\(.*\)| "\1": "./.content/bin/\1",|'
)
) 2>&1 | tee "${LOGS_FOLDER_PATH}/post-lists-output-$(ndate).txt"
fi
# -----------------------------------------------------------------------------
stop_timer
exit 0
# -----------------------------------------------------------------------------