-
Notifications
You must be signed in to change notification settings - Fork 611
/
git-sdk.sh
executable file
·483 lines (456 loc) · 11.6 KB
/
git-sdk.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
# This profile.d script configures a few things for the Git SDK (but is
# excluded from the end user-facing Git for Windows).
# If both 32-bit and 64-bit Git for Windows SDK is installed next to each other,
# using the default directory names, mount them as /sdk32 and /sdk64,
# respectively, to make it easier to interact between the two.
rootdir="$(cygpath -w /)" &&
rootdir="${rootdir%\\}" &&
case "$rootdir" in
*\\git-sdk-32|*\\git-sdk-64)
otherarch=$((96-${rootdir##*-})) &&
if test ! -d /sdk$otherarch
then
othersdk="${rootdir%??}$otherarch"
test ! -d "$othersdk" ||
mount -o noacl "$othersdk" /sdk$otherarch 2>/dev/null
fi
;;
esac
sdk () {
case "$1" in
help|--help|-h)
cat >&2 <<-EOF
The 'sdk' shell function helps you to get up and running
with the Git for Windows SDK. The available subcommands are:
create-desktop-icon: install a desktop icon that starts the Git for
Windows SDK Bash.
cd <project>: initialize/update a worktree and cd into it. Known projects:
$(sdk valid_projects | sdk fmt_list)
init <project>: initialize and/or update a worktree. Known projects
are the same as for the 'cd' command.
build <project>: builds one of the following:
$(sdk valid_build_targets | sdk fmt_list)
edit <file>: edit a well-known file. Well-known files are:
$(sdk valid_edit_targets | sdk fmt_list)
reload: reload the 'sdk' function.
EOF
;;
welcome)
test -z "$MSYS_NO_PATHCONV" || cat >&2 <<-EOF
WARNING: You have the MSYS_NO_PATHCONV env var defined
Please consult the documentation, e.g. at
https://github.com/git-for-windows/build-extra/blob/HEAD/ReleaseNotes.md#known-issues
EOF
test -z "$GIT_SDK_WELCOME_SHOWN" || {
echo 'Reloaded the `sdk` function' >&2
return 0
}
cat >&2 <<-EOF
Welcome to the Git for Windows SDK!
The common tasks are automated via the \`sdk\` function;
See \`sdk help\` for details.
EOF
GIT_SDK_WELCOME_SHOWN=t
return 0
;;
create-desktop-icon)
force=t &&
while case "$1" in
--gentle) force=;;
'') break;;
-*) sdk die "Unknown option: %s\n" "$1"; return 1;;
esac; do shift; done &&
case "$MSYSTEM" in
MINGW32) shortcut_suffix=" 32-bit";;
MINGW64) shortcut_suffix=" 64-bit";;
CLANGARM64) shortcut_suffix=" arm64";;
MSYS)
case "$(uname -m)" in
i686) shortcut_suffix=" 32-bit";;
x86_64)
if test -d /clangarm64
then
shortcut_suffix=" arm64"
else
shortcut_suffix=" 64-bit"
fi
;;
*) shortcut_suffix=;;
esac
;;
*) shortcut_suffix=;;
esac &&
desktop_icon_path="Git SDK$shortcut_suffix.lnk" &&
desktop_icon_path="$(create-shortcut.exe -n --desktop-shortcut /git-bash.exe "$desktop_icon_path" |
sed -n 's/^destination: //p')" &&
if test -n "$force" || test ! -f "$desktop_icon_path"
then
create-shortcut.exe --icon-file /msys2.ico --work-dir \
/ /git-bash.exe "$desktop_icon_path"
fi
;;
die)
shift
echo "$*" >&2
return 1
;;
fmt_list)
fmt -w 64 | sed 's/^/\t/'
;;
# for completion
valid_commands)
echo "build cd create-desktop-icon init edit reload"
;;
valid_projects)
printf "%s " git git-extra msys2-runtime installer \
build-extra MINGW-packages MSYS2-packages \
mingw-w64-busybox \
mingw-w64-curl \
mingw-w64-cv2pdb \
mingw-w64-git \
mingw-w64-git-credential-manager \
mingw-w64-git-lfs \
mingw-w64-git-sizer \
mingw-w64-wintoast \
bash \
curl \
gawk \
git-flow \
gnupg \
heimdal \
mintty \
nodejs \
openssh \
openssl \
perl \
perl-HTML-Parser \
perl-Locale-Gettext \
perl-Net-SSLeay \
perl-TermReadKey \
perl-XML-Parser \
perl-YAML-Syck \
subversion \
tig
;;
valid_build_targets)
printf "%s " git-and-installer $(sdk valid_projects | tr ' ' '\n' |
grep -v '^\(build-extra\|\(MINGW\|MSYS2\)-packages\)')
;;
valid_edit_targets)
printf "%s " git-sdk.sh sdk.completion ReleaseNotes.md \
install.iss
;;
# for building
makepkg|makepkg-mingw)
cmd=$1; shift
WITHOUT_PDBS="$(! grep -q WITHOUT_PDBS PKGBUILD || sdk find_mspdb_dll || echo true)" \
MAKEFLAGS=${MAKEFLAGS:--j$(nproc)} PKGEXT='.pkg.tar.xz' $cmd --syncdeps --noconfirm --skipchecksums --skippgpcheck "$@"
;;
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
;;
# here start the commands
init-lazy)
case "$2" in
build-extra|git|MINGW-packages|MSYS2-packages)
src_dir=/usr/src/"$2"
src_cdup_dir="$src_dir"
test -d "$src_dir"/.git && return
mkdir -p "$src_dir" &&
git -C "$src_dir" init &&
git -C "$src_dir" config core.autocrlf false &&
git -C "$src_dir" remote add origin \
https://github.com/git-for-windows/"$2" ||
sdk die "Could not initialize $src_dir"
;;
msys2-runtime)
sdk init MSYS2-packages &&
(cd "$src_dir/$2" &&
test -d src/msys2-runtime ||
sdk makepkg --nobuild) &&
src_cdup_dir="$src_dir/$2" &&
src_dir="$src_cdup_dir/src/msys2-runtime" ||
return 1
;;
git-extra|git-for-windows-keyring|mingw-w64-cv2pdb|\
mingw-w64-git-lfs|\
mingw-w64-git-credential-manager|\
mingw-w64-git-sizer|mingw-w64-wintoast|installer)
sdk init-lazy build-extra &&
src_dir="$src_dir/$2" ||
return 1
;;
mingw-w64-*)
sdk init MINGW-packages &&
src_dir="$src_cdup_dir/$2" &&
test -d "$src_dir" ||
return 1
;;
*)
sdk init MSYS2-packages &&
src_dir="$src_cdup_dir/$2" &&
test -d "$src_dir" ||
return 1
;;
esac
;;
cd)
sdk init "$2" &&
cd "$src_dir" ||
sdk die "Could not change directory to '$2'"
case "$(uname -m)" in
i686)
MSYSTEM=MINGW32
MINGW_MOUNT_POINT=/mingw32
;;
x86_64)
if test -d /clangarm64
then
MSYSTEM=CLANGARM64
MINGW_MOUNT_POINT=/clangarm64
else
MSYSTEM=MINGW64
MINGW_MOUNT_POINT=/mingw64
fi
;;
*)
sdk die "Could not determine CPU architecture"
return 1
;;
esac
PKG_CONFIG_PATH="${MINGW_MOUNT_POINT}/lib/pkgconfig:${MINGW_MOUNT_POINT}/share/pkgconfig"
ACLOCAL_PATH="${MINGW_MOUNT_POINT}/share/aclocal:/usr/share/aclocal"
MANPATH="${MINGW_MOUNT_POINT}/local/man:${MINGW_MOUNT_POINT}/share/man:${MANPATH}"
first_path=$MINGW_MOUNT_POINT/bin
second_path=/usr/bin
case "$PWD" in
*/MSYS2-packages|*/MSYS2-packages/*)
MSYSTEM=MSYS
unset MINGW_MOUNT_POINT
PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/share/pkgconfig:/lib/pkgconfig"
second_path=$first_path
first_path=/usr/bin:/opt/bin
;;
esac
. /etc/msystem
PATH="$first_path:$second_path:$(echo "$PATH" |
sed -e "s|:\($first_path\|$second_path\)/\?:|:|g")"
return $?
;;
init)
sdk init-lazy "$2" &&
case "$(git -C "$src_cdup_dir" symbolic-ref HEAD 2>/dev/null)" in
'')
test -n "$(git -C "$src_cdup_dir" rev-parse HEAD 2>/dev/null)" ||
# Not checked out yet
git -C "$src_cdup_dir" pull origin HEAD
;;
refs/heads/master)
if git -C "$src_cdup_dir" rev-parse --verify HEAD >/dev/null 2>&1
then
git -C "$src_cdup_dir" branch -m main &&
sdk "$@"
return $?
fi
# Not checked out yet
git -C "$src_cdup_dir" symbolic-ref HEAD refs/heads/main &&
git -C "$src_cdup_dir" pull origin HEAD
;;
refs/heads/main)
case "$(git -C "$src_cdup_dir" rev-parse --symbolic-full-name main@{upstream} 2>/dev/null)" in
refs/remotes/origin/master)
git -C "$src_cdup_dir" fetch origin &&
git -C "$src_cdup_dir" branch --set-upstream-to=origin/main main;;
esac &&
case "$(git -C "$src_cdup_dir" symbolic-ref refs/remotes/origin/HEAD 2>/dev/null)" in
''|refs/heads/master)
git -C "$src_cdup_dir" fetch origin &&
git -C "$src_cdup_dir" remote set-head -a origin;;
esac &&
if { git -C "$src_cdup_dir" diff-files --quiet &&
git -C "$src_cdup_dir" diff-index --quiet HEAD ||
test ! -s "$src_cdup_dir"/.git/index; }
then
git -C "$src_cdup_dir" pull origin HEAD
fi
;;
esac &&
if test git = "$2" && test ! -f "$src_dir/config.mak"
then
cat >"$src_dir/config.mak" <<-\EOF
DEVELOPER=1
SKIP_DASHED_BUILT_INS=YesPlease
ifndef NDEBUG
CFLAGS := $(filter-out -O2,$(CFLAGS))
ASLR_OPTION := -Wl,--dynamicbase
BASIC_LDFLAGS := $(filter-out $(ASLR_OPTION),$(BASIC_LDFLAGS))
endif
EOF
elif test msys2-runtime = "$2"
then
remotes="$(git -C "$src_dir" remote -v)"
case "$remotes" in *"cygwin "*) ;;
*) git -C "$src_dir" remote add -f cygwin \
https://github.com/Cygwin/cygwin;; esac
case "$remotes" in *"msys2 "*) ;;
*) git -C "$src_dir" remote add -f msys2 \
https://github.com/Alexpux/Cygwin;; esac
case "$remotes" in *"git-for-windows "*) ;;
*) git -C "$src_dir" remote add -f \
git-for-windows \
https://github.com/git-for-windows/$2;; esac
fi
;;
build)
if test -z "$2"
then
set -- "$1" "$(basename "$PWD")" &&
sdk init-lazy "$2" &&
test "a$PWD" = "a$src_dir" ||
test "a$PWD" = "a$src_cdup_dir" || {
sdk die "$PWD seems not to be a known project"
return $?
}
fi
case "$2" in
git)
sdk init git &&
make -C "$src_dir" -j$(nproc) DEVELOPER=1
;;
installer)
sdk init "$2" &&
"$src_dir"/release.sh "${3:-0-test}"
;;
git-and-installer)
sdk build git &&
make -C "$src_dir" strip install &&
pacman -Syyu git-extra &&
sdk init build-extra &&
"$src_dir"/installer/release.sh "${3:-0-test}"
;;
msys2-runtime)
sdk cd "$2" ||
return $?
if test refs/heads/makepkg = \
"$(git symbolic-ref HEAD 2>/dev/null)" &&
{ git diff-files --quiet &&
git diff-index --quiet HEAD ||
test ! -s .git/index ||
(uname_m="$(uname -m)" &&
test ! -d "../build-$uname_m-pc-msys/$uname_m-pc-msys/winsup/cygwin"); }
then
# no local changes
cd "$src_cdup_dir" &&
sdk makepkg -f
return $?
fi
# Build the current branch
(uname_m="$(uname -m)" &&
cd "../build-$uname_m-pc-msys/$uname_m-pc-msys/winsup/cygwin" &&
make -j$(nproc))
return $?
;;
*)
sdk cd "$2" ||
return $?
if test -f PKGBUILD
then
case "$MSYSTEM" in
MSYS) sdk makepkg -f;;
CLANGARM*|MINGW*) MINGW_ARCH=${MSYSTEM,,} sdk makepkg-mingw -f;;
esac
return $?
fi
cat >&2 <<EOF
sdk build <project>
Supported projects:
git
installer [<version>]
git-and-installer [<version>]
msys2-runtime
EOF
return 1
;;
esac
;;
git-editor)
# Cannot use `git config -e -f "$2", as that would cd up to the
# top-level if the file is in a subdirectory of a Git worktree
eval "$(git var GIT_EDITOR)" "$2"
;;
edit)
cmd=init-lazy
test --cd != "$2" || {
cmd=cd
shift
}
case "$2" in
git-sdk.sh|sdk.completion)
sdk $cmd git-extra &&
sdk git-editor "$src_dir/$2" &&
. "$src_dir/$2"
;;
ReleaseNotes.md|please.sh)
sdk $cmd build-extra &&
sdk git-editor "$src_dir/$2"
;;
install.iss)
sdk $cmd installer &&
sdk git-editor "$src_dir/$2"
;;
*)
sdk die "Not a valid edit target: $2"
;;
esac || return $?
;;
reload)
shift
case "$*" in
--experimental)
sdk init git-extra &&
. "$src_dir"/sdk.completion &&
. "$src_dir"/git-sdk.sh
;;
--system)
. /usr/share/bash-completion/completions/sdk &&
. /etc/profile.d/git-sdk.sh
;;
'')
. "$GIT_SDK_SH_PATH"
;;
*)
sdk die "Unhandled option: '$*'"
;;
esac
return $?
;;
*)
printf "Usage: sdk <command> [<argument>...]\n\n" >&2 &&
sdk help
;;
esac
}
if [ -n "$ZSH_VERSION" ]; then
GIT_SDK_SH_PATH="$(realpath "${(%):-%x}")"
else
GIT_SDK_SH_PATH="$(realpath "$BASH_SOURCE")"
fi
case $- in
*i*)
# in any interactive session, initialize (but do not fetch) worktrees
# in /usr/src, and also create the Git SDK shortcut on the Desktop
# (unless it already exists).
test -n "$JENKINS_URL" || {
for project in git build-extra MINGW-packages MSYS2-packages
do
sdk init-lazy $project
done
sdk create-desktop-icon --gentle
}
sdk welcome
;;
esac