-
Notifications
You must be signed in to change notification settings - Fork 810
/
Copy pathbuild.sh
executable file
·358 lines (321 loc) · 10.4 KB
/
build.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
#!/usr/bin/env bash
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
# Stop script if unbound variable found (use ${var:-} if intentional)
set -u
usage()
{
echo "Common settings:"
echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
echo " --verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
echo " --binaryLog Create MSBuild binary log (short: -bl)"
echo ""
echo "Actions:"
echo " --bootstrap Force the build of the bootstrap compiler"
echo " --restore Restore projects required to build (short: -r)"
echo " --norestore Don't restore projects required to build"
echo " --build Build all projects (short: -b)"
echo " --rebuild Rebuild all projects"
echo " --pack Build nuget packages"
echo " --publish Publish build artifacts"
echo " --sign Sign build artifacts"
echo " --help Print help and exit"
echo ""
echo "Test actions:"
echo " --testcoreclr Run unit tests on .NET Core (short: --test, -t)"
echo " --testCompilerComponentTests Run FSharp.Compiler.ComponentTests on .NET Core"
echo " --testBenchmarks Build and Run Benchmark suite"
echo " --testScripting Run FSharp.Private.ScriptingTests on .NET Core"
echo ""
echo "Advanced settings:"
echo " --ci Building in CI"
echo " --docker Run in a docker container if applicable"
echo " --skipAnalyzers Do not run analyzers during build operations"
echo " --skipBuild Do not run the build"
echo " --prepareMachine Prepare machine for CI run, clean up processes after build"
echo " --sourceBuild Simulate building for source-build"
echo " --buildnorealsig Build product with realsig- (default use realsig+ where necessary)"
echo " --tfm Override the default target framework"
echo ""
echo "Command line arguments starting with '/p:' are passed through to MSBuild."
}
source="${BASH_SOURCE[0]}"
# resolve $source until the file is no longer a symlink
while [[ -h "$source" ]]; do
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
source="$(readlink "$source")"
# if $source was a relative symlink, we need to resolve it relative to the path where the
# symlink file was located
[[ $source != /* ]] && source="$scriptroot/$source"
done
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
restore=false
build=false
rebuild=false
pack=false
publish=false
sign=false
test_core_clr=false
test_compilercomponent_tests=false
test_benchmarks=false
test_scripting=false
configuration="Debug"
verbosity='minimal'
binary_log=false
force_bootstrap=false
ci=false
skip_analyzers=false
skip_build=false
prepare_machine=false
source_build=false
buildnorealsig=true
properties=""
docker=false
args=""
tfm="net9.0" # This needs to be changed every time it's bumped by arcade/us.
BuildCategory=""
BuildMessage=""
if [[ $# = 0 ]]
then
usage
exit 1
fi
while [[ $# > 0 ]]; do
opt="$(echo "$1" | awk '{print tolower($0)}')"
case "$opt" in
--help|-h)
usage
exit 0
;;
--configuration|-c)
configuration=$2
args="$args $1"
shift
;;
--verbosity|-v)
verbosity=$2
args="$args $1"
shift
;;
--binarylog|-bl)
binary_log=true
;;
--bootstrap)
force_bootstrap=true
;;
--restore|-r)
restore=true
;;
--norestore)
restore=false
;;
--build|-b)
build=true
;;
--rebuild)
rebuild=true
;;
--pack)
pack=true
;;
--publish)
publish=true
;;
--sign)
sign=true
;;
--testcoreclr|--test|-t)
test_core_clr=true
;;
--testcompilercomponenttests)
test_compilercomponent_tests=true
;;
--testbenchmarks)
test_benchmarks=true
;;
--testscripting)
test_scripting=true
;;
--ci)
ci=true
;;
--skipanalyzers)
skip_analyzers=true
;;
--skipbuild)
skip_build=true
;;
--preparemachine)
prepare_machine=true
;;
--docker)
docker=true
;;
--sourcebuild)
source_build=true
;;
--buildnorealsig)
buildnorealsig=true
;;
--tfm)
tfm=$2
shift
;;
/p:*)
properties="$properties $1"
;;
*)
echo "Invalid argument: $1"
usage
exit 1
;;
esac
args="$args $1"
shift
done
# Import Arcade functions
. "$scriptroot/common/tools.sh"
function Test() {
BuildCategory="Test"
BuildMessage="Error running tests"
testproject=""
targetframework=""
while [[ $# > 0 ]]; do
opt="$(echo "$1" | awk '{print tolower($0)}')"
case "$opt" in
--testproject)
testproject=$2
shift
;;
--targetframework)
targetframework=$2
shift
;;
*)
echo "Invalid argument: $1"
exit 1
;;
esac
shift
done
if [[ "$testproject" == "" || "$targetframework" == "" ]]; then
echo "--testproject and --targetframework must be specified"
exit 1
fi
projectname=$(basename -- "$testproject")
projectname="${projectname%.*}"
testlogpath="$artifacts_dir/TestResults/$configuration/${projectname}_$targetframework.xml"
args="test \"$testproject\" --no-restore --no-build -c $configuration -f $targetframework --test-adapter-path . --logger \"xunit;LogFilePath=$testlogpath\" --blame-hang-timeout 5minutes --results-directory $artifacts_dir/TestResults/$configuration -p:vstestusemsbuildoutput=false"
args+=" -- xUnit.MaxParallelThreads=1"
"$DOTNET_INSTALL_DIR/dotnet" $args || exit $?
}
function BuildSolution {
BUILDING_USING_DOTNET=false
BuildCategory="Build"
BuildMessage="Error preparing build"
InitializeToolset
local toolset_build_proj=$_InitializeToolset
local bl=""
if [[ "$binary_log" = true ]]; then
bl="/bl:\"$log_dir/Build.binlog\""
fi
local projects="$repo_root/FSharp.sln"
echo "$projects:"
# https://github.com/dotnet/roslyn/issues/23736
local enable_analyzers=!$skip_analyzers
UNAME="$(uname)"
if [[ "$UNAME" == "Darwin" ]]; then
enable_analyzers=false
fi
local source_build_args=""
if [[ "$source_build" == true ]]; then
source_build_args="/p:DotNetBuildRepo=true /p:DotNetBuildSourceOnly=true"
fi
# NuGet often exceeds the limit of open files on Mac and Linux
# https://github.com/NuGet/Home/issues/2163
if [[ "$UNAME" == "Darwin" || "$UNAME" == "Linux" ]]; then
ulimit -n 6500
fi
local quiet_restore=""
if [[ "$ci" != true ]]; then
quiet_restore=true
fi
# Node reuse fails because multiple different versions of FSharp.Build.dll get loaded into MSBuild nodes
node_reuse=false
# build bootstrap tools
# source_build=In source build proto does no work, except cause sourcebuild in wrapper to build
bootstrap_dir=$artifacts_dir/Bootstrap
if [[ "$force_bootstrap" == true ]]; then
rm -fr $bootstrap_dir
fi
if [ ! -f "$bootstrap_dir/fslex/fslex.dll" ]; then
local bltools=""
if [[ "$bl" != "" ]]; then
bltools=$bl+".proto.binlog"
fi
local blrestore=""
if [[ "$source_build" != "true" ]]; then
blrestore="/restore"
fi
BuildMessage="Error building tools"
local args=" publish $repo_root/proto.proj $blrestore $bltools /p:Configuration=Proto $source_build_args $properties"
echo $args
"$DOTNET_INSTALL_DIR/dotnet" $args #$args || exit $?
fi
if [[ "$skip_build" != true ]]; then
# do real build
BuildMessage="Error building solution"
MSBuild $toolset_build_proj \
$bl \
/p:Configuration=$configuration \
/p:Projects="$projects" \
/p:RepoRoot="$repo_root" \
/p:Restore=$restore \
/p:Build=$build \
/p:Rebuild=$rebuild \
/p:Pack=$pack \
/p:Publish=$publish \
/p:Sign=$sign \
/p:UseRoslynAnalyzers=$enable_analyzers \
/p:ContinuousIntegrationBuild=$ci \
/p:QuietRestore=$quiet_restore \
/p:QuietRestoreBinaryLog="$binary_log" \
/p:BuildNoRealsig=$buildnorealsig \
$source_build_args \
$properties
fi
}
function TrapAndReportError {
local exit_code=$?
if [[ ! $exit_code == 0 ]]; then
Write-PipelineTelemetryError -category $BuildCategory "$BuildMessage (exit code '$exit_code')."
ExitWithExitCode $exit_code
fi
}
# allow early termination to report the appropriate build failure reason
trap TrapAndReportError EXIT
InitializeDotNetCli $restore
BuildSolution
if [[ "$test_core_clr" == true ]]; then
coreclrtestframework=$tfm
Test --testproject "$repo_root/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj" --targetframework $coreclrtestframework
Test --testproject "$repo_root/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj" --targetframework $coreclrtestframework
Test --testproject "$repo_root/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj" --targetframework $coreclrtestframework
Test --testproject "$repo_root/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharp.Compiler.Private.Scripting.UnitTests.fsproj" --targetframework $coreclrtestframework
Test --testproject "$repo_root/tests/FSharp.Build.UnitTests/FSharp.Build.UnitTests.fsproj" --targetframework $coreclrtestframework
Test --testproject "$repo_root/tests/FSharp.Core.UnitTests/FSharp.Core.UnitTests.fsproj" --targetframework $coreclrtestframework
fi
if [[ "$test_compilercomponent_tests" == true ]]; then
coreclrtestframework=$tfm
Test --testproject "$repo_root/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj" --targetframework $coreclrtestframework
fi
if [[ "$test_benchmarks" == true ]]; then
pushd "$repo_root/tests/benchmarks"
./SmokeTestBenchmarks.sh
popd
fi
if [[ "$test_scripting" == true ]]; then
coreclrtestframework=$tfm
Test --testproject "$repo_root/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharp.Compiler.Private.Scripting.UnitTests.fsproj" --targetframework $coreclrtestframework
fi
ExitWithExitCode 0