-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathrestore-toolset.sh
executable file
·117 lines (96 loc) · 3.48 KB
/
restore-toolset.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
#!/usr/bin/env bash
function InitializeCustomSDKToolset {
if [[ "$restore" != true ]]; then
return
fi
# The following frameworks and tools are used only for testing.
# Do not attempt to install them in source build.
if [[ $product_build == true || $properties == *"DotNetBuildRepo=true"* ]]; then
return
fi
DISTRO=
MAJOR_VERSION=
if [ -e /etc/os-release ]; then
. /etc/os-release
DISTRO="$ID"
MAJOR_VERSION="${VERSION_ID:+${VERSION_ID%%.*}}"
fi
InitializeDotNetCli true
InstallDotNetSharedFramework "6.0.0"
InstallDotNetSharedFramework "7.0.0"
InstallDotNetSharedFramework "8.0.0"
InstallDotNetSharedFramework "9.0.0"
CreateBuildEnvScript
}
# Installs additional shared frameworks for testing purposes
function InstallDotNetSharedFramework {
local version=$1
local dotnet_root=$DOTNET_INSTALL_DIR
local fx_dir="$dotnet_root/shared/Microsoft.NETCore.App/$version"
if [[ ! -d "$fx_dir" ]]; then
GetDotNetInstallScript "$dotnet_root"
local install_script=$_GetDotNetInstallScript
bash "$install_script" --version $version --install-dir "$dotnet_root" --runtime "dotnet" --skip-non-versioned-files
local lastexitcode=$?
if [[ $lastexitcode != 0 ]]; then
echo "Failed to install Shared Framework $version to '$dotnet_root' (exit code '$lastexitcode')."
ExitWithExitCode $lastexitcode
fi
fi
}
function CreateBuildEnvScript {
mkdir -p $artifacts_dir
scriptPath="$artifacts_dir/sdk-build-env.sh"
scriptContents="
#!/usr/bin/env bash
export DOTNET_MULTILEVEL_LOOKUP=0
export DOTNET_ROOT=$DOTNET_INSTALL_DIR
export DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=$DOTNET_INSTALL_DIR
export PATH=$DOTNET_INSTALL_DIR:\$PATH
export NUGET_PACKAGES=$NUGET_PACKAGES
"
echo "$scriptContents" > ${scriptPath}
}
# ReadVersionFromJson [json key]
function ReadGlobalVersion {
local key=$1
if command -v jq &> /dev/null; then
_ReadGlobalVersion="$(jq -r ".[] | select(has(\"$key\")) | .\"$key\"" "$global_json_file")"
elif [[ "$(cat "$global_json_file")" =~ \"$key\"[[:space:]\:]*\"([^\"]+) ]]; then
_ReadGlobalVersion=${BASH_REMATCH[1]}
fi
if [[ -z "$_ReadGlobalVersion" ]]; then
Write-PipelineTelemetryError -category 'Build' "Error: Cannot find \"$key\" in $global_json_file"
ExitWithExitCode 1
fi
}
function CleanOutStage0ToolsetsAndRuntimes {
ReadGlobalVersion "dotnet"
local dotnetSdkVersion=$_ReadGlobalVersion
local dotnetRoot=$DOTNET_INSTALL_DIR
local versionPath="$dotnetRoot/.version"
local majorVersion="${dotnetSdkVersion:0:1}"
local aspnetRuntimePath="$dotnetRoot/shared/Microsoft.AspNetCore.App/$majorVersion.*"
local coreRuntimePath="$dotnetRoot/shared/Microsoft.NETCore.App/$majorVersion.*"
local wdRuntimePath="$dotnetRoot/shared/Microsoft.WindowsDesktop.App/$majorVersion.*"
local sdkPath="$dotnetRoot/sdk/*"
if [ -f "$versionPath" ]; then
local lastInstalledSDK=$(cat $versionPath)
if [[ "$lastInstalledSDK" != "$dotnetSdkVersion" ]]; then
echo $dotnetSdkVersion > $versionPath
rm -rf $aspnetRuntimePath
rm -rf $coreRuntimePath
rm -rf $wdRuntimePath
rm -rf $sdkPath
rm -rf "$dotnetRoot/packs"
rm -rf "$dotnetRoot/sdk-manifests"
rm -rf "$dotnetRoot/templates"
Write-PipelineTelemetryError -category 'Build' "Found old version of SDK, cleaning out folder. Please run build.sh again"
ExitWithExitCode 1
fi
else
echo $dotnetSdkVersion > $versionPath
fi
}
InitializeCustomSDKToolset
CleanOutStage0ToolsetsAndRuntimes