forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-sources.sh
executable file
·289 lines (260 loc) · 7.29 KB
/
get-sources.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
#!/bin/sh
# The purpose of this script is to gather all of the source code for a
# specific Git for Windows release, fulfilling the obligation under the
# GPL to provide it when distributing binaries.
die () {
echo "$*" >&2
exit 1
}
mingit=
case "$1" in
--mingit)
shift
mingit=t
;;
esac
test $# = 1 ||
die "Usage: $0 [--mingit] <package-versions>"
test -d /usr/src/MSYS2-packages/git ||
die "Need to run this in an SDK"
msys_source_url=http://repo.msys2.org/msys/sources
mingw_source_url=http://repo.msys2.org/mingw/sources
sf_repos_url=http://sourceforge.net/projects/msys2/files/REPOS
msys_sf_source_url=$sf_repos_url/MSYS2/Sources
mingw_sf_source_url=$sf_repos_url/MINGW/Sources
azure_blobs_source_url=https://wingit.blob.core.windows.net/sources
cd "$(dirname "$0")" ||
die "Could not change directory to build-extra/"
test -f "$1" ||
die "File not found (use absolute path?): $1"
dir=cached-source-packages
mkdir -p "$dir" ||
die "Could not make the cache directory"
if test -n "$mingit"
then
zipdir=source-zips-mingit
rm -rf $zipdir &&
mkdir $zipdir ||
die "Could not make $zipdir"
zipprev=source-zips
else
zipdir=source-zips
zipprev=$zipdir.previous
rm -rf $zipprev
test ! -d $zipdir ||
mv $zipdir $zipprev
mkdir $zipdir
fi
tar2zip () {
unpackdir=$dir/.unpack &&
rm -rf $unpackdir &&
mkdir $unpackdir &&
(cd $unpackdir && tar xzf -) <"$1" &&
(cd $unpackdir/* &&
CARCH=x86_64 MSBUILD_DIR=. \
bash -c 'source PKGBUILD &&
repo= &&
case "${source[0]}" in
*::git*)
repo="${source[0]%%::*}" &&
trailer="${source[0]##*#}" &&
case "$trailer" in
tag=*) rev=refs/tags/${trailer#tag=};;
branch=*) rev=refs/heads/${trailer#branch=};;
commit=*) rev=${trailer#commit=};;
"${source[0]}") rev=HEAD;;
*) echo "Unhandled trailer: $trailer" >&2; exit 1;;
esac &&
if test HEAD = $rev
then
zip=$repo.zip
else
zip=$repo-${rev##*/}.zip
fi &&
sed -i -e "s/^source=[^)]*/source=(\"$zip\"/" \
-e "s/^\( *\)git am \(--[^ ]* \)\?/\1patch -p1 </" \
PKGBUILD
;;
http:*|https:*)
sed -i "s/^\(source=(.\).*\/\([^)]*\)/\1\2/" PKGBUILD
;;
esac &&
case "${source[1]}" in
git+https:*.git)
test -z "$repo" || {
echo "Cannot handle *two* Git repos" >&2
exit 1
} &&
repo="${source[1]##*/}" &&
repo="${repo%.git}" &&
rev=HEAD &&
zip=$repo.zip &&
sed -i -e "s/git+https:.*$repo.git/$repo.zip/" \
-e "s/^\( *\)git am \(--[^ ]* \)\?/\1patch -p1 </" \
PKGBUILD
;;
esac &&
if test -n "$repo"
then
echo "Converting $repo to $zip" &&
if test git = $repo &&
! git -C $repo rev-parse -q --verify $rev
then
git -C "$repo" fetch origin $rev:$rev
fi &&
git -C "$repo" archive --prefix="$repo/" --format=zip \
"$rev" >"$zip" &&
rm -rf "$repo"
fi') &&
(cd $unpackdir && zip -9qr - .) >"$2" ||
die "Could not transmogrify $1 to $2"
}
cat "$1" |
while read name version
do
case "$name" in
gcc-libs|heimdal-libs|mingw-w64-*-gcc-libs)
# built as secondary package (see MSYS2-packages/*/PKGBUILD)
name=${name%-libs}
;;
mingw-w64-*-gcc-libgfortran)
# built as secondary package (see MSYS2-packages/*/PKGBUILD)
name=${name%-*}
;;
libdb|libpcre|libreadline|libserf|libsqlite)
# built as secondary package (see MSYS2-packages/*/PKGBUILD)
name=${name#lib}
;;
libintl)
# built as secondary package (see MSYS2-packages/*/PKGBUILD)
name=gettext
;;
libsasl)
# built as secondary package (see MSYS2-packages/*/PKGBUILD)
name=cyrus-sasl
;;
libpcre2_8)
# built as a secondary package (see MSYS2-packages/*/PKGBUILD)
name=pcre2
;;
mingw-w64-*-libwinpthread-git)
# built as secondary package (see MINGW-packages/*/PKGBUILD)
name=$(echo $name | sed 's/libwinpthread/winpthreads/')
;;
mingw-w64-*-git-doc-html)
# built as secondary package (see MINGW-packages/*/PKGBUILD)
name=${name%-doc-html}
;;
libcrypt)
# before https://github.com/msys2/MSYS2-packages/commit/a58271b3957
# the package was called crypt
test "$version" != 2.1-1 ||
name=crypt
;;
libnghttp2)
# built as secondary package (see MSYS2-packages/*/PKGBUILD)
name=nghttp2
;;
esac
# Work around mismatched version uploaded in MSYS2/Git for Windows
case $name-$version in
dash-0.5.8-1) version=0.5.8-2;;
mingw-w64-*-antiword-0.37-2) version=0.37-1;;
mingw-w64-*-curl-7.55.0-2) version=7.55.0-1;;
esac
zipname=$name-$version.zip
# Already copied?
test ! -f $zipdir/$zipname ||
continue
# Already transformed?
test ! -f $zipprev/$zipname ||
if test -n "$mingit"
then
echo "Copying $zipname..." >&2
cp $zipprev/$zipname $zipdir/ ||
die "Could not copy zip: $zipprev/$zipname"
continue
else
mv $zipprev/$zipname $zipdir/ ||
die "Could not move previous zip: $zipprev/$zipname"
continue
fi
w64=${name#mingw-w64-x86_64-}
w64=${w64#mingw-w64-i686-}
if test "$name" != "$w64"
then
filename=mingw-w64-$w64-$version.src.tar.gz
else
filename=$name-$version.src.tar.gz
fi
if test ! -f "$dir/$filename"
then
case "$name" in
git-extra|mingw-w64-x86_64-git-extra|mingw-w64-i686-git-extra|mingw-w64-x86_64-git|mingw-w64-i686-git|msys2-runtime|mingw-w64-x86_64-git-credential-manager|mingw-w64-i686-git-credential-manager|mingw-w64-x86_64-git-credential-manager-core|mingw-w64-i686-git-credential-manager-core|mingw-w64-i686-git-lfs|mingw-w64-x86_64-git-lfs|curl|mingw-w64-i686-curl|mingw-w64-x86_64-curl|mingw-w64-i686-wintoast|mingw-w64-x86_64-wintoast|bash|heimdal|perl|openssh)
url="$azure_blobs_source_url/$filename"
sf1_url=
sf2_url=
sf3_url=
;;
mingw-w64-*)
url=$mingw_source_url/$filename
sf1_url=$mingw_sf_source_url/$filename/download
sf2_url=$mingw_sf_source_url/$name-$version.src.tar.gz/download
sf3_url="$azure_blobs_source_url/$filename"
;;
*)
if test crypt != $name && test perl-Clone != $name &&
test ! -d /usr/src/MSYS2-packages/$name
then
name2="$(cd /usr/src/MSYS2-packages/ &&
grep -l "^pkgname=.*[ '\")]$name[ '\")]" \
*/PKGBUILD |
sed 's|/PKGBUILD$||')"
case "$name2" in
'')
die "Unknown origin: $name"
;;
*' '*)
die "Multiple origins of $name: $name2"
;;
esac
# "real" package already in packages-versions?
! grep "^$name2 $version$" <"$1" >/dev/null ||
continue
filename=$name2-$version.src.tar.gz
zipname=$name2-$version.zip
# Already transformed?
test ! -f $zipprev/$zipname ||
if test -n "$mingit"
then
echo "Copying $zipname..." >&2
cp $zipprev/$zipname $zipdir/ ||
die "Could not copy zip: $zipprev/$zipname"
continue
else
mv $zipprev/$zipname $zipdir/ ||
die "Could not move previous zip: $zipprev/$zipname"
continue
fi
fi
url="$msys_source_url/$filename"
sf1_url="$msys_sf_source_url/$filename/download"
sf2_url="$azure_blobs_source_url/$filename"
sf3_url=
;;
esac
echo "Downloading $url"
test -s "$dir/$filename" ||
curl -sfLo "$dir/$filename" "$url" ||
curl -sfLo "$dir/$filename" "$sf1_url" ||
curl -sfLo "$dir/$filename" "$sf2_url" ||
curl -sfLo "$dir/$filename" "$sf3_url" ||
die "Could not download $filename from $url ($sf1_url $sf2_url $sf3_url)" >&2
test -s "$dir/$filename" ||
die "Empty file: $dir/$filename"
fi
echo "Converting $filename to $zipname"
tar2zip "$dir/$filename" "$zipdir/$zipname" ||
die "Could not transform $dir/$filename"
done
echo "Sources are in $zipdir/"