forked from dotnet/source-build
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-source-tarball.sh
More file actions
executable file
·331 lines (277 loc) · 12.7 KB
/
build-source-tarball.sh
File metadata and controls
executable file
·331 lines (277 loc) · 12.7 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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
usage() {
echo "usage: $0 <path-to-tarball-root> [--skip-build] [--enable-leak-detection] [-- [extra build.sh args]]"
echo ""
}
if [ -z "${1:-}" ]; then
usage
exit 1
fi
TARBALL_ROOT=$1
shift
SKIP_BUILD=0
INCLUDE_LEAK_DETECTION=0
MINIMIZE_DISK_USAGE=0
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
while :; do
if [ $# -le 0 ]; then
break
fi
lowerI="$(echo $1 | awk '{print tolower($0)}')"
case $lowerI in
--skip-build)
SKIP_BUILD=1
;;
--enable-leak-detection)
INCLUDE_LEAK_DETECTION=1
;;
--minimize-disk-usage)
MINIMIZE_DISK_USAGE=1
;;
--)
shift
echo "Detected '--': passing remaining parameters '$@' as build.sh arguments."
break
;;
-?|-h|--help)
usage
exit 0
;;
*)
echo "Unrecognized argument '$1'"
usage
exit 1
;;
esac
shift
done
if [ $MINIMIZE_DISK_USAGE -eq 1 ]; then
echo "WARNING"
echo "WARNING"
echo "WARNING: --minimize-disk-usage intentionally trashes your local repo and any local work. It will not be recoverable. It is intended for CI use only."
echo "WARNING"
echo "WARNING"
echo "WARNING: You have 10 seconds to cancel."
sleep 10
fi
export FULL_TARBALL_ROOT=$(readlink -f $TARBALL_ROOT)
if [ -e "$TARBALL_ROOT" ]; then
echo "info: '$TARBALL_ROOT' already exists"
fi
export SCRIPT_ROOT="$(cd -P "$( dirname "$0" )" && pwd)"
sdkLine=`grep -m 1 'dotnet' "$SCRIPT_ROOT/global.json"`
sdkPattern="\"dotnet\" *: *\"(.*)\""
if [[ $sdkLine =~ $sdkPattern ]]; then
export SDK_VERSION=${BASH_REMATCH[1]}
fi
echo "Found bootstrap SDK $SDK_VERSION"
CLI_PATH="$SCRIPT_ROOT/.dotnet"
DarcVersion=$(cat $SCRIPT_ROOT/DarcVersion.txt)
DARC_DLL="$CLI_PATH/tools/.store/microsoft.dotnet.darc/$DarcVersion/microsoft.dotnet.darc/$DarcVersion/tools/netcoreapp2.1/any/Microsoft.DotNet.Darc.dll"
if [ $SKIP_BUILD -ne 1 ]; then
if [ -e "$SCRIPT_ROOT/bin" ]; then
rm -rf "$SCRIPT_ROOT/bin"
fi
$SCRIPT_ROOT/clean.sh
$SCRIPT_ROOT/build.sh /p:ArchiveDownloadedPackages=true "$@"
fi
mkdir -p "$TARBALL_ROOT"
# We need to keep bin/src/<repo>/.git around for sourcelink metadata but we can delete
# just about everything else, Darc will pull it from the copy in .git/modules.
# This list of extensions is everything over 6MB or so.
if [ $MINIMIZE_DISK_USAGE -eq 1 ]; then
find $SCRIPT_ROOT/bin/src \( -type f \( \
-iname '*.dll' -o \
-iname '*.exe' -o \
-iname '*.pdb' -o \
-iname '*.mdb' -o \
-iname '*.zip' -o \
-iname '*.cs' -o \
-iname '*.vb' -o \
-iname '*.il' -o \
-iname '*.xlf' -o \
-iname '*.cpp' -o \
-iname '*.txt' -o \
-iname '*.map' -o \
-iname '*.md' -o \
-iname '*.fs' -o \
-iname '*.h' -o \
-iname '*.c' -o \
-iname '*.js' -o \
-iname '*.json' -o \
-iname '*.ildump' -o \
-iname '*.resx' -o \
-iname '*.xml' -o \
-iname '*.css' -o \
-iname '*.*proj' -o \
-iname '*.nupkg' \) \) -exec rm {} \;
fi
echo 'Copying sources to tarball...'
# Use Git to put sources in the tarball. This ensure it's fresh, without having to clean and reset
# the working dir. This helps preserve diagnostic information if the tarball build doesn't work.
# Checkout non-submodule sources into tarball.
git --work-tree="$TARBALL_ROOT" checkout HEAD -- src
# Checkout submodule sources into tarball.
git submodule foreach --quiet --recursive '
SCRIPT_SUBMODULE_PATH="$toplevel/$path"
TARBALL_SUBMODULE_PATH="$FULL_TARBALL_ROOT/${SCRIPT_SUBMODULE_PATH#$SCRIPT_ROOT/}"
mkdir -p "$TARBALL_SUBMODULE_PATH"
echo "Checking out $(pwd) => $TARBALL_SUBMODULE_PATH ..."
if [ "$(ls -A)" = ".git" ]; then
# Checkout fails for an empty tree. (E.g. nuget-client submodule NuGet.Build.Localization.)
echo " Nothing to check out from $TARBALL_SUBMODULE_PATH"
else
git --work-tree="$TARBALL_SUBMODULE_PATH" checkout -- .
fi'
# Now re-uberclone into the tarball src directory. Since we reuse the .gitdirs, this shouldn't hit the network at all.
ignored_repos="https://dev.azure.com/dnceng/internal/_git/dotnet-optimization;https://dev.azure.com/devdiv/DevDiv/_git/DotNet-Trusted;https://devdiv.visualstudio.com/DevDiv/_git/DotNet-Trusted;https://dnceng@dev.azure.com/dnceng/internal/_git/dotnet-optimization;https://dev.azure.com/dnceng/internal/_git/dotnet-core-setup;https://github.com/dotnet/source-build-reference-packages"
#export the LC_LIB_PATH for libgit2 so file as fedora fails to find it in the repodir
export LD_LIBRARY_PATH=$CLI_PATH/tools/.store/microsoft.dotnet.darc/$DarcVersion/microsoft.dotnet.darc/$DarcVersion/tools/netcoreapp2.1/any/runtimes/rhel-x64/native/
"$CLI_PATH/dotnet" "$DARC_DLL" clone --repos-folder=$TARBALL_ROOT/src/ --git-dir-folder $SCRIPT_ROOT/.git/modules/src/ --include-toolset --ignore-repos "$ignored_repos" --azdev-pat bogus --github-pat bogus --depth 0 --debug
# now we don't need .git/modules/src or Darc anymore
if [ $MINIMIZE_DISK_USAGE -eq 1 ]; then
rm -rf "$SCRIPT_ROOT/.git/modules/src"
rm -rf $SCRIPT_ROOT/tools-local/arcade-services
fi
# then delete the master copies - we only need the specific hashes
pushd "$TARBALL_ROOT/src"
find "$PWD" -maxdepth 1 -type d | grep -v reference-assemblies | grep -v netcorecli-fsc | grep -v package-source-build | grep -v "$PWD\$" | egrep -v '\.[A-Fa-f0-9]{40}' | xargs rm -rf
popd
echo 'Removing binaries from tarball src...'
find $TARBALL_ROOT/src \( -type f \( \
-iname *.dll -o \
-iname *.exe -o \
-iname *.pdb -o \
-iname *.mdb -o \
-iname *.zip -o \
-iname *.nupkg \) \) -exec rm {} \;
echo 'Copying sourcelink metadata to tarball...'
pushd $SCRIPT_ROOT
for srcDir in `find bin/src -name '.git' -type d`; do
newPath=`echo $srcDir | sed 's/^bin\///' | sed 's/\.git$//'`
cp -r $srcDir $TARBALL_ROOT/$newPath
done
popd
echo 'Copying scripts and tools to tarball...'
cp $SCRIPT_ROOT/*.proj $TARBALL_ROOT/
cp $SCRIPT_ROOT/*.props $TARBALL_ROOT/
cp $SCRIPT_ROOT/*.targets $TARBALL_ROOT/
cp $SCRIPT_ROOT/global.json $TARBALL_ROOT/
cp $SCRIPT_ROOT/DarcVersion.txt $TARBALL_ROOT/
cp $SCRIPT_ROOT/ProdConFeed.txt $TARBALL_ROOT/
cp $SCRIPT_ROOT/smoke-test* $TARBALL_ROOT/
cp -r $CLI_PATH $TARBALL_ROOT/
cp -r $SCRIPT_ROOT/eng $TARBALL_ROOT/
cp -r $SCRIPT_ROOT/keys $TARBALL_ROOT/
cp -r $SCRIPT_ROOT/patches $TARBALL_ROOT/
cp -r $SCRIPT_ROOT/scripts $TARBALL_ROOT/
cp -r $SCRIPT_ROOT/repos $TARBALL_ROOT/
cp -r $SCRIPT_ROOT/tools-local $TARBALL_ROOT/
rm -rf $TARBALL_ROOT/tools-local/arcade-services/
rm -rf $TARBALL_ROOT/.dotnet/shared/2.1.0/
rm -rf $TARBALL_ROOT/.dotnet/tools/
rm -rf $TARBALL_ROOT/.dotnet/host/fxr/2.1.0/
cp -r $SCRIPT_ROOT/bin/git-info $TARBALL_ROOT/
cp $SCRIPT_ROOT/support/tarball/build.sh $TARBALL_ROOT/build.sh
mkdir -p $TARBALL_ROOT/packages/prebuilt
mkdir -p $TARBALL_ROOT/packages/source-built
find $SCRIPT_ROOT/packages/restored/ -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
find $SCRIPT_ROOT/bin/obj/x64/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
# Copy reference-packages from bin dir to reference-packages directory.
# See corresponding change in dir.props to change ReferencePackagesBasePath conditionally in offline build.
mkdir -p $TARBALL_ROOT/packages/reference
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/source $TARBALL_ROOT/packages/reference/source
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/staging $TARBALL_ROOT/packages/reference/staging
# Copy tarballs to ./packages/archive directory
mkdir -p $TARBALL_ROOT/packages/archive
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/external-tarballs/*.tar.gz $TARBALL_ROOT/packages/archive/
# Copy generated source from bin to src/generatedSrc
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/generatedSrc $TARBALL_ROOT/src/generatedSrc
if [ -e $SCRIPT_ROOT/testing-smoke/smoke-test-packages ]; then
cp -rf $SCRIPT_ROOT/testing-smoke/smoke-test-packages $TARBALL_ROOT/packages
fi
echo 'Removing source-built packages from tarball prebuilts...'
for built_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
do
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $built_package) ]; then
rm $TARBALL_ROOT/packages/prebuilt/$(basename $built_package)
fi
if [ -e $TARBALL_ROOT/packages/smoke-test-packages/$(basename $built_package) ]; then
rm $TARBALL_ROOT/packages/smoke-test-packages/$(basename $built_package)
fi
done
echo 'Copying source-built packages to tarball to replace packages needed before they are built...'
mkdir -p $TARBALL_ROOT/packages/source-built
cp -r $SCRIPT_ROOT/Tools/source-built/coreclr-tools $TARBALL_ROOT/packages/source-built/
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*Arcade*.nupkg $TARBALL_ROOT/packages/source-built/
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*SourceLink*.nupkg $TARBALL_ROOT/packages/source-built/
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*Build*Tasks*.nupkg $TARBALL_ROOT/packages/source-built/
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/runtime*.nupkg $TARBALL_ROOT/packages/source-built/
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetHost*.nupkg $TARBALL_ROOT/packages/source-built/
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetAppHost*.nupkg $TARBALL_ROOT/packages/source-built/
# Setup package version props to include both source-built and running PackageVersions.props
mkdir --parents $TARBALL_ROOT/bin/obj/x64/Release/
cp $SCRIPT_ROOT/support/tarball/PackageVersions.props $TARBALL_ROOT/bin/obj/x64/Release/
if [ $INCLUDE_LEAK_DETECTION -eq 1 ]; then
echo 'Building leak detection MSBuild tasks...'
"$CLI_PATH/dotnet" restore $SCRIPT_ROOT/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection.csproj --source $FULL_TARBALL_ROOT/packages/source-built --source $FULL_TARBALL_ROOT/packages/prebuilt
"$CLI_PATH/dotnet" publish -o $FULL_TARBALL_ROOT/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection $SCRIPT_ROOT/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection.csproj
fi
echo 'Removing reference-only packages from tarball prebuilts...'
for ref_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/packages-to-delete/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
do
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package) ]; then
rm $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package)
fi
done
allRefPkgs=(`tar -tf $TARBALL_ROOT/packages/archive/Private.SourceBuild.ReferencePackages.*.tar.gz | tr '[:upper:]' '[:lower:]'`)
allSourceBuiltPkgs=(`tar -tf $TARBALL_ROOT/packages/archive/Private.SourceBuilt.Artifacts.*.tar.gz | tr '[:upper:]' '[:lower:]'`)
echo 'Removing reference-packages from tarball prebuilts...'
for ref_package in ${allRefPkgs[@]}
do
if [ -e $TARBALL_ROOT/packages/prebuilt/$ref_package ]; then
rm $TARBALL_ROOT/packages/prebuilt/$ref_package
fi
done
echo 'Removing previously source-built packages from tarball prebuilts...'
for ref_package in ${allSourceBuiltPkgs[@]}
do
if [ -e $TARBALL_ROOT/packages/prebuilt/$ref_package ]; then
rm $TARBALL_ROOT/packages/prebuilt/$ref_package
fi
done
echo 'Removing source-built, previously source-built packages and reference packages from il pkg src...'
OLDIFS=$IFS
allBuiltPkgs=(`ls $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*.nupkg | xargs -n1 basename | tr '[:upper:]' '[:lower:]'`)
pushd $TARBALL_ROOT/packages/reference/staging/
ilSrcPaths=(`find . -maxdepth 2 -mindepth 2`)
popd
for path in ${ilSrcPaths[@]}; do
IFS='/'
read -a splitLine <<< "$path"
remove=false
if [[ " ${allRefPkgs[@]} " =~ " ${splitLine[1]}.${splitLine[2]}.nupkg " ]]; then
remove=true
fi
if [[ " ${allSourceBuiltPkgs[@]} " =~ " ${splitLine[1]}.${splitLine[2]}.nupkg " ]]; then
remove=true
fi
if [[ " ${allBuiltPkgs[@]} " =~ " ${splitLine[1]}.${splitLine[2]}.nupkg " ]]; then
remove=true
fi
if [[ "$remove" == "true" ]]; then
rm -rf "$TARBALL_ROOT/packages/reference/staging/$path"
rm -rf "$TARBALL_ROOT/packages/reference/source/$path"
fi
done
IFS=$OLDIFS
echo 'Recording commits for the source-build repo and all submodules, to aid in reproducibility...'
cat >$TARBALL_ROOT/source-build-info.txt << EOF
source-build:
$(git rev-parse HEAD) . ($(git describe --always HEAD))
submodules:
$(git submodule status --recursive)
EOF
echo "Done. Tarball created: $TARBALL_ROOT"