forked from dotnet/source-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-source-tarball.sh
executable file
·174 lines (137 loc) · 5.84 KB
/
build-source-tarball.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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
usage() {
echo "usage: $0 <path-to-tarball-root> [--skip-build]"
echo ""
}
if [ -z "${1:-}" ]; then
usage
exit 1
fi
TARBALL_ROOT=$1
shift
SKIP_BUILD=0
while :; do
if [ $# -le 0 ]; then
break
fi
lowerI="$(echo $1 | awk '{print tolower($0)}')"
case $lowerI in
-?|-h|--help)
usage
exit 0
;;
--skip-build)
SKIP_BUILD=1
;;
*)
echo "Unrecognized argument '$1'"
usage
exit 1
;;
esac
shift
done
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)"
SDK_VERSION=$(cat $SCRIPT_ROOT/DotnetCLIVersion.txt)
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 /flp:v=detailed
fi
mkdir -p "$TARBALL_ROOT"
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'
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/init-tools.msbuild $TARBALL_ROOT/
cp $SCRIPT_ROOT/DotnetCLIVersion.txt $TARBALL_ROOT/
cp $SCRIPT_ROOT/ProdConFeed.txt $TARBALL_ROOT/
cp $SCRIPT_ROOT/smoke-test* $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/
cp -r $SCRIPT_ROOT/bin/git-info $TARBALL_ROOT/
cp -r $SCRIPT_ROOT/Tools $TARBALL_ROOT/
rm -f $TARBALL_ROOT/Tools/dotnetcli/dotnet.tar
rm -f $TARBALL_ROOT/Tools/dotnetcli/sdk/$SDK_VERSION/nuGetPackagesArchive.lzma
rm -rf $TARBALL_ROOT/Tools/dotnetcli/store
rm -rf $TARBALL_ROOT/Tools/dotnetcli/additionalDeps
# Remove props file generated by CoreFX that contains the RuntimeOS value of the current machine.
# It artificially limits the tarball to be buildable on only the OS that created it.
rm -rf $TARBALL_ROOT/Tools/configuration/configuration.props
cp $SCRIPT_ROOT/support/tarball/build.sh $TARBALL_ROOT/build.sh
mkdir -p $TARBALL_ROOT/prebuilt/nuget-packages
find $SCRIPT_ROOT/packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/prebuilt/nuget-packages/ \;
find $SCRIPT_ROOT/bin/obj/x64/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/prebuilt/nuget-packages/ \;
if [ -e $SCRIPT_ROOT/testing-smoke/smoke-test-packages ]; then
cp -rf $SCRIPT_ROOT/testing-smoke/smoke-test-packages $TARBALL_ROOT/prebuilt
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/prebuilt/nuget-packages/$(basename $built_package) ]; then
rm $TARBALL_ROOT/prebuilt/nuget-packages/$(basename $built_package)
fi
if [ -e $TARBALL_ROOT/prebuilt/smoke-test-packages/$(basename $built_package) ]; then
rm $TARBALL_ROOT/prebuilt/smoke-test-packages/$(basename $built_package)
fi
done
if [ -z "${SOURCE_BUILD_SKIP_PREBUILT_REPORT:-}" ]; then
echo 'Creating prebuilt package usage report...'
(
# Don't clean up (or ask to clean up).
export SOURCE_BUILD_SKIP_SUBMODULE_CHECK=1
"$SCRIPT_ROOT/build.sh" /nologo /t:ReportTarballPrebuiltUsage /p:TarballPrebuiltPackagesPath="$FULL_TARBALL_ROOT/prebuilt/nuget-packages/"
)
fi
echo 'WORKAROUND: Overwriting the source-built roslyn-tools MSBuild files with prebuilt so that roslyn-tools can successfully build in the tarball... (https://github.com/dotnet/source-build/issues/654)'
ROSLYN_TOOLS_PACKAGE='RoslynTools.RepoToolset'
JSON_LINE=$(grep "$ROSLYN_TOOLS_PACKAGE" "$SCRIPT_ROOT/src/roslyn-tools/global.json")
# Remove spaces.
JSON_LINE=${JSON_LINE// }
# Isolate version from something like: "RoslynTools.RepoToolset":"1.0.0-beta2-62805-03"
PREFIX="\"$ROSLYN_TOOLS_PACKAGE\":\""
ROSLYN_TOOLS_REPO_TOOLSET_VERSION=${JSON_LINE:${#PREFIX}:$((${#JSON_LINE} - ${#PREFIX} - 1))}
REPO_TOOLSET_PACKAGE_DIR="$SCRIPT_ROOT/packages/${ROSLYN_TOOLS_PACKAGE,,}/$ROSLYN_TOOLS_REPO_TOOLSET_VERSION"
if [ ! -d "$REPO_TOOLSET_PACKAGE_DIR" ]; then
echo "Failed to find repo toolset at: $REPO_TOOLSET_PACKAGE_DIR"
exit 1
fi
SOURCE_BUILT_SDK_TOOLS_DIR="$TARBALL_ROOT/Tools/source-built/$ROSLYN_TOOLS_PACKAGE/tools"
cp "$REPO_TOOLSET_PACKAGE_DIR/tools/"*.props "$SOURCE_BUILT_SDK_TOOLS_DIR"
cp "$REPO_TOOLSET_PACKAGE_DIR/tools/"*.targets "$SOURCE_BUILT_SDK_TOOLS_DIR"
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"