-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.ps1
169 lines (151 loc) · 5.19 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
##########################################################################
# This is the Cake bootstrapper script for PowerShell.
# This version was download from https://github.com/larzw/Cake.Paket
# It was modified to use paket (instead of NuGet) for dependency management.
# Feel free to change this file to fit your needs.
##########################################################################
<#
.SYNOPSIS
This is a Powershell script to bootstrap a Cake build.
.DESCRIPTION
This Powershell script will download paket.exe if missing,
install all your dependencies via paket.exe restore
and execute your Cake build script with the parameters you provide.
.PARAMETER Script
The build script to execute.
.PARAMETER Target
The build script target to run.
.PARAMETER Configuration
The build configuration to use.
.PARAMETER Verbosity
Specifies the amount of information to be displayed.
.PARAMETER Experimental
Tells Cake to use the latest Roslyn release.
.PARAMETER WhatIf
Performs a dry run of the build script.
No tasks will be executed.
.PARAMETER Mono
Tells Cake to use the Mono scripting engine.
.PARAMETER Paket
The relative path to the .paket directory.
.PARAMETER Cake
The relative path to directory containing Cake.exe.
.PARAMETER Tools
The relative path to the Cake tools directory.
.PARAMETER Addins
The relative path to the Cake addins directory.
.PARAMETER Modules
The relative path to the Cake modules directory.
.PARAMETER ScriptArgs
Remaining arguments are added here.
.LINK
http://cakebuild.net
#>
[CmdletBinding()]
Param(
[string]$Script = "setup.cake",
[string]$Target = "Default",
[ValidateSet("Release", "Debug")]
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[switch]$Experimental,
[Alias("DryRun","Noop")]
[switch]$WhatIf,
[switch]$Mono,
[ValidatePattern('.paket$')]
[string]$Paket = ".\.paket",
[string]$Cake = ".\packages\tools\Cake",
[string]$Tools = ".\packages\tools",
[string]$Addins = ".\packages\addins",
[string]$Modules = ".\packages\modules",
[switch]$MsBuild,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)
Write-Host "Preparing to run build script..."
# Should we use mono?
$UseMono = "";
if($Mono.IsPresent) {
Write-Verbose -Message "Using the Mono based scripting engine."
$UseMono = "-mono"
}
# Should we use the new Roslyn?
$UseExperimental = "";
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
Write-Verbose -Message "Using experimental version of Roslyn."
$UseExperimental = "-experimental"
}
# Is this a dry run?
$UseDryRun = "";
if($WhatIf.IsPresent) {
$UseDryRun = "-dryrun"
}
Write-Verbose -Message "Using paket for dependency management..."
# Make sure the .paket directory exits
$PaketDir = Resolve-Path $Paket
if(!(Test-Path $PaketDir)) {
Throw "Could not find .paket directory at $PaketDir"
}
Write-Verbose -Message "Found .paket in PATH at $PaketDir"
# Set paket directory enviornment variable
$ENV:PAKET = $PaketDir
# If paket.exe does not exits then download it using paket.bootstrapper.exe
$PAKET_EXE = Join-Path $PaketDir "paket.exe"
if (!(Test-Path $PAKET_EXE)) {
# If paket.bootstrapper.exe exits then run it.
$PAKET_BOOTSTRAPPER_EXE = Join-Path $PaketDir "paket.bootstrapper.exe"
if (!(Test-Path $PAKET_BOOTSTRAPPER_EXE)) {
Throw "Could not find paket.bootstrapper.exe at $PAKET_BOOTSTRAPPER_EXE"
}
Write-Verbose -Message "Found paket.bootstrapper.exe in PATH at $PAKET_BOOTSTRAPPER_EXE"
# Download paket.exe
Write-Verbose -Message "Running paket.bootstrapper.exe to download paket.exe"
Invoke-Expression $PAKET_BOOTSTRAPPER_EXE
if (!(Test-Path $PAKET_EXE)) {
Throw "Could not find paket.exe at $PAKET_EXE"
}
}
# Install the dependencies
if ($MsBuild) {
Write-Verbose -Message "Running msbuild -t:Restore Source"
Invoke-Expression "msbuild -t:Restore -p:Configuration=$CONFIGURATION Source"
} else {
Write-Verbose -Message "Running dotnet restore Source"
Invoke-Expression "dotnet restore Source"
}
# tools
if (Test-Path $Tools) {
$ToolsDir = Resolve-Path $Tools
$ENV:CAKE_PATHS_TOOLS = $ToolsDir
}
else {
Write-Verbose -Message "Could not find tools directory at $Tools"
}
# addins
if (Test-Path $Addins) {
$AddinsDir = Resolve-Path $Addins
$ENV:CAKE_PATHS_ADDINS = $AddinsDir
}
else {
Write-Verbose -Message "Could not find addins directory at $Addins"
}
# modules
if (Test-Path $Modules) {
$ModulesDir = Resolve-Path $Modules
$ENV:CAKE_PATHS_MODULES = $ModulesDir
}
else {
Write-Verbose -Message "Could not find modules directory at $Modules"
}
# Make sure that Cake has been installed.
$CakeDir = Resolve-Path $Cake
$CAKE_EXE = Join-Path $CakeDir "Cake.exe"
if (!(Test-Path $CAKE_EXE)) {
Throw "Could not find Cake.exe at $CAKE_EXE"
}
Write-Verbose -Message "Found Cake.exe in PATH at $CAKE_EXE"
# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" -msbuild=`"$MsBuild`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
exit $LASTEXITCODE