forked from microsoft/vstest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·428 lines (365 loc) · 14.5 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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/usr/bin/env/ bash
# Copyright (c) Microsoft. All rights reserved.
# Build script for Test Platform.
set -o nounset # Fail on uninitialized variables.
set -e # Fail on non-zero exit code.
# ANSI color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NOCOLOR='\033[0m'
#
# Parse options
#
CONFIGURATION="Debug"
TARGET_RUNTIME="ubuntu.16.04-x64"
VERSION="" # Will set this later by reading TestPlatform.Settings.targets file.
VERSION_SUFFIX="dev"
FAIL_FAST=false
DISABLE_LOCALIZED_BUILD=false
CI_BUILD=false
VERBOSE=false
PROJECT_NAME_PATTERNS=
#
# Source build repo api
# See https://github.com/dotnet/source-build/blob/dev/release/2.0/Documentation/RepoApi.md
#
DOTNET_BUILD_FROM_SOURCE=0
DOTNET_CORE_SDK_DIR=
DOTNET_BUILD_TOOLS_DIR=
while [ $# -gt 0 ]; do
lowerI="$(echo ${1:-} | awk '{print tolower($0)}')"
case $lowerI in
-h | --help)
usage
exit
;;
-c)
CONFIGURATION=$2
shift
;;
-r)
TARGET_RUNTIME=$2
shift
;;
-v)
VERSION=$2
shift
;;
-vs)
VERSION_SUFFIX=$2
shift
;;
-noloc)
DISABLE_LOCALIZED_BUILD=$2
shift
;;
-ci)
CI_BUILD=$2
shift
;;
-p)
PROJECT_NAME_PATTERNS=$2
shift
;;
-dotnetbuildfromsource)
DOTNET_BUILD_FROM_SOURCE=1
;;
-dotnetcoresdkdir)
DOTNET_CORE_SDK_DIR=$2
shift
;;
-dotnetbuildtoolsdir)
DOTNET_BUILD_TOOLS_DIR=$2
shift
;;
-verbose)
VERBOSE=true
;;
*)
break
;;
esac
shift
done
#
# Variables
#
TP_ROOT_DIR=$(cd "$(dirname "$0")"; pwd -P)
TP_TOOLS_DIR="$TP_ROOT_DIR/tools"
TP_DOTNET_DIR="${DOTNET_CORE_SDK_DIR:-${TP_TOOLS_DIR}/dotnet}"
TP_PACKAGES_DIR="${NUGET_PACKAGES:-${TP_ROOT_DIR}/packages}"
TP_OUT_DIR="$TP_ROOT_DIR/artifacts"
TP_PACKAGE_PROJ_DIR="$TP_ROOT_DIR/src/package/package"
TP_PACKAGE_NUSPEC_DIR="$TP_ROOT_DIR/src/package/nuspec"
TP_SRC_DIR="$TP_ROOT_DIR/src"
TP_USE_REPO_API=$DOTNET_BUILD_FROM_SOURCE
# Set VERSION from scripts/build/TestPlatform.Settings.targets
VERSION=$(test -z $VERSION && grep TPVersionPrefix $TP_ROOT_DIR/scripts/build/TestPlatform.Settings.targets | head -1 | cut -d'>' -f2 | cut -d'<' -f1 || echo $VERSION)
#
# Dotnet configuration
#
# Disable first run since we want to control all package sources
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
# Dotnet build doesnt support --packages yet. See https://github.com/dotnet/cli/issues/2712
export NUGET_PACKAGES=$TP_PACKAGES_DIR
DOTNET_CLI_VERSION="LATEST"
#DOTNET_RUNTIME_VERSION="LATEST"
#
# Build configuration
#
TPB_Solution="TestPlatform.sln"
TPB_Build_From_Source_Solution="TestPlatform_BuildFromSource.sln"
TPB_TargetFramework="net451"
TPB_TargetFrameworkCore="netcoreapp2.0"
TPB_TargetFrameworkCore10="netcoreapp1.0"
TPB_Configuration=$CONFIGURATION
TPB_TargetRuntime=$TARGET_RUNTIME
TPB_Version=$(test -z $VERSION_SUFFIX && echo $VERSION || echo $VERSION-$VERSION_SUFFIX)
TPB_CIBuild=$CI_BUILD
TPB_LocalizedBuild=$DISABLE_LOCALIZED_BUILD
TPB_Verbose=$VERBOSE
#
# Logging
#
log()
{
printf "${GREEN}... $@${NOCOLOR}\n"
}
verbose()
{
if [ ${TPB_Verbose-false} ]
then
printf "${YELLOW}... $@${NOCOLOR}\n" >&2
fi
}
error()
{
printf "${RED}... $@${NOCOLOR}\n" >&2
}
function usage()
{
log " Usage: ./build.sh [Options]"
log ""
log " -c <CONFIGURATION> Build the specified Configuration (Debug or Release, default: Debug)"
log " -r <TARGET_RUNTIME> Build for the specified runtime moniker (ubuntu.14.04-x64)"
log " -v <VERSION> Version number for the package generated (15.0.0)"
log " -vs <VERSION_SUFFIX> Version suffix for package generated (dev)"
log " -noloc <DISABLE_LOCALIZED_BUILD> Disable Localized builds (true,false)"
log " -ci <CI_BUILD> Declares if this is a CI_BUILD or not"
log " -p <PROJECT_NAME_PATTERNS> Pattern to build specific projects"
log " -verbose <VERBOSE> Enable verbose logging (true, false)"
}
#
# Build steps
#
function install_cli()
{
if [[ $TP_USE_REPO_API = 0 ]]; then
# Skip download of dotnet toolset if REPO API is enabled
local failed=false
local install_script="$TP_TOOLS_DIR/dotnet-install.sh"
local remote_path="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh"
log "Installing dotnet cli..."
local start=$SECONDS
# Install the latest version of dotnet-cli
curl --retry 10 -sSL --create-dirs -o $install_script $remote_path || failed=true
if [ "$failed" = true ]; then
error "Failed to download dotnet-install.sh script."
return 1
fi
chmod u+x $install_script
log "install_cli: Get the latest dotnet cli toolset..."
$install_script --install-dir "$TP_TOOLS_DIR/dotnet" --no-path --channel "master" --version $DOTNET_CLI_VERSION
# Get netcoreapp1.1 shared components
log "install_cli: Get the shared netcoreapp1.0 runtime..."
$install_script --install-dir "$TP_TOOLS_DIR/dotnet" --no-path --channel "preview" --version "1.0.5" --shared-runtime
log "install_cli: Get the shared netcoreapp1.1 runtime..."
$install_script --install-dir "$TP_TOOLS_DIR/dotnet" --no-path --channel "release/1.1.0" --version "1.1.2" --shared-runtime
log "install_cli: Get the shared netcoreapp2.0 runtime..."
$install_script --install-dir "$TP_TOOLS_DIR/dotnet" --no-path --channel "release/2.0.0" --version "2.0.0" --shared-runtime
#log "install_cli: Get shared components which is compatible with dotnet cli version $DOTNET_CLI_VERSION..."
#$install_script --install-dir "$TP_TOOLS_DIR/dotnet" --no-path --channel "master" --version $DOTNET_RUNTIME_VERSION --shared-runtime
fi
local dotnet_path=$(_get_dotnet_path)
if [[ ! -e $dotnet_path ]]; then
log "dotnet not found at $dotnet_path. Did the dotnet cli installation succeed?"
return 1
fi
log "install_cli: Complete. Elapsed $(( SECONDS - start ))s."
return 0
}
function restore_package()
{
local failed=false
local dotnet=$(_get_dotnet_path)
log "restore_package: Start restoring packages to $TP_PACKAGES_DIR."
local start=$SECONDS
log ".. .. Restore: Source: $TP_ROOT_DIR/src/package/external/external.csproj"
$dotnet restore $TP_ROOT_DIR/src/package/external/external.csproj --packages $TP_PACKAGES_DIR -v:minimal -warnaserror -p:Version=$TPB_Version || failed=true
if [ "$failed" = true ]; then
error "Failed to restore packages."
return 2
fi
log "restore_package: Complete. Elapsed $(( SECONDS - start ))s."
}
function invoke_build()
{
local failed=false
local dotnet=$(_get_dotnet_path)
log "invoke_build: Start build."
local start=$SECONDS
log ".. .. Build: Source: $TPB_Solution"
# Workaround for https://github.com/dotnet/sdk/issues/335
export FrameworkPathOverride=$TP_PACKAGES_DIR/microsoft.targetingpack.netframework.v4.6/1.0.1/lib/net46/
if [ -z "$PROJECT_NAME_PATTERNS" ]
then
if [[ $TP_USE_REPO_API = 0 ]]; then
$dotnet build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild || failed=true
else
$dotnet build $TPB_Build_From_Source_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild || failed=true
fi
else
find . -name "$PROJECT_NAME_PATTERNS" | xargs -L 1 $dotnet build --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild
fi
log ".. .. Build: Complete."
if [ "$failed" = true ]; then
error "Failed to build solution."
return 2
fi
log "invoke_build: Complete. Elapsed $(( SECONDS - start ))s."
}
function publish_package()
{
local failed=false
local dotnet=$(_get_dotnet_path)
log "publish_package: Started."
local start=$SECONDS
local packageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFramework/$TPB_TargetRuntime
local coreCLRPackageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFrameworkCore
local frameworkPackageDirMap=( \
$TPB_TargetFrameworkCore:$coreCLRPackageDir
)
if [[ $DOTNET_BUILD_FROM_SOURCE = 0 ]]; then
frameworkPackageDirMap+=( \
$TPB_TargetFramework:$packageDir
)
fi
for fxpkg in "${frameworkPackageDirMap[@]}" ;
do
local framework="${fxpkg%%:*}"
local packageDir="${fxpkg##*:}"
local projects=( \
$TP_PACKAGE_PROJ_DIR/package.csproj \
$TP_ROOT_DIR/src/vstest.console/vstest.console.csproj \
$TP_ROOT_DIR/src/datacollector/datacollector.csproj
)
log "Package: Publish projects for $framework"
for project in "${projects[@]}" ;
do
log ".. Package: Publish $project"
$dotnet publish $project --configuration $TPB_Configuration --framework $framework --output $packageDir -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild
done
# Copy TestHost for desktop targets
local testhost=$packageDir/TestHost
mkdir -p $testhost
cp -r src/testhost/bin/$TPB_Configuration/net451/win7-x64/* $testhost
cp -r src/testhost.x86/bin/$TPB_Configuration/net451/win7-x86/* $testhost
# Copy over the logger assemblies to the Extensions folder.
local extensionsDir="$packageDir/Extensions"
# Create an extensions directory.
mkdir -p $extensionsDir
# Note Note: If there are some dependencies for the logger assemblies, those need to be moved too.
# Ideally we should just be publishing the loggers to the Extensions folder.
loggers=("Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll" "Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.pdb")
for i in ${loggers[@]}; do
mv $packageDir/${i} $extensionsDir
done
# Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
runtimeproviders=("Microsoft.TestPlatform.TestHostRuntimeProvider.dll" "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb")
for i in ${runtimeproviders[@]}; do
mv $packageDir/${i} $extensionsDir
done
newtonsoft=$TP_PACKAGES_DIR/newtonsoft.json/9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll
cp $newtonsoft $packageDir
done
# Publish TestHost for netcoreapp1.0 target
log ".. Package: Publish testhost.csproj"
local projectToPackage=$TP_ROOT_DIR/src/testhost/testhost.csproj
local packageOutputPath=$TP_OUT_DIR/$TPB_Configuration/Microsoft.TestPlatform.TestHost/$TPB_TargetFrameworkCore10
$dotnet publish $projectToPackage --configuration $TPB_Configuration --framework $TPB_TargetFrameworkCore10 --output $packageOutputPath -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild
# For libraries that are externally published, copy the output into artifacts. These will be signed and packaged independently.
packageName="Microsoft.TestPlatform.Build"
binariesDirectory="src/$packageName/bin/$TPB_Configuration/**"
publishDirectory="$TP_OUT_DIR/$TPB_Configuration/$packageName"
mkdir -p $publishDirectory
cp -r $binariesDirectory $publishDirectory
log "publish_package: Complete. Elapsed $(( SECONDS - start ))s."
publishplatformatbstractions
}
function publishplatformatbstractions()
{
log "Publish-PlatfromAbstractions-Internal: Started."
local start=$SECONDS
local coreCLRPackageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFrameworkCore10
local platformAbstraction="$TP_ROOT_DIR/src/Microsoft.TestPlatform.PlatformAbstractions/bin/$TPB_Configuration"
local platformAbstractionNetCore=$platformAbstraction/$TPB_TargetFrameworkCore10
cp -r $platformAbstractionNetCore $coreCLRPackageDir
log "Publish-PlatfromAbstractions-Internal: Complete. Elapsed $(( SECONDS - start ))"
}
function create_package()
{
local failed=false
local dotnet=$(_get_dotnet_path)
local start=$SECONDS
log "Create-NugetPackages: Started."
stagingDir="$TP_OUT_DIR/$TPB_Configuration"
packageOutputDir="$TP_OUT_DIR/$TPB_Configuration/packages"
mkdir -p $packageOutputDir
nuspecFiles=("TestPlatform.TranslationLayer.nuspec" "TestPlatform.ObjectModel.nuspec" "TestPlatform.TestHost.nuspec"\
"Microsoft.TestPlatform.nuspec" "Microsoft.TestPlatform.Portable.nuspec" "TestPlatform.CLI.nuspec" "TestPlatform.Build.nuspec" "Microsoft.NET.Test.Sdk.nuspec")
projectFiles=("Microsoft.TestPlatform.CLI.csproj" "Microsoft.TestPlatform.Build.csproj")
binDir="$TP_ROOT_DIR/bin/packages"
for i in ${nuspecFiles[@]}; do
cp $TP_PACKAGE_NUSPEC_DIR/${i} $stagingDir
done
for i in ${projectFiles[@]}; do
cp $TP_PACKAGE_NUSPEC_DIR/${i} $stagingDir
done
# Copy and rename props file.
cp "$TP_PACKAGE_NUSPEC_DIR/Microsoft.NET.Test.Sdk.props" $stagingDir
# Copy over empty and third patry notice file
cp "$TP_PACKAGE_NUSPEC_DIR/_._" $stagingDir
cp "$TP_PACKAGE_NUSPEC_DIR/../ThirdPartyNotices.txt" $stagingDir
for i in ${projectFiles[@]}; do
log "$dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version" \
&& $dotnet restore $stagingDir/${i} \
&& $dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version
done
log "Create-NugetPackages: Elapsed $(( SECONDS - start ))s."
}
#
# Privates
#
_get_dotnet_path()
{
echo "$TP_DOTNET_DIR/dotnet"
}
# Execute build
start=$SECONDS
log "Build started"
log "Test platform environment variables: "
(set | grep ^TP_)
log "Test platform build variables: "
(set | grep ^TPB_)
if [ -z "$PROJECT_NAME_PATTERNS" ]
then
install_cli && restore_package && invoke_build && publish_package && create_package
else
invoke_build
fi
if [[ $? -ne 0 ]]; then
log "Build failed. Elapsed $(( SECONDS - start ))s."
exit 1
fi
log "Build complete. Elapsed $(( SECONDS - start ))s."