-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjinx
More file actions
executable file
·2283 lines (1838 loc) · 64.3 KB
/
jinx
File metadata and controls
executable file
·2283 lines (1838 loc) · 64.3 KB
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
#! /bin/sh
# Copyright (C) 2022-2025 mintsuki
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
set -e
IFS=" "" "'
'
LC_COLLATE=C
export LC_COLLATE
umask 0022
jinx_major_ver="0.6"
jinx_minor_ver="5"
jinx_version="${jinx_major_ver}.${jinx_minor_ver}"
debian_snapshot="20250627T143139Z"
XBPS_VERSION=0.60.5
XBPS_B2SUM=91aad926f25e78c17b2646f2e478e9a4141d9d80ebb93bc821c91333c8f5b5cf72a08edb7f25aef486e0761f15da8322207474c3b6f546d6403dd424cc442525
die() {
echo "$1"
exit 1
}
if [ -z "$1" ]; then
die "$0: no command specified."
fi
cmd_help() {
echo "usage: $0 <command> <package(s)>"
printf "\n help|--help Displays this message"
printf "\n version|--version Prints the version"
printf "\n init Initialises a build directory"
printf "\n build Builds package(s), does incremental builds"
printf "\n build-if-needed Builds package(s) if necessary"
printf "\n rebuild Rebuilds package(s)"
printf "\n host-build Same as build, but for host package(s)"
printf "\n host-rebuild Same as rebuild, but for host package(s)"
printf "\n regenerate|regen Regenerates patch for package(s) and re-runs prepare step"
printf "\n install Installs package(s)"
printf "\n reinstall Reinstalls package(s)"
printf "\n rebuild-cache Rebuilds Jinx cache"
printf "\n\nexample: $0 build-if-needed '*'\n"
}
cmd_init() {
if ! [ -f "$1"/Jinxfile ]; then
die "$0: Provided source directory contains no Jinxfile"
fi
srcdir="$1"
if [ -f ".jinx-parameters" ]; then
die "$0: Current directory already initialised, run '$0 deinit' first"
fi
if [ -f "Jinxfile" ]; then
die "$0: In-tree builds are not supported"
fi
cat <<EOF >.jinx-parameters
#! /bin/sh
JINX_SOURCE_DIR="${srcdir}"
JINX_ARCH="$(uname -m)"
EOF
shift 1
for p in "$@"; do
echo "JINX_$p" | sed 's/=/="/g;s/$/"/g' >>.jinx-parameters
done
echo "Initialised with '${srcdir}' as source directory"
}
case "$1" in
version|--version)
echo "Jinx version $jinx_version"
exit 0
;;
help|--help)
cmd_help
exit 0
;;
init)
shift 1
cmd_init "$@"
exit 0
;;
esac
if ! [ "$(uname -s)" = "Linux" ]; then
die "$0: Jinx only supports running on Linux hosts."
fi
case "$1" in
install)
;;
*)
if [ "$(id -u)" = "0" ]; then
die "$0: Jinx does not support running as root."
fi
;;
esac
make_dir() {
for d in "$@"; do
mkdir -p "$d"
dn="$(cd "$d" && pwd -P)"
while true; do
if [ "$dn" = "$base_dir" ] || [ "$dn" = "$build_dir" ] || [ "$dn" = "/" ]; then
break
fi
chmod 755 "$dn"
dn="$(dirname "$dn")"
done
done
}
script_name="$(basename "$0")"
script_dir="$(dirname "$0")"
if [ "$script_dir" = "." ] || [ -z "$script_dir" ]; then
if echo "$0" | grep "/" >/dev/null 2>&1; then
script_dir=.
else
script_dir="$(dirname $(which "${script_name}"))"
fi
fi
script_dir="$(cd "${script_dir}" && pwd -P)"
script="${script_dir}/${script_name}"
in_container=false
if [ "$script" = "/base_dir/jinx" ]; then
in_container=true
fi
if [ -z "$JINX_PARALLELISM" ]; then
max_threads_by_mem="$(( ((($(free | awk '/^Mem:/{print $2}') + 1048575) / 1048576) + 1) / 2 ))"
parallelism="$(nproc 2>/dev/null || echo 1)"
parallelism="$(( $parallelism < $max_threads_by_mem ? $parallelism : $max_threads_by_mem ))"
else
parallelism="$JINX_PARALLELISM"
fi
if [ "$in_container" = "false" ]; then
build_dir="$(pwd -P)"
else
build_dir=/build_dir
fi
if ! [ -f "${build_dir}"/.jinx-parameters ]; then
die "$0: Please run '$0 init <source dir> <parameters>' first"
fi
. "${build_dir}"/.jinx-parameters
if [ "$in_container" = "false" ]; then
base_dir="$(cd "$JINX_SOURCE_DIR" && pwd -P)"
else
base_dir=/base_dir
fi
JINX_CONFIG_FILE="${base_dir}/Jinxfile"
if ! [ -d "$(dirname "$JINX_CONFIG_FILE")" ]; then
die "$0: cannot access Jinxfile directory"
fi
JINX_CONFIG_FILE="$(cd "$(dirname "$JINX_CONFIG_FILE")" && pwd -P)"/"$(basename "$JINX_CONFIG_FILE")"
if [ -z "$JINX_CACHE_DIR" ]; then
JINX_CACHE_DIR="${base_dir}/.jinx-cache"
fi
if ! [ -d "$(dirname "$JINX_CACHE_DIR")" ]; then
die "$0: cannot access cache directory parent"
fi
if [ "$in_container" = "false" ]; then
make_dir "$JINX_CACHE_DIR"
JINX_CACHE_DIR="$(cd "$JINX_CACHE_DIR" && pwd -P)"
make_dir "${base_dir}/sources" "${build_dir}/host-builds" "${build_dir}/host-pkgs" "${build_dir}/builds" "${build_dir}/pkgs"
fi
apt_cache="$JINX_CACHE_DIR/apt-cache"
temp_collect=""
trap 'eval rm -rf "$temp_collect"' EXIT
make_temp() {
tmp="$(mktemp "$JINX_CACHE_DIR/tmp.XXXXXXXX")"
temp_collect="${temp_collect} \"${tmp}\""
if [ "$1" = "-d" ]; then
rm -f "${tmp}"
make_dir "${tmp}"
fi
}
build_hostdeps() {
for hostdep in ${hostdeps} ${hostrundeps}; do
[ -f "${base_dir}"/host-recipes/${hostdep} ] || die "missing host dependency '${hostdep}' for recipe '${name}'"
[ -d "${build_dir}"/host-pkgs/${hostdep} ] && continue
"${script}" host-build ${hostdep}
done
}
build_deps() {
for dep in ${deps} ${builddeps}; do
[ -f "${base_dir}"/recipes/${dep} ] || die "missing dependency '${dep}' for recipe '${name}'"
(
set -e
unset version
unset from_source
. "${base_dir}"/recipes/${dep}
if ! [ -z "${from_source}" ]; then
version=$(unset version && source_source_recipe ${from_source} && echo "$version")
fi
[ -f "${build_dir}"/pkgs/${name}-${version}_${revision}.${JINX_ARCH}.xbps ]
) && continue
"${script}" build ${dep}
done
}
get_hostdeps_file_run() {
deps_to_do=""
for hostdep in ${hostrundeps}; do
grep " ${hostdep} " "${hostdeps_file}" >/dev/null 2>&1 || deps_to_do="${deps_to_do} ${hostdep}"
grep " ${hostdep} " "${hostdeps_file}" >/dev/null 2>&1 || printf " ${hostdep} " >> "${hostdeps_file}"
done
for hostdep in ${deps_to_do}; do
"${script}" internal-get-hostdeps-file-run ${hostdep} "${hostdeps_file}"
done
}
get_hostdeps_file() {
deps_to_do=""
for hostdep in ${hostdeps} ${hostrundeps}; do
grep " ${hostdep} " "${hostdeps_file}" >/dev/null 2>&1 || deps_to_do="${deps_to_do} ${hostdep}"
grep " ${hostdep} " "${hostdeps_file}" >/dev/null 2>&1 || printf " ${hostdep} " >> "${hostdeps_file}"
done
for hostdep in ${deps_to_do}; do
"${script}" internal-get-hostdeps-file-run ${hostdep} "${hostdeps_file}"
done
}
get_builddeps_file() {
deps_to_do=""
for dep in ${deps} ${builddeps}; do
grep " ${dep} " "${deps_file}" >/dev/null 2>&1 || deps_to_do="${deps_to_do} ${dep}"
grep " ${dep} " "${deps_file}" >/dev/null 2>&1 || printf " ${dep} " >> "${deps_file}"
done
for dep in ${deps_to_do}; do
"${script}" internal-get-deps-file ${dep} "${deps_file}"
done
}
get_deps_file() {
deps_to_do=""
for dep in ${deps}; do
grep " ${dep} " "${deps_file}" >/dev/null 2>&1 || deps_to_do="${deps_to_do} ${dep}"
grep " ${dep} " "${deps_file}" >/dev/null 2>&1 || printf " ${dep} " >> "${deps_file}"
done
for dep in ${deps_to_do}; do
"${script}" internal-get-deps-file ${dep} "${deps_file}"
done
}
run_in_container1() {
run_in_cont1_root="$1"
shift 1
make_dir "$run_in_cont1_root"/jinx-cache
nochown_so=""
if [ -f "$JINX_CACHE_DIR/nochown.so" ]; then
nochown_so="--env LD_PRELOAD=/jinx-cache/nochown.so"
fi
"$JINX_CACHE_DIR/rbrt" \
--root "$run_in_cont1_root" rw \
--uid 0 \
--gid 0 \
--env HOME=/root \
--env LANG=en_US.UTF-8 \
--env LC_COLLATE=C \
--env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin \
--env LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib \
--env DEBIAN_FRONTEND=noninteractive \
${nochown_so} \
-m"${apt_cache}":/var/cache/apt/archives \
-m"$JINX_CACHE_DIR":/jinx-cache:ro \
-- \
"$@"
rm -rf "$run_in_cont1_root"/jinx-cache
}
check_duplicates() {
for elem in $(cd "$1" && find .); do
if [ -f "$2"/${elem} ] || [ -L "$2"/${elem} ]; then
return 1
fi
done
}
prepare_container() {
cd "${build_dir}"
make_temp
hostdeps_file="${tmp}"
make_temp
deps_file="${tmp}"
build_hostdeps
build_deps
get_hostdeps_file
get_builddeps_file
make_temp -d
container_pkgs="${tmp}"
make_temp -d
sysroot_dir="${tmp}"
for dep in $(cat "${deps_file}"); do
XBPS_ARCH=invalid \
XBPS_TARGET_ARCH="${JINX_ARCH}" \
"$JINX_CACHE_DIR"/xbps-bin/xbps-install -y -r "${sysroot_dir}" -R "${build_dir}"/pkgs "${dep}" >/dev/null 2>&1
done
if [ "$JINX_NATIVE_MODE" = "yes" ] && [ -z "$cross_compile" ]; then
imgroot="${sysroot_dir}"
else
for hostdep in $(cat "${hostdeps_file}"); do
if ! check_duplicates "${build_dir}"/host-pkgs/${hostdep}/usr/local "${container_pkgs}"; then
die "jinx: error: Dependency '${hostdep}' contains file confilcts"
fi
cp -Pplr "${build_dir}"/host-pkgs/${hostdep}/usr/local/. "${container_pkgs}"/
done
imagedeps="$(echo "${imagedeps}" | xargs -n1 | sort -u | xargs)"
pkgset=""
for pkg in ${imagedeps}; do
pkgset="${pkgset}${pkg}/"
if [ -f "$JINX_CACHE_DIR/sets/${pkgset}.image/.jinx-set-valid" ]; then
continue
fi
rm -rf "$JINX_CACHE_DIR/sets/${pkgset}"
make_dir "$JINX_CACHE_DIR/sets/${pkgset}"
want_link='l'
want_experimental=''
if echo "${pkg}" | grep -q '^experimental:'; then
want_link=''
want_experimental='-t experimental'
pkg="$(echo "${pkg}" | sed 's/^experimental://g')"
fi
cp -Pp${want_link}rf "$JINX_CACHE_DIR/sets/${pkgset}../.image" "$JINX_CACHE_DIR/sets/${pkgset}.image"
rm -f "$JINX_CACHE_DIR/sets/${pkgset}.image/.jinx-set-valid"
run_in_container1 "$JINX_CACHE_DIR/sets/${pkgset}.image" apt-get install -y ${want_experimental} "${pkg}"
# Fix permissions of files
for f in $(find "$JINX_CACHE_DIR/sets/${pkgset}.image" -perm 000 2>/dev/null); do
chmod 755 "$f"
done
touch "$JINX_CACHE_DIR/sets/${pkgset}.image/.jinx-set-valid"
done
imgroot="$JINX_CACHE_DIR/sets/${pkgset}.image"
fi
}
run_in_container() {
if [ "${allow_network}" = "yes" ]; then
unshare_net_flag=""
else
unshare_net_flag="-n"
fi
if [ ! -z "$TERM" ]; then
run_in_cont_term="--env TERM=\"$TERM\""
fi
if ! [ -z "$COLORTERM" ]; then
run_in_cont_colorterm="--env COLORTERM=\"$COLORTERM\""
fi
make_dir "${imgroot}/base_dir" "${imgroot}/sources" "${imgroot}/build_dir"
native_mode_mounts=""
if ( [ "$JINX_NATIVE_MODE" = "yes" ] && [ "$cross_compile" = "yes" ] ) || ( ! [ "$JINX_NATIVE_MODE" = "yes" ] ); then
make_dir "${imgroot}/sysroot"
container_pkgs_native_mount="-m${container_pkgs}:/usr/local:ro"
sysroot_native_mount="-m${sysroot_dir}:/sysroot:ro"
run_in_cont_lang=en_US.UTF-8
else
if ! [ -z "$JINX_NATIVE_LANG" ]; then
run_in_cont_lang="$JINX_NATIVE_LANG"
else
run_in_cont_lang=C
fi
fi
run_in_cont_argvar=""
for arg in "$@"; do
run_in_cont_argvar="$run_in_cont_argvar \"$arg\""
done
shadow_git_dir_build=""
if [ -d "${build_dir}"/.git ]; then
make_temp -d
shadow_git_dir_build="-m${tmp}:/build_dir/.git"
fi
shadow_git_dir_base=""
if [ -d "${base_dir}"/.git ]; then
make_temp -d
shadow_git_dir_base="-m${tmp}:/base_dir/.git"
fi
nochown_so=""
if [ -f "$JINX_CACHE_DIR/nochown.so" ]; then
nochown_so="--env LD_PRELOAD=/base_dir/.jinx-cache/nochown.so"
fi
"$JINX_CACHE_DIR/rbrt" \
--root "${imgroot}" \
--uid $(id -u) \
--gid $(id -g) \
--env HOME=/root \
--env LANG=${run_in_cont_lang} \
--env LC_COLLATE=C \
--env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin \
--env LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib \
${run_in_cont_term} \
${run_in_cont_colorterm} \
--env JINX_PARALLELISM="$parallelism" \
--env JINX_CONFIG_FILE=/base_dir/Jinxfile \
--env JINX_SOURCE_DIR=/base_dir \
${nochown_so} \
${container_pkgs_native_mount:+"${container_pkgs_native_mount}"} \
${sysroot_native_mount:+"${sysroot_native_mount}"} \
-m"${base_dir}":/base_dir${container_base_dir_ro} \
${shadow_git_dir_base:+"${shadow_git_dir_base}"} \
-m"${base_dir}"/sources:/base_dir/sources${container_sources_ro} \
-m"${build_dir}":/build_dir \
${shadow_git_dir_build:+"${shadow_git_dir_build}"} \
${unshare_net_flag} \
--workdir / \
-- \
/bin/bash -c "cd /build_dir && /bin/bash /base_dir/jinx $run_in_cont_argvar"
rm -rf "${imgroot}/sysroot" "${imgroot}/base_dir" "${imgroot}/sources" "${imgroot}/build_dir"
}
destroy_container() {
rm -rf "${container_pkgs}" "${sysroot_dir}"
}
do_hg_fetch() {
hg clone "${hg_url}" "${base_dir}"/sources/${name}
( cd "${base_dir}"/sources/${name} && hg up "${tag}" )
}
do_git_fetch() {
if [ -z "${commit}" ]; then
die "* error: Git commit not specified"
fi
if ! ( echo "${commit}" | grep -qE '^[0-9a-f]{40}$' ); then
die "* error: Invalid commit hash"
fi
if [ "${shallow}" = "no" ]; then
git clone "${git_url}" "${base_dir}"/sources/${name}
git -C "${base_dir}"/sources/${name} -c advice.detachedHead=false checkout "${commit}"
else
git clone "${git_url}" -c advice.detachedHead=false --revision="${commit}" --depth=1 "${base_dir}"/sources/${name}
fi
}
do_tarball_fetch() {
tarball_path="${base_dir}"/sources/"$(basename "${tarball_url}")"
if ! [ -f "$tarball_path" ]; then
make_temp
download_path="${tmp}"
curl -L -o "${download_path}" "${tarball_url}"
mv "${download_path}" "${tarball_path}"
fi
checksum_verified=no
if ! [ -z "${tarball_sha256}" ]; then
actual_sha256="$(sha256sum "${tarball_path}" | awk '{print $1;}')"
if ! [ ${actual_sha256} = ${tarball_sha256} ]; then
die "* error: Failed to verify SHA256 for ${name}.
Expected '${tarball_sha256}';
got '${actual_sha256}'."
fi
checksum_verified=yes
fi
if ! [ -z "${tarball_sha512}" ]; then
actual_sha512="$(sha512sum "${tarball_path}" | awk '{print $1;}')"
if ! [ ${actual_sha512} = ${tarball_sha512} ]; then
die "* error: Failed to verify SHA512 for ${name}.
Expected '${tarball_sha512}';
got '${actual_sha512}'."
fi
checksum_verified=yes
fi
if ! [ -z "${tarball_blake2b}" ]; then
actual_blake2b="$(b2sum "${tarball_path}" | awk '{print $1;}')"
if ! [ ${actual_blake2b} = ${tarball_blake2b} ]; then
die "* error: Failed to verify BLAKE2B for ${name}.
Expected '${tarball_blake2b}';
got '${actual_blake2b}'."
fi
checksum_verified=yes
fi
if [ "${checksum_verified}" = "no" ]; then
die "* error: No checksum method specified for ${name}"
fi
make_temp -d
extract_dir="${tmp}"
( cd "${extract_dir}" && tar -xf "${tarball_path}" )
mv "${extract_dir}"/* "${base_dir}"/sources/${name} >/dev/null 2>&1 || (
make_dir "${base_dir}"/sources/${name}
mv "${extract_dir}"/* "${base_dir}"/sources/${name}/
)
rm -rf "${extract_dir}" "${tarball_path}"
}
get_real_source_dir() {
if [ -z "${source_dir}" ]; then
source_dir="${base_dir}"/sources/${name}
else
source_dir="${base_dir}"/"${source_dir}"
is_local_package=true
fi
}
cont_fetch() {
make_dir "${base_dir}"/sources
source_source_recipe $1
get_real_source_dir
if ! [ -z "${git_url}" ]; then
do_git_fetch
elif ! [ -z "${hg_url}" ]; then
do_hg_fetch
elif ! [ -z "${tarball_url}" ]; then
do_tarball_fetch
fi
}
default_recipe_steps() {
early_prepare() {
true
}
prepare() {
true
}
configure() {
true
}
build() {
true
}
package() {
true
}
}
source_source_recipe() {
if [ -f "${base_dir}"/source-recipes/$1 ]; then
. "${base_dir}"/source-recipes/$1
elif [ -f "${base_dir}"/recipes/$1 ]; then
. "${base_dir}"/recipes/$1
unset deps
unset builddeps
unset hostrundeps
imagedeps="${source_imagedeps}"
hostdeps="${source_hostdeps}"
deps="${source_deps}"
allow_network="${source_allow_network}"
else
die "* could not find source recipe '$1'"
fi
}
cont_patch() {
source_source_recipe $1
get_real_source_dir
"${script}" internal-early-prepare $1
make_temp
patch_trash="${tmp}"
cd "${source_dir}"
needs_match_timestamps=no
rm -rf "${base_dir}"/sources/${name}-clean
if [ -d "${base_dir}"/patches/${name} ]; then
for patch in "${base_dir}"/patches/${name}/*; do
[ "${patch}" = "${base_dir}/patches/${name}/*" ] && break
[ "${patch}" = "${base_dir}"/patches/${name}/jinx-working-patch.patch ] && continue
if ! [ -d "${base_dir}"/sources/${name}-clean ]; then
cp -rp "${source_dir}" "${base_dir}"/sources/${name}-clean
needs_match_timestamps=yes
fi
patch --no-backup-if-mismatch -p1 -r "${patch_trash}" < "${patch}"
done
if [ "${needs_match_timestamps}" = yes ]; then
# make sure timestamps match
for f in $(diff -rq --no-dereference "${base_dir}"/sources/${name}-clean "${source_dir}" | sed '/^Only in/d;s/^Files //g;s/ and.*$//g'); do
touch --reference="$f" "$(echo "$f" | sed "s|sources/${name}-clean|sources/${name}|g")"
done
rm -rf "${base_dir}"/sources/${name}-clean
fi
fi
cp -rp "${source_dir}" "${base_dir}"/sources/${name}-clean
if [ -f "${base_dir}"/patches/${name}/jinx-working-patch.patch ]; then
patch --no-backup-if-mismatch -p1 -r "${patch_trash}" < "${base_dir}"/patches/${name}/jinx-working-patch.patch
# make sure timestamps match
for f in $(diff -rq --no-dereference "${base_dir}"/sources/${name}-clean "${source_dir}" | sed '/^Only in/d;s/^Files //g;s/ and.*$//g'); do
touch --reference="$f" "$(echo "$f" | sed "s|sources/${name}-clean|sources/${name}|g")"
done
fi
cp -rp "${source_dir}" "${base_dir}"/sources/${name}-workdir
cd "${base_dir}"
touch "${base_dir}"/sources/${name}.patched
}
do_early_prepare() {
default_recipe_steps
source_source_recipe $1
get_real_source_dir
sysroot_dir="/sysroot"
cd "${source_dir}"
[ "${is_local_package}" = true ] || container_base_dir_ro=":ro"
early_prepare
container_base_dir_ro=""
cd "${base_dir}"
}
do_prepare() {
default_recipe_steps
source_source_recipe $1
get_real_source_dir
[ -f "${base_dir}"/sources/${name}.prepared ] && return
sysroot_dir="/sysroot"
cd "${source_dir}"
[ "${is_local_package}" = true ] || container_base_dir_ro=":ro"
prepare
container_base_dir_ro=""
cd "${base_dir}"
touch "${base_dir}"/sources/${name}.prepared
}
do_configure_host() {
default_recipe_steps
unset from_source
. "${base_dir}"/host-recipes/$1
make_dir "${build_dir}"/host-builds/${name}
if ! [ -z "${from_source}" ]; then
version=$(unset version && source_source_recipe ${from_source} && echo "$version")
source_dir="$(unset source_dir && source_source_recipe ${from_source} && echo "$source_dir")"
if [ -z "${source_dir}" ]; then
source_dir="${base_dir}"/sources/${from_source}
else
source_dir="${base_dir}"/"${source_dir}"
fi
fi
prefix="/usr/local"
sysroot_dir="/sysroot"
cd "${build_dir}"/host-builds/${name}
configure
cd "${base_dir}"
}
do_build_host() {
default_recipe_steps
unset from_source
. "${base_dir}"/host-recipes/$1
make_dir "${build_dir}"/host-builds/${name}
if ! [ -z "${from_source}" ]; then
version=$(unset version && source_source_recipe ${from_source} && echo "$version")
source_dir="$(unset source_dir && source_source_recipe ${from_source} && echo "$source_dir")"
if [ -z "${source_dir}" ]; then
source_dir="${base_dir}"/sources/${from_source}
else
source_dir="${base_dir}"/"${source_dir}"
fi
fi
prefix="/usr/local"
sysroot_dir="/sysroot"
cd "${build_dir}"/host-builds/${name}
build
cd "${base_dir}"
}
do_package_host() {
default_recipe_steps
unset from_source
. "${base_dir}"/host-recipes/$1
dest_dir="${build_dir}"/host-pkgs/${name}
rm -rf "${dest_dir}"
make_dir "${dest_dir}"
if ! [ -z "${from_source}" ]; then
version=$(unset version && source_source_recipe ${from_source} && echo "$version")
source_dir="$(unset source_dir && source_source_recipe ${from_source} && echo "$source_dir")"
if [ -z "${source_dir}" ]; then
source_dir="${base_dir}"/sources/${from_source}
else
source_dir="${base_dir}"/"${source_dir}"
fi
fi
prefix="/usr/local"
sysroot_dir="/sysroot"
make_dir "${dest_dir}${prefix}"
cd "${build_dir}"/host-builds/${name}
package
# Remove libtool files
for i in $(find "${dest_dir}${prefix}" -name "*.la"); do
rm -rvf $i
done
cd "${base_dir}"
}
do_configure() {
default_recipe_steps
unset from_source
. "${base_dir}"/recipes/$1
make_dir "${build_dir}"/builds/${name}
if ! [ -z "${from_source}" ] || ! [ -z "${tarball_url}" ] || ! [ -z "${git_url}" ] || ! [ -z "${hg_url}" ] || ! [ -z "${source_dir}" ]; then
if ! [ -z "${from_source}" ]; then
version=$(unset version && source_source_recipe ${from_source} && echo "$version")
source_dir="$(unset source_dir && source_source_recipe ${from_source} && echo "$source_dir")"
else
from_source=${name}
fi
if [ -z "${source_dir}" ]; then
source_dir="${base_dir}"/sources/${from_source}
else
source_dir="${base_dir}"/"${source_dir}"
fi
fi
prefix="/usr"
sysroot_dir="/sysroot"
cd "${build_dir}"/builds/${name}
configure
cd "${base_dir}"
}
do_build() {
default_recipe_steps
unset from_source
. "${base_dir}"/recipes/$1
make_dir "${build_dir}"/builds/${name}
if ! [ -z "${from_source}" ] || ! [ -z "${tarball_url}" ] || ! [ -z "${git_url}" ] || ! [ -z "${hg_url}" ] || ! [ -z "${source_dir}" ]; then
if ! [ -z "${from_source}" ]; then
version=$(unset version && source_source_recipe ${from_source} && echo "$version")
source_dir="$(unset source_dir && source_source_recipe ${from_source} && echo "$source_dir")"
else
from_source=${name}
fi
if [ -z "${source_dir}" ]; then
source_dir="${base_dir}"/sources/${from_source}
else
source_dir="${base_dir}"/"${source_dir}"
fi
fi
prefix="/usr"
sysroot_dir="/sysroot"
cd "${build_dir}"/builds/${name}
build
cd "${base_dir}"
}
do_package() {
default_recipe_steps
unset from_source
. "${base_dir}"/recipes/$1
dest_dir="${build_dir}"/pkgs/${name}
rm -rf "${dest_dir}"
make_dir "${dest_dir}"
if ! [ -z "${from_source}" ] || ! [ -z "${tarball_url}" ] || ! [ -z "${git_url}" ] || ! [ -z "${hg_url}" ] || ! [ -z "${source_dir}" ]; then
if ! [ -z "${from_source}" ]; then
version=$(unset version && source_source_recipe ${from_source} && echo "$version")
source_dir="$(unset source_dir && source_source_recipe ${from_source} && echo "$source_dir")"
else
from_source=${name}
fi
if [ -z "${source_dir}" ]; then
source_dir="${base_dir}"/sources/${from_source}
else
source_dir="${base_dir}"/"${source_dir}"
fi
fi
prefix="/usr"
sysroot_dir="/sysroot"
make_dir "${dest_dir}${prefix}"
cd "${build_dir}"/builds/${name}
package
# Remove libtool files
for i in $(find "${dest_dir}${prefix}" -name "*.la"); do
rm -rvf $i
done
xbps_deps=""
for dep in ${deps}; do
bootstrap_pkg=$(unset bootstrap_pkg && . "${base_dir}"/recipes/${dep} && echo "${bootstrap_pkg}")
if [ "${bootstrap_pkg}" = "yes" ]; then
continue
fi
xbps_deps="${xbps_deps} ${dep}>=0.0"
done
cd "${build_dir}"/pkgs
XBPS_ARCH=invalid \
XBPS_TARGET_ARCH="${JINX_ARCH}" \
"$JINX_CACHE_DIR"/xbps-bin/xbps-create \
-A $JINX_ARCH \
-s ${name} \
-n ${name}-${version}_${revision} \
-D "${xbps_deps}" \
"${dest_dir}"
rm -rf "${dest_dir}"
cd "${base_dir}"
}
precont_fetch() {
source_source_recipe $1
get_real_source_dir
[ -d "${source_dir}" ] && return
cross_compile=yes
allow_network="yes"
prepare_container
run_in_container internal-cont-fetch $1
destroy_container
}
precont_patch() {
source_source_recipe $1
get_real_source_dir
[ -f "${base_dir}"/sources/$1.patched ] && return
cross_compile=yes
allow_network="yes"
prepare_container
run_in_container internal-cont-patch $1
destroy_container
}
do_source() {
source_source_recipe $1
get_real_source_dir
"${script}" internal-precont-fetch $1
"${script}" internal-precont-patch $1
[ -f "${base_dir}"/sources/$1.prepared ] && return
cross_compile=yes