-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
host-functions-source.sh
1226 lines (972 loc) · 29.5 KB
/
host-functions-source.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
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -----------------------------------------------------------------------------
# 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.
# -----------------------------------------------------------------------------
# Helper script used in the second edition of the xPack build
# scripts. As the name implies, it should contain only functions and
# should be included with 'source' by the host build scripts.
# -----------------------------------------------------------------------------
function host_get_current_date()
{
# Use the UTC date as version in the name of the distribution file.
DISTRIBUTION_FILE_DATE=${DISTRIBUTION_FILE_DATE:-$(date -u +%Y%m%d-%H%M)}
# Leave a track of the start date, in case of resume needed.
mkdir -pv "${HOST_WORK_FOLDER_PATH}"
touch "${HOST_WORK_FOLDER_PATH}/${DISTRIBUTION_FILE_DATE}"
echo
echo "DISTRIBUTION_FILE_DATE=\"${DISTRIBUTION_FILE_DATE}\""
}
function host_start_timer()
{
HOST_BEGIN_SECOND=$(date +%s)
echo
echo "Script \"$0\" started at $(date)."
}
function host_stop_timer()
{
local host_end_second=$(date +%s)
echo
echo "Script \"$0\" completed at $(date)."
local delta_seconds=$((host_end_second-HOST_BEGIN_SECOND))
if [ ${delta_seconds} -lt 100 ]
then
echo "Duration: ${delta_seconds} seconds."
elif [ ${delta_seconds} -lt 3600 ]
then
local delta_minutes=$(((delta_seconds+30)/60))
echo "Duration: ${delta_minutes} minutes."
else
local delta_minutes=$(((delta_seconds+30)/60))
local delta_hours=$((delta_minutes/60))
local delta_hour_minutes=$((delta_minutes-(delta_hours*60)))
printf "Duration: %dh%02dm.\n" ${delta_hours} ${delta_hour_minutes}
fi
}
function host_notify_completed()
{
if [ "${HOST_UNAME}" == "Darwin" ]
then
say "Wake up, the build completed successfully"
fi
}
# -----------------------------------------------------------------------------
# Detect the machine the build runs on.
function host_detect()
{
echo
uname -a
HOST_UNAME="$(uname)"
HOST_MACHINE="$(uname -m)"
HOST_DISTRO_NAME="?" # Linux distribution name (Ubuntu|CentOS|...)
HOST_DISTRO_LC_NAME="?" # Same, in lower case.
HOST_NODE_ARCH="?" # Node.js process.arch (ia32|x64|arm|arm64)
HOST_NODE_PLATFORM="?" # Node.js process.platform (darwin|linux|win32)
if [ "${HOST_UNAME}" == "Darwin" ]
then
# uname -p -> i386, arm
# uname -m -> x86_64, arm64
HOST_DISTRO_NAME=Darwin
HOST_DISTRO_LC_NAME=darwin
HOST_BITS="64"
if [ "${HOST_MACHINE}" == "x86_64" ]
then
HOST_NODE_ARCH="x64"
elif [ "${HOST_MACHINE}" == "arm64" ]
then
HOST_NODE_ARCH="arm64"
else
echo "Unknown uname -m ${HOST_MACHINE}"
exit 1
fi
HOST_NODE_PLATFORM="darwin"
elif [ "${HOST_UNAME}" == "Linux" ]
then
# ----- Determine distribution name and word size -----
# uname -p -> x86_64|i686 (unknown in recent versions, use -m)
# uname -m -> x86_64|i686|aarch64|armv7l
if [ "${HOST_MACHINE}" == "x86_64" ]
then
HOST_BITS="64"
HOST_NODE_ARCH="x64"
elif [ "${HOST_MACHINE}" == "i386" -o "${HOST_MACHINE}" == "i686" ]
then
HOST_BITS="32"
HOST_NODE_ARCH="ia32"
elif [ "${HOST_MACHINE}" == "aarch64" ]
then
HOST_BITS="64"
HOST_NODE_ARCH="arm64"
elif [ "${HOST_MACHINE}" == "armv7l" -o "${HOST_MACHINE}" == "armv8l" ]
then
HOST_BITS="32"
HOST_NODE_ARCH="arm"
else
echo "Unknown uname -m ${HOST_MACHINE}"
exit 1
fi
HOST_NODE_PLATFORM="linux"
local lsb_path=$(which lsb_release)
if [ -z "${lsb_path}" ]
then
echo "Please install the lsb core package and rerun."
exit 1
fi
HOST_DISTRO_NAME=$(lsb_release -si)
HOST_DISTRO_LC_NAME=$(echo ${HOST_DISTRO_NAME} | tr "[:upper:]" "[:lower:]")
else
echo "Unsupported uname ${HOST_UNAME}"
exit 1
fi
echo
echo "Running on ${HOST_DISTRO_NAME} ${HOST_NODE_ARCH} (${HOST_BITS}-bit)."
USER_ID=$(id -u)
USER_NAME="$(id -u -n)"
GROUP_ID=$(id -g)
GROUP_NAME="$(id -g -n)"
TARGET_ARCH="${HOST_NODE_ARCH}"
TARGET_PLATFORM="${HOST_NODE_PLATFORM}"
TARGET_MACHINE="${HOST_MACHINE}"
TARGET_BITS="${HOST_BITS}"
IS_NATIVE=""
IS_DEVELOP=""
# Safer as root, with qemu-riscv fails with XBB v3.4.
CONTAINER_RUN_AS_ROOT=${CONTAINER_RUN_AS_ROOT:-"y"}
HAS_WINPTHREAD=${HAS_WINPTHREAD:-""}
}
# -----------------------------------------------------------------------------
function host_prepare_cache()
{
# The folder that caches all downloads is in Work, for easy access.
HOST_CACHE_FOLDER_PATH=${HOST_CACHE_FOLDER_PATH:-"${HOME}/Work/cache"}
CONTAINER_CACHE_FOLDER_PATH="/Host${HOST_CACHE_FOLDER_PATH}"
mkdir -pv "${HOST_CACHE_FOLDER_PATH}"
}
function host_options()
{
local help_message="$1"
shift
ACTION=""
DO_BUILD_SOURCES=""
DO_BUILD_WIN32=""
DO_BUILD_WIN64=""
DO_BUILD_LINUX32=""
DO_BUILD_LINUX64=""
DO_BUILD_LINUX_ARM32=""
DO_BUILD_LINUX_ARM64=""
DO_BUILD_MACOS=""
ENV_FILE=""
RELEASE_VERSION="${RELEASE_VERSION:-$(get_current_version)}"
argc=$#
declare -a argv
argv=( "$@" )
if [ ! -z "${DEBUG}" ]
then
echo ${argv[@]-}
fi
i=0
# Must be declared by the caller.
# declare -a rest
# Identify some of the options. The rest are collected and passed
# to the container script.
while [ $i -lt $argc ]
do
arg="${argv[$i]}"
case "${arg}" in
clean|cleanlibs|cleanall|preload-images)
ACTION="${arg}"
;;
--version)
((++i))
RELEASE_VERSION="${argv[$i]}"
;;
--win|--win64|--windows64)
DO_BUILD_WIN64="y"
;;
--linux64)
DO_BUILD_LINUX64="y"
;;
--arm32)
DO_BUILD_LINUX_ARM32="y"
;;
--arm64)
DO_BUILD_LINUX_ARM64="y"
;;
--macos|--macosx|--osx)
DO_BUILD_MACOS="y"
;;
--sources)
DO_BUILD_SOURCES="y"
;;
--all)
if [ "${HOST_NODE_ARCH}" == "arm64" ]
then
DO_BUILD_LINUX_ARM32="${DO_BUILD_LINUX_ARM32:-"y"}"
DO_BUILD_LINUX_ARM64="${DO_BUILD_LINUX_ARM64:-"y"}"
elif [ "${HOST_NODE_ARCH}" == "x64" ]
then
if [ "$(uname)" == "Darwin" ]
then
DO_BUILD_MACOS="${DO_BUILD_MACOS:-"y"}"
else
DO_BUILD_WIN64="${DO_BUILD_WIN64:-"y"}"
DO_BUILD_LINUX64="${DO_BUILD_LINUX64:-"y"}"
DO_BUILD_SOURCES="y"
fi
else
echo "--all supported only on 64-bit hosts"
fi
;;
--env-file)
((++i))
ENV_FILE="${argv[$i]}"
if [ ! -f "${ENV_FILE}" ];
then
echo "The specified environment file \"${ENV_FILE}\" does not exist, exiting..."
exit 1
fi
;;
# Deprecated.
--date)
((++i))
DISTRIBUTION_FILE_DATE="${argv[$i]}"
;;
--help)
echo "Usage:"
# Some of the options are processed by the container script.
echo "${help_message}"
echo
exit 0
;;
*)
# Collect all other in an array. Append to the end.
# Will be later processed by the container script.
set +u
rest[${#rest[*]}]="$arg"
set -u
;;
esac
((++i))
done
DO_BUILD_ANY="${DO_BUILD_MACOS}${DO_BUILD_LINUX64}${DO_BUILD_LINUX_ARM64}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX_ARM32}${DO_BUILD_WIN32}${DO_BUILD_SOURCES}"
# The ${rest[@]} options will be passed to the inner script.
if [ ! -z "${DEBUG}" ]
then
echo ${rest[@]-}
fi
}
function host_options_windows()
{
local help_message="$1"
shift
ACTION=""
DO_BUILD_WIN32=""
DO_BUILD_WIN64=""
# Kept, since they are used in various common functions.
DO_BUILD_LINUX32=""
DO_BUILD_LINUX64=""
DO_BUILD_LINUX_ARM32=""
DO_BUILD_LINUX_ARM64=""
DO_BUILD_MACOS=""
ENV_FILE=""
argc=$#
declare -a argv
argv=( "$@" )
if [ ! -z "${DEBUG}" ]
then
echo ${argv[@]-}
fi
i=0
# Must be declared by the caller.
# declare -a rest
# Identify some of the options. The rest are collected and passed
# to the container script.
while [ $i -lt $argc ]
do
arg="${argv[$i]}"
case "${arg}" in
clean|cleanlibs|cleanall|preload-images)
ACTION="${arg}"
;;
--win|--win64|--windows64)
DO_BUILD_WIN64="y"
;;
--all)
DO_BUILD_WIN64="y"
;;
--env-file)
((++i))
ENV_FILE="${argv[$i]}"
if [ ! -f "${ENV_FILE}" ];
then
echo "The specified environment file \"${ENV_FILE}\" does not exist, exiting..."
exit 1
fi
;;
# Deprecated.
--date)
((++i))
DISTRIBUTION_FILE_DATE="${argv[$i]}"
;;
--help)
echo "Usage:"
# Some of the options are processed by the container script.
echo "${help_message}"
echo
exit 0
;;
*)
# Collect all other in an array. Append to the end.
# Will be later processed by the container script.
set +u
rest[${#rest[*]}]="$arg"
set -u
;;
esac
((++i))
done
DO_BUILD_ANY="${DO_BUILD_WIN64}${DO_BUILD_WIN32}"
# The ${rest[@]} options will be passed to the inner script.
if [ ! -z "${DEBUG}" ]
then
echo ${rest[@]-}
fi
}
function host_native_options()
{
local help_message="$1"
shift
ACTION=""
DO_BUILD_WIN=""
IS_DEBUG=""
IS_DEVELOP=""
WITH_STRIP="y"
WITH_PDF="n"
WITH_HTML="n"
WITH_TESTS="n"
IS_NATIVE="y"
RELEASE_VERSION="${RELEASE_VERSION:-$(get_current_version)}"
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
clean|cleanlibs|cleanall)
ACTION="$1"
;;
--win|--windows)
DO_BUILD_WIN="y"
;;
--debug)
IS_DEBUG="y"
;;
--develop)
IS_DEVELOP="y"
;;
--jobs)
shift
JOBS=$1
;;
--disable-strip)
WITH_STRIP="n"
shift
;;
--disable-tests)
WITH_TESTS="n"
shift
;;
--without-pdf)
WITH_PDF="n"
shift
;;
--with-pdf)
WITH_PDF="y"
shift
;;
--help)
echo "Build a local/native ${DISTRO_NAME} ${APP_NAME}."
echo "Usage:"
# Some of the options are processed by the container script.
echo "${help_message}"
echo
exit 0
;;
*)
echo "Unknown action/option $1"
exit 1
;;
esac
shift
done
if [ ${IS_DEVELOP} == "y" ]
then
WITH_STRIP="n"
fi
if [ "${DO_BUILD_WIN}" == "y" ]
then
if [ "${HOST_NODE_PLATFORM}" == "linux" ]
then
TARGET_PLATFORM="win32"
else
echo "Windows cross builds are available only on GNU/Linux."
exit 1
fi
fi
}
function host_common()
{
if [ -f "${script_folder_path}/VERSION" ]
then
# Extract only the first line.
RELEASE_VERSION="$(cat "${script_folder_path}/VERSION" | sed -e '2,$d')"
fi
if [ -z "${RELEASE_VERSION}" ]
then
echo "Check the version, it cannot be empty."
exit 1
fi
echo
echo "Preparing release ${RELEASE_VERSION}..."
# ---------------------------------------------------------------------------
# Helper functions.
source "${helper_folder_path}/common-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"
# ---------------------------------------------------------------------------
# The Work folder is in HOME.
HOST_WORK_FOLDER_PATH=${WORK_FOLDER_PATH:-"${HOME}/Work"}
if [ "${IS_NATIVE}" == "y" -a "${IS_DEVELOP}" == "y" ]
then
HOST_WORK_FOLDER_PATH+="/${APP_LC_NAME}-dev"
else
HOST_WORK_FOLDER_PATH+="/${APP_LC_NAME}-${RELEASE_VERSION}"
fi
CONTAINER_WORK_FOLDER_PATH="/Host${HOST_WORK_FOLDER_PATH}"
do_actions
host_prepare_cache
CONTAINER_BUILD_SCRIPT_REL_PATH="build.git/scripts/helper/${CONTAINER_SCRIPT_NAME:-"container-build.sh"}"
echo "Container build script: \"${HOST_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}\"."
# ---------------------------------------------------------------------------
mkdir -pv "${HOST_WORK_FOLDER_PATH}"
# ---------------------------------------------------------------------------
# Set the DISTRIBUTION_FILE_DATE.
host_get_current_date
# ---------------------------------------------------------------------------
host_start_timer
host_prepare_prerequisites
# ---------------------------------------------------------------------------
copy_build_git
}
function host_prepare_prerequisites()
{
if [ "${HOST_UNAME}" == "Darwin" ]
then
local xbb_folder_path
local must_install=""
if [ -d "${HOME}/.local/xbb" ]
then
xbb_folder_path="${HOME}/.local/xbb"
elif [ -d "${HOME}/opt/xbb" ]
then
xbb_folder_path="${HOME}/opt/xbb"
elif [ -d "${HOME}/opt/homebrew/xbb" ]
then
xbb_folder_path="${HOME}/opt/homebrew/xbb"
else
must_install="y"
fi
if [ ! -z "${xbb_folder_path}" ]
then
echo
echo "Checking XBB in '${xbb_folder_path}'..."
if [ ! -f "${xbb_folder_path}/xbb-source.sh" ]
then
must_install="y"
fi
fi
if [ -n "${must_install}" ]
then
echo
echo "Please install the macOS XBB and rerun."
echo "https://github.com/xpack/xpack-build-box/tree/master/macos"
exit 1
fi
(
must_install=""
local tl_folder=""
if [ -d "$HOME/.local/texlive" ]
then
tl_folder="$HOME/.local/texlive"
elif [ -d "$HOME/opt/texlive" ]
then
tl_folder="$HOME/opt/texlive"
else
must_install="y"
fi
# Check local TeX Live.
if [ -n "${tl_folder}" ]
then
# TODO: update for Apple Silicon
PATH="${tl_folder}/bin/$(ls "${tl_folder}/bin" | sed -n -e 1p):${PATH}"
export PATH
echo
echo "Checking TeX Live in '${tl_folder}'..."
set +e
tex --version | grep 'TeX 3'
if [ $? != 0 ]
then
must_install="y"
fi
set -e
fi
if [ -n "${must_install}" ]
then
echo
echo "Please install TeX Live and rerun."
echo "https://github.com/xpack/xpack-build-box/blob/master/macos/README.md#install-tex"
# Comment this out if TeX is temporarily not available and use --without-pdf
exit 1
fi
)
fi # "${HOST_UNAME}" == "Darwin"
host_prepare_cache
# The host script will pass to the container script
# various environment variables.
HOST_DEFINES_SCRIPT_PATH="${HOST_WORK_FOLDER_PATH}/build.git/scripts/host-defs-source.sh"
DEPLOY_FOLDER_NAME=${DEPLOY_FOLDER_NAME:-"deploy"}
}
# -----------------------------------------------------------------------------
function host_prepare_docker()
{
echo
echo "Checking Docker..."
set +e
docker --version
if [ $? != 0 ]
then
echo "Please start docker daemon and rerun."
echo "If not installed, see https://docs.docker.com/installation/."
exit 1
fi
echo
echo "Pruning Docker..."
docker system prune -f
set -e
}
# -----------------------------------------------------------------------------
function host_build_target()
{
message="$1"
shift
echo
echo "================================================================================"
echo "=== ${message}"
echo
echo "$@"
local container_script_path=""
local target_platform="${HOST_NODE_PLATFORM}"
local target_arch="${HOST_NODE_ARCH}"
local target_machine="${HOST_MACHINE}"
local target_bits="${HOST_BITS}"
# If the docker image is not set, it is a native build.
local docker_image=""
local build_binaries_path=""
local env_file=""
while [ $# -gt 0 ]
do
case "$1" in
--script)
container_script_path="$2"
shift 2
;;
--target-platform)
target_platform="$2"
shift 2
;;
--target-arch)
target_arch="$2"
shift 2
;;
--target-machine)
target_machine="$2"
shift 2
;;
--target-bits)
target_bits="$2"
shift 2
;;
--docker-image)
docker_image="$2"
shift 2
;;
--env-file)
env_file="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Unknown option $1, exit."
exit 1
esac
done
if [ "${target_platform}" == "sources" ]
then
target_arch="none"
target_bits=""
fi
# The remaining "$@" options will be passed to the inner script.
if [ -n "${DEBUG}" ]
then
echo "$@"
fi
# ---------------------------------------------------------------------------
mkdir -pv "$(dirname "${HOST_DEFINES_SCRIPT_PATH}")"
echo "${RELEASE_VERSION}" >"$(dirname "${HOST_DEFINES_SCRIPT_PATH}")"/VERSION
rm -rf "${HOST_DEFINES_SCRIPT_PATH}"
touch "${HOST_DEFINES_SCRIPT_PATH}"
echo "RELEASE_VERSION=\"${RELEASE_VERSION}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "DISTRIBUTION_FILE_DATE=\"${DISTRIBUTION_FILE_DATE}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "REQUESTED_TARGET_PLATFORM=\"${target_platform}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "REQUESTED_TARGET_ARCH=\"${target_arch}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "REQUESTED_TARGET_MACHINE=\"${target_machine}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "REQUESTED_TARGET_BITS=\"${target_bits}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "HOST_PLATFORM=\"${HOST_NODE_PLATFORM}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "HOST_ARCH=\"${HOST_NODE_ARCH}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "HOST_MACHINE=\"${HOST_MACHINE}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "HOST_BITS=\"${HOST_BITS}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "HOST_UNAME=\"${HOST_UNAME}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "USER_ID=\"${USER_ID}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "USER_NAME=\"${USER_NAME}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "GROUP_ID=\"${GROUP_ID}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "GROUP_NAME=\"${GROUP_NAME}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "CONTAINER_RUN_AS_ROOT=\"${CONTAINER_RUN_AS_ROOT}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "HOST_WORK_FOLDER_PATH=\"${HOST_WORK_FOLDER_PATH}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "CONTAINER_WORK_FOLDER_PATH=\"${CONTAINER_WORK_FOLDER_PATH}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "HOST_CACHE_FOLDER_PATH=\"${HOST_CACHE_FOLDER_PATH}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "CONTAINER_CACHE_FOLDER_PATH=\"${CONTAINER_CACHE_FOLDER_PATH}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
echo "DEPLOY_FOLDER_NAME=\"${DEPLOY_FOLDER_NAME}\"" >>"${HOST_DEFINES_SCRIPT_PATH}"
if [ -z "${docker_image}" ]
then
host_run_native_script \
--script "${container_script_path}" \
--env-file "${env_file}" \
-- \
"$@"
else
host_run_docker_script \
--script "${container_script_path}" \
--docker-image "${docker_image}" \
--docker-container-name "${APP_LC_NAME}-${RELEASE_VERSION}-${target_platform}-${target_arch}-build" \
--env-file "${env_file}" \
--host-uname "${HOST_UNAME}" \
-- \
"$@"
fi
if [ -n "${DEBUG}" ]
then
echo "host_build_target ${rest[@]-} completed."
fi
}
# -----------------------------------------------------------------------------
function host_run_native_script()
{
local local_script=""
local env_file=""
while [ $# -gt 0 ]
do
case "$1" in
--script)
local_script="$2"
shift 2
;;
--env-file)
env_file="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Unknown option $1, exit."
exit 1
esac
done
# The remaining $@ options will be passed to the inner script.
echo
echo "Running script \"$(basename "${local_script}")\" natively..."
# Run the inner script in a local sub-shell, possibly with the
# custom environment.
(
if [ -n "${env_file}" -a -f "${env_file}" ]
then
source "${env_file}"
fi
/bin/bash ${DEBUG} "${local_script}" "$@"
)
}
# -----------------------------------------------------------------------------
function host_run_docker_script()
{
local docker_script=""
local docker_image=""
local docker_container_name=""
local host_uname=""
local env_file=""
local opt_env_file=
while [ $# -gt 0 ]
do
case "$1" in
--script)
docker_script="$2"
shift 2
;;
--docker-image)
docker_image="$2"
shift 2
;;
--docker-container-name)
docker_container_name="$2"
shift 2
;;
--host-uname)
host_uname="$2"
shift 2
;;
--env-file)
env_file="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Unknown option $1, exit."
exit 1
esac
done
set +e
# Remove a possible previously crashed container.
docker rm --force "${docker_container_name}" > /dev/null 2> /dev/null
set -e
echo
echo "Running script \"$(basename "${docker_script}")\" inside docker image \"${docker_image}\"..."