forked from dotnet/source-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-source-tarball.sh
More file actions
executable file
·156 lines (137 loc) · 5.46 KB
/
build-source-tarball.sh
File metadata and controls
executable file
·156 lines (137 loc) · 5.46 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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
usage() {
echo "usage: $0 <path-to-tarball-root> [options]"
echo "options:"
echo " --skip-build assume we have already built (requires you have built with the /p:ArchiveDownloadedPackages=true flag)"
echo " --enable-leak-detection build leaked-binary detection tasts for later use while building from this tarball"
echo " --skip-prebuilt-check do not confirm that all prebuilt packages used are either reference packages, previously-built, or known extras"
echo " --with-ref-packages <dir> use the specified directory of available reference packages to determine what prebuilts to delete, instead of downloading the most recent version"
echo " --with-packages <dir> use the specified directory of available previously-built packages to determine what prebuilts to delete, instead of downloading the most recent version"
echo " --with-sdk <dir> use the specified SDK to check out source code. do not copy it to the tarball. an external SDK will be required to build from the tarball."
echo "use -- to send the remaining arguments to build.sh"
}
if [ -z "${1:-}" ]; then
usage
exit 1
fi
TARBALL_ROOT=$1
shift
SKIP_BUILD=0
CUSTOM_SDK_DIR=''
MINIMIZE_DISK_USAGE=0
CUSTOM_REF_PACKAGES_DIR=''
CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR=''
MAIN_BUILD_ARGS=("/p:ArchiveDownloadedPackages=true")
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)
MAIN_BUILD_ARGS+=( "/p:IncludeLeakDetection=true" )
;;
--minimize-disk-usage)
MINIMIZE_DISK_USAGE=1
MAIN_BUILD_ARGS+=( "/p:DestructiveIntermediateClean=true" )
;;
--skip-prebuilt-check)
MAIN_BUILD_ARGS+=( "/p:SkipPrebuiltEnforcement=true" )
;;
--with-sdk)
CUSTOM_SDK_DIR="$2"
if [ ! -d "$CUSTOM_SDK_DIR" ]; then
echo "Custom SDK directory '$CUSTOM_SDK_DIR' does not exist"
fi
if [ ! -x "$CUSTOM_SDK_DIR/dotnet" ]; then
echo "Custom SDK '$CUSTOM_SDK_DIR/dotnet' not found or not executable"
fi
shift
;;
--with-ref-packages)
CUSTOM_REF_PACKAGES_DIR="$2"
if [ ! -d "$CUSTOM_REF_PACKAGES_DIR" ]; then
echo "Custom reference packages directory '$CUSTOM_REF_PACKAGES_DIR' does not exist"
exit 1
fi
MAIN_BUILD_ARGS+=( "/p:SkipDownloadingReferencePackages=true" )
MAIN_BUILD_ARGS+=( "/p:CustomRefPackagesDir=$CUSTOM_REF_PACKAGES_DIR" )
shift
;;
--with-packages)
CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR="$2"
if [ ! -d "$CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR" ]; then
echo "Custom reference packages directory '$CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR' does not exist"
exit 1
fi
MAIN_BUILD_ARGS+=( "/p:SkipDownloadingPreviouslySourceBuiltPackages=true" )
MAIN_BUILD_ARGS+=( "/p:CustomPreviouslySourceBuiltPackagesDir=$CUSTOM_PREVIOUSLY_BUILT_PACKAGES_DIR" )
shift
;;
--)
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 SCRIPT_ROOT="$(cd -P "$( dirname "$0" )" && pwd)"
fullTarballRoot="$TARBALL_ROOT"
while [[ -h $fullTarballRoot ]]; do
fullTarballRoot="$(readlink "$fullTarballRoot")"
# if $source was a relative symlink, we need to resolve it relative to the path where the
# symlink file was located
[[ $fullTarballRoot != /* ]] && fullTarballRoot="$SCRIPT_ROOT/$fullTarballRoot"
done
export FULL_TARBALL_ROOT="$fullTarballRoot"
if [ -e "$TARBALL_ROOT" ]; then
echo "info: '$TARBALL_ROOT' already exists"
fi
if [ -d "$CUSTOM_SDK_DIR" ]; then
export SDK_VERSION=`"$CUSTOM_SDK_DIR/dotnet" --version`
echo "Using custom bootstrap SDK from '$CUSTOM_SDK_DIR', version $SDK_VERSION"
else
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"
fi
if [ $SKIP_BUILD -ne 1 ]; then
if [ -e "$SCRIPT_ROOT/artifacts" ]; then
rm -rf "$SCRIPT_ROOT/artifacts"
fi
$SCRIPT_ROOT/clean.sh
else
MAIN_BUILD_ARGS+=( "/p:SkipProductionBuild=true" )
fi
mkdir -p "$FULL_TARBALL_ROOT"
MAIN_BUILD_ARGS+=( "/p:TarballRoot=$FULL_TARBALL_ROOT" )
MAIN_BUILD_ARGS+=( "/p:PackSourceBuildTarball=true" )
$SCRIPT_ROOT/build.sh ${MAIN_BUILD_ARGS[@]} /bl:$SCRIPT_ROOT/artifacts/log/Debug/BuildTarball_$(date +"%m%d%H%M%S").binlog "$@"
echo "Done. Tarball created: $TARBALL_ROOT"