-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
build.ps1
203 lines (167 loc) · 6.71 KB
/
build.ps1
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
[CmdletBinding()]
Param(
[string]$Target = "Run-All-Tests",
[switch]$SkipBuildingCake
)
#####################################################################
# FUNCTIONS
#####################################################################
Function CleanDirectory([string]$Directory)
{
if(Test-Path $Directory) {
Remove-Item -Path $Directory -Recurse -Force
}
New-Item -Path $Directory -Type Directory | Out-Null
}
Function BuildCake([string]$ScriptRoot)
{
# Clean the build directory.
$RootDirectory = (Join-Path $ScriptRoot "../..")
CleanDirectory((Join-Path $RootDirectory "artifacts"))
# Build Cake.
try {
Push-Location
Set-Location $RootDirectory
Invoke-Expression "./build.ps1 -Target Copy-Files" | Out-Null
if($LASTEXITCODE -ne 0) {
Throw "An error occured while building Cake."
}
}
finally {
Pop-Location
}
}
Function GetCakePath([string]$ScriptRoot)
{
Return (Get-ChildItem -Path (Join-Path $ScriptRoot "../../artifacts" -Resolve) -Filter "Cake.exe" -Recurse | Sort-Object -Property LastWriteTime -Descending | Select -First 1).Directory.FullName
}
Function GetCakeCoreCLRPath([string]$ScriptRoot)
{
Return (Get-ChildItem -Path (Join-Path $ScriptRoot "../../artifacts" -Resolve) -Filter "Cake.dll" -Recurse | Sort-Object -Property LastWriteTime -Descending | Select -First 1).Directory.FullName
}
#####################################################################
# PREPARATION
#####################################################################
$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition
$Script = (Join-Path $PSScriptRoot "windows.cake")
$MonoScript = (Join-Path $PSScriptRoot "build.cake")
$ToolsPath = Join-Path $PSScriptRoot "tools"
$NuGetPath = Join-Path $ToolsPath "nuget.exe"
$DotNetChannel = "rel-1.0.1"
$DotNetVersion = "1.0.1"
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v1.0.1/scripts/obtain/dotnet-install.ps1"
$NuGetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
# Make sure the tools directory exist.
if(!(Test-Path $ToolsPath)) {
Write-Verbose "Creating tools directory..."
New-Item -Path $ToolsPath -Type Directory | Out-Null
}
###########################################################################
# INSTALL .NET CORE CLI
###########################################################################
Function Remove-PathVariable([string]$VariableToRemove)
{
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
}
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}
}
# Get .NET Core CLI path if installed.
$FoundDotNetCliVersion = $null
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$FoundDotNetCliVersion = dotnet --version
}
if($FoundDotNetCliVersion -ne $DotNetVersion) {
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
if (!(Test-Path $InstallPath)) {
mkdir -Force $InstallPath | Out-Null
}
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1")
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath
Remove-PathVariable "$InstallPath"
$env:PATH = "$InstallPath;$env:PATH"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
}
dotnet --info
#####################################################################
# BUILD CAKE
#####################################################################
# Build Cake.
if(!$SkipBuildingCake.IsPresent) {
Write-Host "Building Cake..."
BuildCake($PSScriptRoot)
}
# Get the built Cake path.
$BuiltCakePath = GetCakePath($PSScriptRoot)
if([string]::IsNullOrWhiteSpace($BuiltCakePath)) {
Throw "Could not resolve built Cake path."
}
$BuiltCakeCoreCLRPath = GetCakeCoreCLRPath($PSScriptRoot)
if([string]::IsNullOrWhiteSpace($BuiltCakeCoreCLRPath)) {
Throw "Could not resolve built Cake CoreCLR path."
}
# Get the local Cake path.
$CakePath = Join-Path $ToolsPath "Cake"
$CakeCoreCLRPath = Join-Path $ToolsPath "Cake.CoreCLR"
$CakeExePath = Join-Path $CakePath "Cake.exe"
$CakeDllPath = Join-Path $CakeCoreCLRPath "Cake.dll"
# Clean the local Cake path.
if(!$SkipBuildingCake.IsPresent) {
CleanDirectory($ToolsPath)
New-Item -Path $CakePath -Type Directory | Out-Null
New-Item -Path $CakeCoreCLRPath -Type Directory | Out-Null
Copy-Item "$BuiltCakePath/*.*" $CakePath -Recurse
Copy-Item "$BuiltCakeCoreCLRPath/*.*" $CakeCoreCLRPath -Recurse
}
# Ensure that Cake can be found where we expect it to.
if(!(Test-Path $CakeExePath)) {
Throw "Could not locate Cake at $CakeExePath."
}
# Ensure that Cake CoreCLR can be found where we expect it to.
if(!(Test-Path $CakeDllPath)) {
Throw "Could not locate Cake CoreCLR at $CakeDllPath."
}
# Make sure NuGet exist.
if (!(Test-Path $NuGetPath)) {
Write-Verbose "Downloading NuGet..."
(New-Object System.Net.WebClient).DownloadFile($NuGetUrl, $NuGetPath)
if (!(Test-Path $NuGetPath)) {
Throw "Could not find NuGet.exe"
}
}
#####################################################################
# SETUP ENVIRONMENT
#####################################################################
$Env:MyEnvironmentVariable = "Hello World"
#####################################################################
# RUN TESTS
#####################################################################
[int] $TestResult = 0
# Run tests using new Cake.
&$CakeExePath "--version"
Write-Output "Running integration tests..."
&$CakeExePath "$Script" "--target=$Target" "--verbosity=quiet" "--platform=windows" "--customarg=hello"
$TestResult+=$LASTEXITCODE
Write-Output ""
# Run tests using new Cake.
&$CakeExePath "--version"
Write-Output "Running integration tests mono scripting..."
&$CakeExePath "$MonoScript" --mono "--target=$Target" "--verbosity=quiet" "--platform=windows" "--customarg=hello"
$TestResult+=$LASTEXITCODE
Write-Output ""
# Run tests using new Cake.
&dotnet $CakeDllPath "--version"
Write-Output "Running CoreCLR integration tests..."
&dotnet $CakeDllPath "$Script" "--target=$Target" "--verbosity=quiet" "--platform=windows" "--customarg=hello"
$TestResult+=$LASTEXITCODE
Write-Output ""
Exit $TestResult