-
Notifications
You must be signed in to change notification settings - Fork 651
Expand file tree
/
Copy pathplease.sh
More file actions
executable file
·1051 lines (950 loc) · 29.1 KB
/
please.sh
File metadata and controls
executable file
·1051 lines (950 loc) · 29.1 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
# This script is meant to help maintain Git for Windows. It automates large
# parts of the release engineering.
#
# Most of these functions are called from automation, i.e. from Azure Pipelines
# and from GitHub workflows
# Note: functions whose arguments are documented on the function name's own
# line are actually subcommands, and running this script without any argument
# will list all subcommands.
die () {
printf "$@" >&2
exit 1
}
# Never allow the SDKs to change directory to $HOME
export CHERE_INVOKING=1
# Never allow ORIGINAL_PATH to mess up our PATH
unset ORIGINAL_PATH
# Do not follow MSYS2's switch to zstd, at least for now
PKGEXT='.pkg.tar.xz'
export PKGEXT
SRCEXT='.src.tar.gz'
export SRCEXT
# In MinGit, there is no `cygpath`...
# We really only use -w, -am and -au in please.sh, so that's what we
# support here
cygpath () { # [<short-options>] <path>
test $# = 2 ||
die "This minimal cygpath drop-in cannot handle '%s'\n" "$*"
case "$1" in
-w)
case "$2" in
/[a-zA-Z]/*)
echo "$2" |
sed -e 's|^/\(.\)\(.*\)|\u\1:\2|' -e 's|/|\\|g'
;;
[a-zA-Z]:[\\/]*)
echo "$2" |
sed -e 's|^\(.\)|\u\1|' -e 's|/|\\|g'
;;
/*)
echo "$(cd / && pwd -W)$2" |
sed -e 's|/|\\|g'
;;
*)
echo "$2" |
sed -e 's|/|\\|g'
;;
esac
;;
-am)
case "$2" in
/[a-zA-Z]/*)
echo "$2" |
sed -e 's|^/\(.\)\(.*\)|\u\1:\2|' -e 's|\\|/|g'
;;
[a-zA-Z]:[\\/]*)
echo "$2" |
sed -e 's|^\(.\)|\u\1|' -e 's|\\|/|g'
;;
/*)
echo "$(cd / && pwd -W)$2" |
sed -e 's|\\|/|g'
;;
*)
echo "$(pwd -W)/$2" |
sed -e 's|\\|/|g' -e 's|//*|/|g'
;;
esac
;;
-au)
case "$2" in
/[a-zA-Z]/*)
echo "$2" |
sed -e 's|^/\(.\)\(.*\)|/\l\1\2|' -e 's|\\|/|g'
;;
[a-zA-Z]:[\\/]*)
echo "$2" |
sed -e 's|^\(.\):|/\l\1|' -e 's|\\|/|g'
;;
/*)
echo "$2" |
sed -e 's|\\|/|g'
;;
*)
echo "$(pwd)/$2" |
sed -e 's|\\|/|g' -e 's|//*|/|g'
;;
esac
;;
*)
die "Unhandled cygpath option: '%s'\n" "$1"
;;
esac
}
sdk_path () { # <bitness>
result="$(git config windows.sdk"$1".path)" || {
result="C:/git-sdk-$1" && test -e "$result" ||
die "%s\n\n\t%s\n%s\n" \
"No $1-bit Git for Windows SDK found at location:" \
"C:/git-sdk-$1" \
"Config variable to override: windows.sdk$1.path"
}
echo "$result"
}
sdk64="$(sdk_path 64)"
sdk32="$(sdk_path 32)"
in_use () { # <sdk> <path>
test -n "$(case "$1" in
"$sdk32") "$1/mingw32/bin/WhoUses.exe" -m "$1$2";;
*) "$1/mingw64/bin/WhoUses.exe" -m "$1$2";;
esac | grep '^[^-P]')"
}
# require_not_in_use <sdk> <path>
require_not_in_use () {
! in_use "$@" ||
die "%s: in use\n" "$1/$2"
}
independent_shell=
is_independent_shell () { #
test -n "$independent_shell" || {
normalized64="$(cygpath -w "$sdk64")"
normalized32="$(cygpath -w "$sdk32")"
case "$(cygpath -w "$(which sh.exe)")" in
"$normalized64\\"*|"$normalized32\\"*)
independent_shell=f
;;
*)
independent_shell=t
;;
esac
}
test t = "$independent_shell"
}
mount_sdks () { #
test -d /sdk32 || mount "$sdk32" /sdk32
test -d /sdk64 || mount "$sdk64" /sdk64
}
require_clean_worktree () {
git update-index --ignore-submodules --refresh &&
git diff-files --ignore-submodules &&
git diff-index --cached --ignore-submodules HEAD ||
die "%s not up-to-date\n" "$sdk$pkgpath"
}
fast_forward () {
if test -d "$2"/.git
then
git -C "$1" fetch "$2" refs/heads/main
else
git -C "$1" fetch "$2"/.. refs/heads/main
fi &&
git -C "$1" merge --ff-only "$3" &&
test "a$3" = "a$(git -C "$1" rev-parse --verify HEAD)"
}
# up_to_date <path>
up_to_date () {
# test that repos at <path> are up-to-date in both 64-bit and 32-bit
pkgpath="$1"
(cd "$pkgpath" && sdk= && require_clean_worktree)
commit32="$(cd "$sdk32$pkgpath" && git rev-parse --verify HEAD)" &&
commit64="$(cd "$sdk64$pkgpath" && git rev-parse --verify HEAD)" ||
die "Could not determine HEAD commit in %s\n" "$pkgpath"
if test "a$commit32" != "a$commit64"
then
fast_forward "$sdk32$pkgpath" "$sdk64$pkgpath" "$commit64" ||
fast_forward "$sdk64$pkgpath" "$sdk32$pkgpath" "$commit32" ||
die "%s: commit %s (32-bit) != %s (64-bit)\n" \
"$pkgpath" "$commit32" "$commit64"
fi
}
whatis () {
git show -s --pretty='tformat:%h (%s, %ad)' --date=short "$@"
}
is_rebasing () {
test -d "$(git rev-parse --git-path rebase-merge)"
}
has_merge_conflicts () {
test -n "$(git ls-files --unmerged)"
}
pacman_helper () {
"$sdk64/git-cmd.exe" --command=usr\\bin\\bash.exe -l \
"$sdk64/usr/src/build-extra/pacman-helper.sh" "$@"
}
bundle_pdbs () { # [--directory=<artifacts-directory] [--unpack=<directory>] [--arch=<arch>] [<package-versions>]
packages="mingw-w64-git-pdb mingw-w64-curl-pdb mingw-w64-openssl-pdb"
artifactsdir=
architectures=
unpack=
while case "$1" in
--directory=*)
artifactsdir="$(cygpath -am "${1#*=}")" || exit
test -d "$artifactsdir" ||
mkdir "$artifactsdir" ||
die "Could not create artifacts directory: %s\n" "$artifactsdir"
;;
--arch=*)
architectures="${architectures:+$architectures }${1#*=}"
;;
--unpack=*)
unpack="$(cygpath -am "${1#*=}")" || exit
test -d "$unpack" ||
die "Not a directory: %s\n" "$unpack"
;;
--*)
die "Unknown option: %s\n" "$1"
;;
*)
break
;;
esac; do shift; done
test $# -le 1 ||
die "Extra options: %s\n" "$*"
test -z "$unpack" || test -z "$artifactsdir" ||
die "--unpack and --directory are mutually exclusive\n"
test -n "$unpack" ||
test -n "$artifactsdir" ||
artifactsdir="$(cygpath -am "$HOME")" || exit
test -n "$architectures" ||
architectures="i686 x86_64 aarch64"
versions="$(case $# in 0) pacman -Q;; 1) cat "$1";; esac |
sed 's/^\(mingw-w64\)\(-clang-[^-]*\|-[^-]*\)/\1/' | sort | uniq)"
test -n "$versions" ||
die 'Could not obtain package versions\n'
git_version="$(echo "$versions" | sed -n 's/^mingw-w64-git //p')"
test -n "$git_version" ||
die "Could not determine Git version"
dir="${this_script_path:+$(cygpath -au \
"${this_script_path%/*}")/}"cached-source-packages
test -n "$unpack" ||
unpack=$dir/.unpack
url=https://raw.githubusercontent.com/git-for-windows/pacman-repo/refs/heads
mkdir -p "$dir" ||
die "Could not create '%s'\n" "$dir"
for arch in $architectures
do
echo "Unpacking .pdb files for $arch..." >&2
case $arch in
x86_64)
oarch=x86_64
pacman_arch=x86_64
artifact_suffix=64-bit
;;
i686)
oarch=i686
pacman_arch=i686
artifact_suffix=32-bit
;;
aarch64)
oarch=aarch64
pacman_arch=clang-aarch64
artifact_suffix=arm64
;;
*)
die "Unhandled architecture: $arch"
;;
esac
test -z "$artifactsdir" ||
test ! -d $unpack ||
rm -rf $unpack ||
die 'Could not remove %s\n' "$unpack"
mkdir -p $unpack
for package in $packages
do
name=${package%-*}
version=$(echo "$versions" | sed -n "s/^$name //p")
if test -z "$version"
then
# Fall back to mingw-w64-curl-winssl if mingw-w64-curl is not installed
if test mingw-w64-curl = "$name"
then
name=mingw-w64-curl-winssl
package=$name-pdb
version=$(echo "$versions" | sed -n "s/^$name //p")
fi
test -n "$version" ||
die "Package $name not installed?!?"
fi
case "$package" in
mingw-w64-*)
tar=mingw-w64-$pacman_arch-${package#mingw-w64-}-$version-any.pkg.tar.xz
dir2="/usr/src/MINGW-packages/$name"
;;
*)
tar=$package-$version-$arch.pkg.tar.xz
test i686 = $arch &&
dir2="$sdk32/usr/src/MSYS2-packages/$name" ||
dir2="$sdk64/usr/src/MSYS2-packages/$name"
;;
esac
test -f "$dir/$tar" ||
if test -f "$dir2/$tar"
then
cp "$dir2/$tar" "$dir/$tar" ||
die 'Could not copy %s (%d)\n' "$tar" $?
else
echo "Retrieving $tar..." >&2
curl -sfo "$dir/$tar" $url/$oarch/$tar
case $? in
0) ;; # okay
56)
while test 56 = $?
do
curl -sfo "$dir/$tar" \
$url/$oarch/$tar ||
die "curl error %s (%d)\n" \
"$tar" $?
done
;;
*)
die 'curl error %s (%d)\n' "$tar" $?
;;
esac
fi
(cd "$unpack" &&
"/git-cmd.exe" --command=usr\\bin\\sh.exe -l -c \
"tar --wildcards -xf \"$dir/$tar\" \\*.pdb") ||
die 'Could not unpack .pdb files from %s\n' "$tar"
done
test -n "$artifactsdir" || continue
zip=pdbs-for-git-$artifact_suffix-$git_version.zip &&
echo "Bundling .pdb files for $artifact_suffix..." >&2
(cd "$unpack" &&
"/git-cmd.exe" --command=usr\\bin\\sh.exe -l -c \
"7z a -mx9 \"$artifactsdir/$zip\" *") &&
echo "Created $artifactsdir/$zip" >&2 ||
die 'Could not create %s for %s\n' "$zip" "$arch"
done
}
create_sdk_artifact () { # [--out=<directory>] [--git-sdk=<directory>] [--architecture=(x86_64|i686|aarch64|auto)] [--bitness=(32|64)] [--force] <name>
git_sdk_path=/
output_path=
force=
architecture=auto
bitness=
keep_worktree=
while case "$1" in
--out|-o)
shift
output_path="$(cygpath -am "$1")" || exit
;;
--out=*|-o=*)
output_path="$(cygpath -am "${1#*=}")" || exit
;;
-o*)
output_path="$(cygpath -am "${1#-?}")" || exit
;;
--git-sdk|--sdk|-g)
shift
git_sdk_path="$(cygpath -am "$1")" || exit
;;
--git-sdk=*|--sdk=*|-g=*)
git_sdk_path="$(cygpath -am "${1#*=}")" || exit
;;
-g*)
git_sdk_path="$(cygpath -am "${1#-?}")" || exit
;;
--bitness|-b)
shift
bitness="$1"
;;
--bitness=*|-b=*)
bitness="${1#*=}"
echo "WARNING: using --bitness or -b is deprecated. Please use --architecture instead."
;;
-b*)
bitness="${1#-?}"
echo "WARNING: using --bitness or -b is deprecated. Please use --architecture instead."
;;
--architecture=*|-a=*)
architecture="${1#*=}"
;;
-a*)
architecture="${1#-?}"
;;
--force|-f)
force=t
;;
--keep-worktree)
keep_worktree=t
;;
--no-keep-worktree)
keep_worktree=
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 1 ||
die "Expected one argument, got $#: %s\n" "$*"
test -n "$output_path" ||
output_path="$(cygpath -am "$1")"
if test -n "$bitness"
then
case "$bitness" in
32)
architecture=i686
;;
64)
architecture=x86_64
;;
*) die "Unhandled bitness: %s\n" "$bitness";;
esac
elif test auto = "$architecture"
then
if git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:clangarm64 2>/dev/null
then
architecture=aarch64
elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/i686-pc-cygwin 2>/dev/null
then
architecture=i686
elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/i686-pc-msys 2>/dev/null
then
architecture=i686
elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/x86_64-pc-cygwin 2>/dev/null
then
architecture=x86_64
elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/x86_64-pc-msys 2>/dev/null
then
architecture=x86_64
else
die "'%s' is neither 32-bit nor 64-bit SDK?!?" "$git_sdk_path"
fi
elif test -z "$architecture"
then
die "Either --architecture or --bitness must be provided for this function to work."
fi
case "$architecture" in
x86_64)
MSYSTEM=MINGW64
PREFIX="/mingw64"
# TODO update to git-sdk-amd64 after the repo has been updated
SDK_REPO="git-sdk-64"
;;
i686)
MSYSTEM=MINGW32
PREFIX="/mingw32"
# TODO update to git-sdk-x86 after the repo has been updated
SDK_REPO="git-sdk-32"
;;
aarch64)
MSYSTEM=CLANGARM64
PREFIX="/clangarm64"
SDK_REPO="git-sdk-arm64"
;;
*) die "Unhandled architecture: %s\n" "$architecture";;
esac
mode=
case "$1" in
minimal|git-sdk-minimal) mode=minimal-sdk;;
full) mode=full-sdk;;
minimal-sdk|makepkg-git|build-installers|full-sdk) mode=$1;;
*) die "Unhandled artifact: '%s'\n" "$1";;
esac
test ! -d "$output_path" ||
if test -z "$force"
then
die "Directory exists already: '%s'\n" "$output_path"
elif test -f "$output_path/.git"
then
git -C "$(git -C "$output_path" rev-parse --git-common-dir)" worktree remove -f "$(cygpath -am "$output_path")"
else
rm -rf "$output_path"
fi ||
die "Could not remove '%s'\n" "$output_path"
if test -d "$git_sdk_path"
then
test ! -f "${git_sdk_path%/}/.git" ||
git_sdk_path="$(git -C "${git_sdk_path%/}" rev-parse --git-dir)"
test ! -d "${git_sdk_path%/}/.git" ||
git_sdk_path="${git_sdk_path%/}/.git"
test true = "$(git -C "$git_sdk_path" rev-parse --is-inside-git-dir)" ||
die "Not a Git repository: '%s'\n" "$git_sdk_path"
else
test -z "$architecture" ||
die "No SDK found at '%s'; Please use \`--architecture=<a>\` to indicate which SDK to use" "$git_sdk_path"
test "z$git_sdk_path" != "z${git_sdk_path%.git}" ||
git_sdk_path="$git_sdk_path.git"
git clone --depth 1 --bare https://github.com/git-for-windows/$SDK_REPO "$git_sdk_path"
fi
test full-sdk != "$mode" || {
mkdir -p "$output_path" &&
git -C "$git_sdk_path" archive --format=tar HEAD -- ':(exclude)ssl' |
xz -9 >"$output_path"/$SDK_REPO.tar.xz &&
echo "$SDK_REPO.tar.xz written to '$output_path'" >&2 ||
die "Could not write $SDK_REPO.tar.xz to '%s'\n" "$output_path"
return 0
}
git -C "$git_sdk_path" config core.repositoryFormatVersion 1 &&
git -C "$git_sdk_path" config extensions.worktreeConfig true &&
git -C "$git_sdk_path" worktree add --detach --no-checkout "$output_path" HEAD &&
sparse_checkout_file="$(git -C "$output_path" rev-parse --git-path info/sparse-checkout)" &&
git -C "$output_path" config --worktree core.sparseCheckout true &&
git -C "$output_path" config --worktree core.bare false &&
mkdir -p "${sparse_checkout_file%/*}" &&
case "$mode" in
build-installers)
cat <<-\EOF >"$sparse_checkout_file"
# Minimal `sh`
/git-cmd.exe
/usr/bin/sh.exe
/usr/bin/msys-2.0.dll
/etc/nsswitch.conf
# Pacman
/usr/bin/pacman.exe
/usr/bin/pactree.exe
/usr/bin/msys-gpg*.dll
/usr/bin/gpg.exe
/usr/bin/gpgconf.exe
/usr/bin/msys-gcrypt*.dll
/usr/bin/msys-z.dll
/usr/bin/msys-sqlite*.dll
/usr/bin/msys-bz2*.dll
/usr/bin/msys-assuan*.dll
/etc/pacman*
/usr/ssl/certs/ca-bundle.crt
/usr/share/pacman/
/var/lib/pacman/local/
/update-via-pacman.ps1
# Some other utilities required by `make-file-list.sh`
/usr/bin/cat.exe
/usr/bin/dirname.exe
/usr/bin/grep.exe
/usr/bin/ls.exe
/usr/bin/rm.exe
/usr/bin/sed.exe
/usr/bin/sort.exe
/usr/bin/uniq.exe
/usr/bin/msys-iconv-*.dll
/usr/bin/msys-intl-*.dll
/usr/bin/msys-pcre*.dll
/usr/bin/msys-gcc_s-*.dll
# For the libuuid/libunistring check
/usr/bin/msys-apr*.dll
/usr/bin/msys-unistring*.dll
/usr/bin/msys-gnutls*.dll
# For the /etc/bash.bash_logout check
/etc/bash.bash_logout
# markdown, to render the release notes
/usr/bin/markdown
# gettext (for makepkg)
/usr/bin/gettext.exe
/usr/bin/xgettext.exe
/usr/bin/msys-gettext*.dll
# The `error_highlight` Ruby gem, needed by `asciidoctor`
*error_highlight*
# Files to include into the installer/Portable Git/MinGit
EOF
git -C "$output_path" checkout -- &&
mkdir -p "$output_path/tmp" &&
printf 'export MSYSTEM=%s\nexport PATH=%s/bin:/usr/bin/:/usr/bin/core_perl:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem\n' "$MSYSTEM" "$PREFIX" >"$output_path/etc/profile" &&
mkdir -p "${output_path}${PREFIX}/bin" &&
case $architecture in
i686)
# copy git.exe, for the libssp test
git -C "$output_path" show HEAD:mingw32/bin/git.exe \
>"$output_path/mingw32/bin/git.exe" &&
# Work around an outdated i686 gnupg/gnutls build that depends on a hence-updated libunistring
if test ! -e "$output_path/usr/bin/msys-unistring-2.dll" -a \
-e "$output_path/usr/bin/msys-unistring-5.dll" -a \
-e "$output_path/usr/bin/msys-gnutls-30.dll" &&
grep msys-unistring-2 "$output_path/usr/bin/msys-gnutls-30.dll"
then
cp "$output_path/usr/bin/msys-unistring-5.dll" \
"$output_path/usr/bin/msys-unistring-2.dll"
fi &&
ARCH=i686 "$output_path/git-cmd.exe" --command=usr\\bin\\sh.exe -lx \
"${this_script_path%/*}/make-file-list.sh" |
# escape the `[` in `[.exe`
sed -e 's|[][]|\\&|g' >>"$sparse_checkout_file" &&
if git -C "$git_sdk_path" rev-parse -q --verify HEAD:.sparse/makepkg-git >/dev/null
then
printf '\n' >>"$sparse_checkout_file" &&
git -C "$git_sdk_path" show HEAD:.sparse/makepkg-git >>"$sparse_checkout_file"
else
cat <<-EOF >>"$sparse_checkout_file"
# For code-signing
/mingw32/bin/osslsigncode.exe
/mingw32/bin/libgsf-[0-9]*.dll
/mingw32/bin/libglib-[0-9]*.dll
/mingw32/bin/libgobject-[0-9]*.dll
/mingw32/bin/libgio-[0-9]*.dll
/mingw32/bin/libxml2-[0-9]*.dll
/mingw32/bin/libgmodule-[0-9]*.dll
/mingw32/bin/libzstd*.dll
/mingw32/bin/libffi-[0-9]*.dll
EOF
fi
;;
*)
git -C "$git_sdk_path" show HEAD:.sparse/minimal-sdk >"$sparse_checkout_file" &&
printf '\n' >>"$sparse_checkout_file" &&
git -C "$git_sdk_path" show HEAD:.sparse/makepkg-git >>"$sparse_checkout_file" &&
if test x86_64 = $architecture
then
printf '\n' >>"$sparse_checkout_file" &&
git -C "$git_sdk_path" show HEAD:.sparse/makepkg-git-i686 >>"$sparse_checkout_file"
fi &&
printf '\n# For the /etc/msystem.d/ check\n/etc/msystem.d/\n\n' >>"$sparse_checkout_file" &&
printf '\n# markdown, to render the release notes\n/usr/bin/markdown\n\n' >>"$sparse_checkout_file" &&
ARCH=$architecture "$output_path/git-cmd.exe" --command=usr\\bin\\sh.exe -l \
"${this_script_path%/*}/make-file-list.sh" | sed -e 's|[][]|\\&|g' -e 's|^|/|' >>"$sparse_checkout_file"
;;
esac &&
rm "$output_path/etc/profile" &&
cat <<-EOF >>"$sparse_checkout_file" &&
# 7-Zip
$PREFIX/bin/7z.dll
$PREFIX/bin/7z.exe
# WinToast
$PREFIX/bin/wintoast.exe
# BusyBox
$PREFIX/bin/busybox.exe
EOF
mkdir -p "$output_path/.sparse" &&
cp "$sparse_checkout_file" "$output_path/.sparse/build-installers"
;;
*)
git -C "$git_sdk_path" show HEAD:.sparse/minimal-sdk >"$sparse_checkout_file" &&
if test makepkg-git = $mode
then
printf '\n' >>"$sparse_checkout_file" &&
git -C "$git_sdk_path" show HEAD:.sparse/$mode >>"$sparse_checkout_file" &&
if test x86_64 = $architecture
then
printf '\n' >>"$sparse_checkout_file" &&
git -C "$git_sdk_path" show HEAD:.sparse/$mode-i686 >>"$sparse_checkout_file"
fi
fi
;;
esac &&
git -C "$output_path" checkout -- &&
if test ! -f "$output_path/etc/profile"
then
if test minimal-sdk = $mode
then
printf 'export MSYSTEM=%s\nexport PATH=%s/bin:/usr/bin/:/usr/bin/core_perl:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem\n' "$MSYSTEM" "$PREFIX" >"$output_path/etc/profile"
elif test makepkg-git = $mode
then
cat >"$output_path/etc/profile" <<-\EOF
case "$SYSTEMROOT" in
[A-Za-z]:*)
SYSTEMROOT_MSYS=/${SYSTEMROOT%%:*}${SYSTEMROOT#?:}
SYSTEMROOT_MSYS=${SYSTEMROOT_MSYS//\\/\/}
;;
*)
SYSTEMROOT_MSYS=${SYSTEMROOT//\\/\/}
;;
esac
if test MSYS = "$MSYSTEM"
then
PATH=/usr/bin:/usr/bin/core_perl:$SYSTEMROOT_MSYS/system32:$SYSTEMROOT_MSYS
elif test CLANGARM64 = "$MSYSTEM"
then
PATH=/clangarm64/bin:/usr/bin:/usr/bin/core_perl:$SYSTEMROOT_MSYS/system32:$SYSTEMROOT_MSYS
elif test MINGW32 = "$MSYSTEM"
then
PATH=/mingw32/bin:/mingw64/bin:/usr/bin:/usr/bin/core_perl:$SYSTEMROOT_MSYS/system32:$SYSTEMROOT_MSYS
else
export MSYSTEM=MINGW64
PATH=/mingw64/bin:/usr/bin:/usr/bin/core_perl:$SYSTEMROOT_MSYS/system32:$SYSTEMROOT_MSYS
fi
# These Cygwin-style pseudo symlinks are marked as system files
# and that attribute cannot be preserved in .zip archives
test -h /dev/fd || {
ln -s /proc/self/fd /dev/
test -h /dev/stdin || ln -s /proc/self/fd/0 /dev/stdin
test -h /dev/stdout || ln -s /proc/self/fd/1 /dev/stdout
test -h /dev/stderr || ln -s /proc/self/fd/2 /dev/stderr
}
EOF
fi
fi &&
if test makepkg-git = $mode && test ! -x "$output_path/usr/bin/git"
then
printf '#!/bin/sh\n\nexec %s/bin/git.exe "$@"\n' \
"$PREFIX" >"$output_path/usr/bin/git"
fi &&
if test makepkg-git = $mode && ! grep -q http://docbook.sourceforge.net/release/xsl-ns/current "$output_path/etc/xml/catalog"
then
# Slightly dirty workaround for missing docbook-xsl-ns
(cd "$output_path/usr/share/xml/" &&
test -d docbook-xsl-ns-1.78.1 ||
curl -L https://sourceforge.net/projects/docbook/files/docbook-xsl-ns/1.78.1/docbook-xsl-ns-1.78.1.tar.bz2/download |
tar xjf -) &&
sed -i -e 's|C:/git-sdk-64-ci||g' -e '/<\/catalog>/i\
<rewriteSystem systemIdStartString="http://docbook.sourceforge.net/release/xsl-ns/current" rewritePrefix="/usr/share/xml/docbook-xsl-ns-1.78.1"/>\
<rewriteURI uriStartString="http://docbook.sourceforge.net/release/xsl-ns/current" rewritePrefix="/usr/share/xml/docbook-xsl-ns-1.78.1"/>' \
"$output_path/etc/xml/catalog"
fi &&
if test -z "$keep_worktree"
then
rm -r "$(cat "$output_path/.git" | sed 's/^gitdir: //')" &&
rm "$output_path/.git"
fi &&
echo "Output written to '$output_path'" >&2 ||
die "Could not write artifact at '%s'\n" "$output_path"
}
find_mspdb_dll () { #
for v in 140 120 110 100 80
do
type -p mspdb$v.dll 2>/dev/null && return 0
done
return 1
}
build_mingw_w64_git () { # [--only-i686] [--only-x86_64] [--only-aarch64] [--skip-test-artifacts] [--skip-doc-man] [--skip-doc-html] [--force] [<revision>]
output_path=
sed_makepkg_e=
force=
src_pkg=
maybe_sync=
while case "$1" in
--only-i686|--only-32-bit)
MINGW_ARCH=mingw32
export MINGW_ARCH
;;
--only-x86_64|--only-64-bit)
MINGW_ARCH=mingw64
export MINGW_ARCH
;;
--only-aarch64)
MINGW_ARCH=clangarm64
export MINGW_ARCH
;;
--skip-test-artifacts)
sed_makepkg_e="$sed_makepkg_e"' -e s/"\${MINGW_PACKAGE_PREFIX}-\${_realname}-test-artifacts"//'
;;
--skip-doc-man)
sed_makepkg_e="$sed_makepkg_e"' -e s/"\${MINGW_PACKAGE_PREFIX}-\${_realname}-doc-man"//'
;;
--skip-doc-html)
sed_makepkg_e="$sed_makepkg_e"' -e s/"\${MINGW_PACKAGE_PREFIX}-\${_realname}-doc-html"//'
;;
--reset-pkgrel)
sed_makepkg_e="$sed_makepkg_e"' -e s/^pkgrel=[0-9][0-9]*$/pkgrel=1/'
;;
--build-src-pkg)
src_pkg=t
;;
--force)
force=--force
;;
--out|--output|-o)
shift
output_path="$(cygpath -am "$1")" || exit
;;
--out=*|--output=*|-o=*)
output_path="$(cygpath -am "${1#*=}")" || exit
;;
-o*)
output_path="$(cygpath -am "${1#-?}")" || exit
;;
--maybe-sync|-s)
maybe_sync="-s --noconfirm"
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# -le 1 ||
die "Expected at most one argument, got $#: %s\n" "$*"
git_src_dir="/usr/src/MINGW-packages/mingw-w64-git/src/git"
test -d ${git_src_dir%/src/git} ||
git clone --depth 1 --single-branch -b main https://github.com/git-for-windows/MINGW-packages /usr/src/MINGW-packages ||
die "Could not clone MINGW-packages\n"
tag="$(git for-each-ref --count=1 --sort=-taggerdate --format '%(refname:short)' --points-at="${1:-HEAD}" 'refs/tags/v[0-9]*')"
test -n "$tag" || {
tag=$(git describe --match=v* "${1:-HEAD}" | sed 's/-.*//').$(date +%Y%m%d%H%M%S) &&
git tag $tag "${1:-HEAD}"
} ||
die "Could not create tag\n"
test -d ${git_src_dir%/src/git}/git ||
git clone --bare https://github.com/git-for-windows/git.git ${git_src_dir%/src/git}/git ||
die "Could not initialize %s\n" ${git_src_dir%/src/git}/git
sha256sum=$(git -c core.eol=lf -c core.autoCRLF=false -c core.abbrev=no archive --format tar $tag | sha256sum.exe) &&
test -n "$sha256sum" ||
die "Could not compute SHA-256 sum for %s\n" $tag
sed -e "s/^tag=.*/tag=${tag#v}/" $sed_makepkg_e \
-e "s/^\(sha256sums=..\)[0-9a-f]\{64\}/\1${sha256sum%% *}/" \
<${git_src_dir%/src/git}/PKGBUILD >${git_src_dir%/src/git}/PKGBUILD.$tag ||
die "Could not write %s\n" ${git_src_dir%/src/git}/PKGBUILD.$tag
case "$tag" in
*[-:/\ ]*)
# This is a prerelease
sed -i -e '/^pkgver *() {/,/^}$/s/^/# /' \
-e 's/^\(pkgver=\).*/\1'"$(echo "${tag#v}" | tr ':/ -' .)"/ \
${git_src_dir%/src/git}/PKGBUILD.$tag
;;
esac
test -d ${git_src_dir%/src/git}/git ||
git clone --bare https://github.com/git-for-windows/git.git ${git_src_dir%/src/git}/git ||
die "Could not initialize %s\n" ${git_src_dir%/src/git}/git
test -d $git_src_dir || {
git -c core.autoCRLF=false clone --reference ${git_src_dir%/src/git}/git https://github.com/git-for-windows/git $git_src_dir &&
git -C $git_src_dir config core.autoCRLF false
} ||
die "Could not initialize %s\n" $git_src_dir
git push ${git_src_dir%/src/git}/git $tag &&
git push $git_src_dir $tag ||
die "Could not push %s\n" $tag
# Work around bug where the incorrect xmlcatalog.exe wrote /etc/xml/catalog
sed -i -e 's|C:/git-sdk-64-ci||g' /etc/xml/catalog
test true != "$GITHUB_ACTIONS" && # GitHub Actions' agents have the mspdb.dll, and cv2pdb finds it
test -z "$SYSTEM_COLLECTIONURI$SYSTEM_TASKDEFINITIONSURI" && # Same for Azure Pipelines
test "$MINGW_ARCH" != "clangarm64" && # We don't need cv2pdb when compiling using Clang/LLVM
! find_mspdb_dll >/dev/null && {
WITH_PDBS=
WITHOUT_PDBS=1
} || {
WITH_PDBS=1
WITHOUT_PDBS=
}
export WITH_PDBS
export WITHOUT_PDBS
(if test -n "$(git config alias.signtool)"
then
d="$(git rev-parse --absolute-git-dir)"
export SIGNTOOL="git ${d:+--git-dir="$d"} signtool"
fi &&
cd ${git_src_dir%/src/git}/ &&
_DEFAULT_EDITOR=vim MAKEFLAGS=${MAKEFLAGS:--j$(nproc)} makepkg-mingw $maybe_sync $force -p PKGBUILD.$tag &&
if test -n "$src_pkg"
then
git --git-dir src/git/.git archive --prefix git/ -o git-$tag.tar.gz $tag &&
sha256sum="$(sha256sum.exe git-$tag.tar.gz)" &&
oid="$(git --git-dir src/git/.git rev-parse $tag^0)" &&
sed -e 's/^source.*git+https.*/source=("git-'$tag'.tar.gz"/' \
-e "s/^\(sha256sums=..\)[0-9a-f]\{64\}/\1${sha256sum%% *}/" \
-e '/^prepare /{N;s/$/&& sed -i s\/GIT_BUILT_FROM_COMMIT\/\\\"'$oid'\\\"\/ version.c \&\&/}' \
<PKGBUILD.$tag >PKGBUILD.src &&
MAKEFLAGS=${MAKEFLAGS:--j$(nproc)} MINGW_ARCH=mingw64 makepkg-mingw $force --allsource -p PKGBUILD.src
fi) ||
die "Could not build mingw-w64-git\n"
test -z "$output_path" || {
pkgpattern="$(bash -c "cd ${git_src_dir%/src/git}/ && . PKGBUILD.$tag && echo \$pkgver-\$pkgrel")" &&
mkdir -p "$output_path" &&
{ test -z "$src_pkg" || cp ${git_src_dir%/src/git}/*-"$pkgpattern".src.tar.gz "$output_path/"; } &&
cp ${git_src_dir%/src/git}/*-"$pkgpattern"-any.pkg.tar.xz ${git_src_dir%/src/git}/PKGBUILD.$tag "$output_path/"
} ||
die "Could not copy artifact(s) to %s\n" "$output_path"
}
# This function does not "clean up" after installing the packages
make_installers_from_mingw_w64_git () { # [--pkg=<package>[,<package>...]] [--version=<version>] [--installer] [--portable] [--mingit] [--mingit-busybox] [--nuget] [--nuget-mingit] [--archive] [--include-arm64-artifacts=<path>]
modes=
install_package=
output=
output_path=
version=0-test
include_arm64_artifacts=
include_pdbs=
while case "$1" in
--pkg=*)
install_package="${install_package:+$install_package }$(echo "${1#*=}" | tr , ' ')"
for file in ${1#*=}
do
candidate="$(echo $file | sed -n 's/.*git-\([0-9][.0-9a-f]*\).*/\1/p')"
test 0-test != "$version" || test -z "$candidate" || version="$candidate"
done
;;
--pkg)
shift
install_package="${install_package:+$install_package }$(echo "$1" | tr , ' ')"
for file in $1
do
candidate="$(echo $file | sed -n 's/.*git-\([0-9][.0-9a-f]*\).*/\1/p')"
test 0-test != "$version" || test -z "$candidate" || version="$candidate"
done
;;
--version)
shift
version=$1
;;
--version=*)
version=${1#*=}
;;
--installer|--portable|--mingit|--mingit-busybox|--nuget|--nuget-mingit|--archive)
modes="${modes:+$modes }${1#--}"
;;
--only-installer|--only-portable|--only-mingit|--only-mingit-busybox|--only-nuget|--only-nuget-mingit|--only-archive)
modes="${1#--only-}"
;;
--out|--output|-o)
shift
output_path="$(cygpath -am "$1")"
output="--output=$output_path" || exit
;;
--out=*|--output=*|-o=*)
output_path="$(cygpath -am "${1#*=}")"
output="--output=$output_path" || exit
;;
-o*)
output_path="$(cygpath -am "${1#-?}")"
output="--output=$output_path" || exit
;;
--include-arm64-artifacts=*)
include_arm64_artifacts="$1"
;;
--include-pdbs)
include_pdbs=--include-pdbs
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# -eq 0 ||
die "Expected no argument, got $#: %s\n" "$*"
test -n "$modes" ||
modes=installer
mkdir -p "$output_path" ||
die "Could not make '%s/'\n" "$output_path"
test -z "$install_package" || {
eval pacman -U --noconfirm --overwrite=\\\* $install_package &&
(. /var/lib/pacman/local/*-git-extra-*/install && post_install)
} ||
die "Could not install packages: %s\n" "$install_package"