-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-qt.fish
executable file
·338 lines (285 loc) · 9.82 KB
/
build-qt.fish
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/usr/bin/env fish
set -g BUILD_ARGV $argv
set_color green
echo QtBuildScript
echo " A fish shell script to simplify your Qt build experience."
echo
set_color normal
if not source (dirname (status --current-filename))/utils/common.fish 2>/dev/null
set_color red
echo "Initialization failed."
exit 1
end
cd $BASE_DIR
if test -n "$QT_BUILDSCRIPT_EXPORTED"
set_color red
echo "You are probably running the build script from an environment"
echo "that is generated by its own exported one, undefined things could happen!"
echo ""
echo "Press enter to continue."
set_color normal
read -p echo
end
set -g EXTRA_EXPORT_VARIABLES
set -g EXTRA_CMAKE_ARGUMENTS
set -le arg_flag
set -lp arg_flag (fish_opt --short=p --long=platform --required-val)
set -lp arg_flag (fish_opt --short=a --long=arch --required-val)
set -lp arg_flag (fish_opt --short=h --long=host-path --required-val)
set -lp arg_flag (fish_opt --short=j --long=parallel --optional-val)
set -lp arg_flag (fish_opt --short=1 --long=help --long-only)
set -lp arg_flag (fish_opt --short=k --long=skip-cleanup)
set -lp arg_flag (fish_opt --short=E --long=export --required-val)
set -lp arg_flag (fish_opt --short=A --long=extra-args --required-val)
set -lp arg_flag (fish_opt --short=N --long=no-install)
set_color red
argparse $arg_flag -- $argv || exit 1
set_color normal
set SUPPORTED_PLATFORMS (basename -s .fish $BASE_DIR/utils/platforms/* | sort)
set SUPPORTED_KITS (basename -s .fish $BASE_DIR/utils/kits/* | sort)
if set -q _flag_help
echo "Usage:"
echo " "(status --current-filename) --help
echo " "(status --current-filename) "[options] [kits]"
echo ""
echo "options:"
echo " -p, --platform=<platform> The target platform, default value is 'desktop'"
echo " -a, --arch=<arch> Target architecture, default='x86_64', platform-specific."
echo " -h, --host-path=<path> Path to the Qt host build directory, can be automatically detected if unspecified."
echo " -j, --parallel=<N> Run N jobs at once, can be automatically detected from nproc if unspecified."
echo " -k, --skip-cleanup Skip cleanup the build directory."
echo " -E, --export=<file> Export prepared environment variables to a custom file only, do not perform build."
echo " -A, --extra-args Append extra arguments to CMake."
echo " -N, --no-install Do not perform installation after build."
echo ""
echo "available kits:"
echo " combination of:"
printf ' - %s\n' $SUPPORTED_KITS
echo ""
echo "available platforms:"
printf ' - %s\n' $SUPPORTED_PLATFORMS
exit 0
end
# Boolean args
set SKIP_CLEANUP (if set -q _flag_skip_cleanup; echo "1"; else; echo "0"; end)
set NO_INSTALL (if set -q _flag_no_install; echo "1"; else; echo "0"; end)
# Args
set PARALLEL_LEVEL (if test -z "$_flag_parallel"; echo "$NPROCS"; else; echo "$_flag_parallel"; end)
set QT_PLATFORM (if test -z "$_flag_platform"; echo "desktop"; else; echo "$_flag_platform"; end)
set QT_ARCH (if test -z "$_flag_arch"; echo "x86_64"; else; echo "$_flag_arch"; end)
set EXPORT_PATH "$_flag_export"
if not contains -- "$QT_PLATFORM" $SUPPORTED_PLATFORMS
set_color red
echo "Platform '$QT_PLATFORM' not supported."
exit 1
end
for kit in $argv
if not contains -- "$kit" $SUPPORTED_KITS
set_color red
echo "Build kit '$kit' not supported."
exit 1
end
end
# Prepend base-kits if exists
if test -e $BASE_DIR/.base-kits
set_color green
echo -n "Applying base kits from: "
set_color normal
echo "$BASE_DIR/.base-kits"
set_color green
echo -n "Base Kits:"
set_color normal
for k in (cat $BASE_DIR/.base-kits)
echo -n " $k"
set -p argv "$k"
end
end
# If kits are empty, apply default kits.
if test -z "$argv"
set_color blue
echo -n "Applying default kits from: "
set_color normal
echo "$BASE_DIR/.default-kits"
set_color green
echo -n "Default Kits:"
set_color normal
set argv
for k in (cat $BASE_DIR/.default-kits)
echo -n " $k"
set -p argv "$k"
end
end
if [ "$QT_PLATFORM" != desktop ]
echo ""
if not set -q _flag_host_path
set -l desktops $BASE_DIR/Current/desktop*
if set -q desktops[1]
set QT_HOST_PATH (realpath $desktops[1])
set_color green
echo -n "Detected QT_HOST_PATH: "
set_color normal
echo $QT_HOST_PATH
else
set_color red
echo "Cannot automatically detect Qt host path, please specify one using the -h option."
exit 1
end
else
set QT_HOST_PATH $_flag_host_path
end
end
echo ""
set -g BUILD_KITS $argv
echo ""
lastdedup BUILD_KITS
set_color green && echo -n "Build Kits: " && set_color normal
echo $BUILD_KITS
if source "$BASE_DIR/utils/platforms/$QT_PLATFORM.fish" 2>/dev/null
set_color green
echo -n "Build Platform: "
set_color normal
echo "$QT_PLATFORM"
else
set_color red
echo "Failed to initialise platform '$QT_PLATFORM'."
exit 1
end
echo ""
set BUILD_KITS_DISPLAY $BUILD_KITS
set_color green
echo "Loading Kits..."
set_color normal
for kit in $BUILD_KITS
if not contains -- $kit $SUPPORTED_KITS
set_color red
echo "Build kit '$kit' not supported."
exit 1
end
set_color green
echo -n " Loading Kit: "
set_color normal
echo "$kit"
set_color blue
if not source "$BASE_DIR/utils/kits/$kit.fish" 2>/dev/null
set_color red
echo "Failed to load '$kit'."
exit 1
end
end
set BUILD_TYPE (string join '-' -- "$QT_PLATFORM" $QT_ARCH (string join '-' (for k in $BUILD_KITS_DISPLAY; echo $k; end | sort | uniq)))
echo ""
set_color green && echo -n "Build Identifier: " && set_color normal
echo $BUILD_TYPE
set -g BUILD_DIR "$BASE_DIR/.build/$BUILD_TYPE"
set -g INSTALL_DIR "$BASE_DIR/nightly/$BUILD_TYPE/"(date "+%Y-%m-%d")
set -p EXTRA_CMAKE_ARGUMENTS -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR/
set -p EXTRA_CMAKE_ARGUMENTS -GNinja
for x in (echo -n $CMAKE_ARGUMENTS_PREPEND | sed 's/ /\n/g')
set -p EXTRA_CMAKE_ARGUMENTS $x
end
for x in (echo -n $CMAKE_ARGUMENTS_APPEND | sed 's/ /\n/g')
set -a EXTRA_CMAKE_ARGUMENTS $x
end
set -p EXTRA_CMAKE_ARGUMENTS $_flag_extra_args
echo ""
echo "CMake arguments:"
set_color blue
for arg in $EXTRA_CMAKE_ARGUMENTS
echo " $arg"
end
set_color normal
set -p EXTRA_CMAKE_ARGUMENTS -DQT_BUILD_SUBMODULES=(string join ';' -- $QT_MODULES)
echo ""
if [ "$SKIP_CLEANUP" = 1 ]
set_color yellow
echo -n "Will not cleanup build directory: "
set_color normal
echo "$BUILD_DIR"
end
if [ "$NO_INSTALL" = 1 ]
set_color yellow
echo -n "Will not perform installation to target directory: "
set_color normal
echo "$INSTALL_DIR"
end
mkdir -p "$BASE_DIR/Current/"
mkdir -p "$BASE_DIR/nightly/"
mkdir -p $BUILD_DIR
set_color yellow
echo "Will build with $PARALLEL_LEVEL concurrent jobs."
set_color normal
# Do not count down in export mode.
if test -z "$EXPORT_PATH"
set_color yellow
echo -n "Will start building in 5 seconds, press Ctrl+C to cancel: "
for sec in 5 4 3 2 1
echo -n "$sec..."
sleep 1
end
set_color normal
echo ""
if [ "$SKIP_CLEANUP" = 0 ]
source $BASE_DIR/utils/cleanup.fish
end
else
set _canexport 0
if rm "$EXPORT_PATH" 2>/dev/null || touch "$EXPORT_PATH"
echo "# Compilation Environment File for kit '$BUILD_TYPE'" | tee "$EXPORT_PATH" 1>/dev/null 2>/dev/null
if test $status -eq 0
set _canexport 1
end
end
if not test $_canexport -eq 1
set_color red
echo "Failed to export compilation environment to $EXPORT_PATH"
set_color normal
exit 1
end
echo "# File generated by calling with argv='$BUILD_ARGV'" >>"$EXPORT_PATH"
echo "#" >>"$EXPORT_PATH"
echo '# Example Usage:' >>"$EXPORT_PATH"
echo "#" >>"$EXPORT_PATH"
echo '# source ./this-file' >>"$EXPORT_PATH"
echo '# mkdir -p $BUILD_DIR && cd $BUILD_DIR' >>"$EXPORT_PATH"
echo '# cmake $SRC_DIR $EXTRA_CMAKE_ARGUMENTS' >>"$EXPORT_PATH"
echo '# cmake --build . --parallel $PARALLEL_LEVEL' >>"$EXPORT_PATH"
echo '# cd $BASE_DIR' >>"$EXPORT_PATH"
echo '# Then run ./utils/finalise.fish to perform finalisation.' >>"$EXPORT_PATH"
echo "" >>"$EXPORT_PATH"
echo "echo 'Initializing Qt Build Environment....'" >>"$EXPORT_PATH"
function exportenv
echo "" >>"$EXPORT_PATH"
echo "# $argv[1]: $argv[2]" >>"$EXPORT_PATH"
echo "export $argv[1]='$$argv[1]'" >>"$EXPORT_PATH"
echo "echo $argv[1]=\$$argv[1]" >>"$EXPORT_PATH"
end
set QT_BUILDSCRIPT_EXPORTED 1
exportenv QT_BUILDSCRIPT_EXPORTED "Mark the environment as exported"
exportenv SKIP_CLEANUP "Skip cleaning up build directories"
exportenv PATH "Executable search paths"
exportenv BUILD_DIR "Build output directory"
exportenv BUILD_TYPE "Build type"
exportenv BUILD_KITS "Build kits"
exportenv BASE_DIR "Base script directory"
exportenv SRC_DIR "Source files' directory"
exportenv PARALLEL_LEVEL "Level of parallelism"
exportenv EXTRA_CMAKE_ARGUMENTS "CMake arguments"
exportenv INSTALL_DIR "Installation prefix"
exportenv QT_PLATFORM "Qt target plarform"
exportenv QT_ARCH "Qt target architecture"
exportenv QT_HOST_PATH "Qt host build path"
exportenv QT_MODULES "Qt submodules to build"
exportenv NO_INSTALL "Skip installation"
for v in $EXTRA_EXPORT_VARIABLES
exportenv $v "$v"
end
echo "Created $EXPORT_PATH"
echo "See the content of the generated file for its usage."
end
if test -z "$EXPORT_PATH"
cd $BUILD_DIR
cmake $SRC_DIR $EXTRA_CMAKE_ARGUMENTS || exit 1
cmake --build . --parallel $PARALLEL_LEVEL || exit 1
set QT_BUILDSCRIPT_EXPORTED 1
source $BASE_DIR/utils/finalise.fish || exit 1
end