forked from ligershark/side-waffle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-debug.ps1
238 lines (196 loc) · 8.79 KB
/
build-debug.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
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
<#
.SYNOPSIS
You can use this script if you are modifying the TemplateBuilder targets
file ligershark.templates.targets and want to try out changes when
building SideWaffle. To use this script you will need to do the following:
1. Create an alias to msbulid.exe
2. Define the environment variable TemplateBuilderDevRoot which should
point to the root template-builder folder, this should end with a \
as well. For example 'C:\Data\personal\mycode\template-builder\'.
.PARAMETER extraBuildArgs
You can now pass in additional arguments for msbuild.exe
Let's say you want to execute a specific target and don't want to hack this file
you can invoke it in the following way
.\build-debug.ps1 -extraBuildArgs '/t:Demo'
.PARAMETER preventOverridingTargetsPath
If this is set the build will still be invoked but the path to the .targets & .tasks file will not be modified. This is useful if you just want to build with the sources in place and use the Debug build configuration
#>
[cmdletbinding(DefaultParameterSetName ='build')]
param(
[Parameter(ParameterSetName='build')]
$extraBuildArgs,
[Parameter(ParameterSetName='build')]
[switch]$preventOverridingTargetsPath,
[Parameter(ParameterSetName='build')]
[switch]$preventOverridingMsbuildPath,
[Parameter(ParameterSetName='optimizeImages')]
[switch]$optimizeImages
)
$global:SideWaffleBuildSettings = New-Object PSObject -Property @{
TempFolder = ("$env:LOCALAPPDATA\SideWaffle\BuildOutput\")
MaxNumThreads = ((Get-WmiObject Win32_Processor).NumberOfCores)
}
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$script:scrDir = (Get-ScriptDirectory)
$script:toolsRoot = (Join-Path -Path (Get-ScriptDirectory) -ChildPath Tools\)
# There are a few things which this script requires
# msbuild alias
# TemplateBuilderDevRoot : Environment variable
# When called it will return true if all dependencies are found, and false if not
function CheckForDependencies{
$depFound = $true
# check for the msbuild alias othewise set it to use
if(!(Get-Alias msbuild)){
$msbuildDefaultPath = ("{0}\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" -f $env:windir);
# check to see if it is in the default location
if(Test-Path $msbuildDefaultPath){
Set-Alias msbuild $msbuildDefaultPath -Scope Global
}
else{
"Unable to locate msbuild.exe. Set the alias 'msbuild' and try again" | Write-Error
$depFound = $false
}
}
if(!$env:TemplateBuilderDevRoot){
"Missing required environment variable TemplateBuilderDevRoot. Please define it and try again" | Write-Error
$depFound = $false
}
elseif(!(Test-Path $env:TemplateBuilderDevRoot)){
"TemplateBuilderDevRoot not found at [{0}]" -f $env:TemplateBuilderDevRoot | Write-Error
$depFound = $false
}
else{
# check to see if $env:TemplateBuilderDevRoot does not end with a '\' and warn the user if not
if(!(($env:TemplateBuilderDevRoot).EndsWith('\'))){
'$env:TemplateBuilderDevRoot does not end with a \ which is expected. Things may not go as planned.' | Write-Warning
}
}
return $depFound
}
function OptimizeImages(){
[cmdletbinding()]
param(
$root = (Join-Path -Path $script:scrDir -ChildPath TemplatePack\),
[switch]
$Recurse
)
process{
'Optimizing images in directory [{0}]' -f $root | Write-Verbose
if($Recurse){
$pngsToOptimize = (Get-ChildItem $root *.png -Recurse)
}
else{
$pngsToOptimize = (Get-ChildItem $root *.png)
}
if($pngsToOptimize){
$pngsToOptimize = ($pngsToOptimize |
Where-Object { !$_.FullName.Contains('\obj\')} |
Where-Object { !$_.FullName.Contains('\bin\')})
}
$beforeOptimizing = ($pngsToOptimize.FullName | Get-Item | Select-Object FullName, Length)
'Number of .pngs to optimize: [{0}]' -f $pngsToOptimize.Length | Write-Verbose
$pngsToOptimize.FullName | OptimizePng
$afterOptimizing = ($pngsToOptimize.FullName | Get-Item | Select-Object FullName, Length)
$delta = @()
foreach($item in $beforeOptimizing){
$beforeItem = $item
$afterItem = ($afterOptimizing | Where-Object {$_.FullName -eq $item.FullName})
$deltaObj = New-Object PSObject -Property @{
FullName = $beforeItem.FullName
LengthBefore = $beforeItem.Length
LengthAfter = [int]::MinValue
LengthDiff = [int]::MinValue
}
if(!$afterItem){
'Unable to find matching file in after collection for file [{0}]' -f $_.FullName | Write-Error
}
else{
$deltaObj.LengthAfter = $afterItem.Length
$deltaObj.LengthDiff = ($beforeItem.Length - $afterItem.Length)
}
$delta += $deltaObj
}
$imgReportPath = (Join-Path -Path $global:SideWaffleBuildSettings.TempFolder -ChildPath 'imagereport.csv')
if(!(Test-Path $global:SideWaffleBuildSettings.TempFolder)){
mkdir $global:SideWaffleBuildSettings.TempFolder
}
$delta | Select-Object FullName, LengthBefore, LengthAfter,LengthDiff | Export-Csv -Path $imgReportPath -NoTypeInformation
'Saved image report to [{0}]' -f $imgReportPath | Write-Verbose
return $delta
}
}
function OptimizePng(){
[cmdletbinding()]
param(
[Parameter(
Mandatory=$true,
ValueFromPipeline=$true)]
$image
)
begin{
$pngout = Join-Path $script:toolsRoot pngout.exe
$pngoptim = Join-Path $script:toolsRoot PNGOptim.1.2.2.exe
}
process{
foreach($img in $image){
$fullPath = Resolve-Path $img
$pngoutArgs = @()
$pngoutArgs += $fullPath
$pngoutArgs += '/q'
'Calling pngout [{0} {1}]' -f $pngout, ($pngoutArgs -join ' ') | Write-Verbose
&$pngout $pngoutArgs
}
}
}
if($optimizeImages){
'optimizing images' | Write-Verbose
$imgResult = OptimizeImages -root $script:scrDir -Recurse
$imgResult |
Select-Object @{Name='Name';Expression={(get-item $_.FullName).Name}},LengthBefore,LengthAfter,LengthDiff |
Sort-Object LengthDiff -Descending |
Write-Output
'Total diff: {0} KB' -f (($imgResult | Measure-Object -Property LengthDiff -Sum | Select-Object Sum).Sum/1KB) | Write-Output
}
else {
$scriptDir = ((Get-ScriptDirectory) + "\")
$templateBuilderTargetsPath = ("{0}tools\ligershark.templates.targets" -f $env:TemplateBuilderDevRoot)
$templateTaskRoot = ("{0}src\LigerShark.TemplateBuilder.Tasks\bin\Debug\" -f $env:TemplateBuilderDevRoot)
if(-not $preventOverridingMsbuildPath){
Set-MSBuild "$env:windir\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
}
if(CheckForDependencies){
"Dep check passed" | Write-Host
# msbuild ".\TemplatePack\TemplatePack.csproj"
# /p:VisualStudioVersion=11.0
# /p:TemplateBuilderTargets="($env:TemplateBuilderDevRoot)tools\ligershark.templates.targets"
# /p:ls-TasksRoot="($env:TemplateBuilderDevRoot)\src\LigerShark.TemplateBuilder.Tasks\bin\Debug\" /fl
# /flp1:v=d;logfile=build.d.log /flp2:v=diag;logfile=build.diag.log
$msbuildArgs = @()
$msbuildArgs += ('{0}TemplatePack\TemplatePack.csproj' -f $scriptDir)
$msbuildArgs += '/m'
$msbuildArgs += '/nologo'
# https://github.com/ligershark/side-waffle/issues/108
# Cmd line build not working for Debug mode for some reason
$msbuildArgs += ("/p:Configuration=Debug")
$msbuildArgs += ("/p:VisualStudioVersion=12.0")
if(!$preventOverridingTargetsPath){
$msbuildArgs += ("/p:TemplateBuilderTargets={0}" -f $templateBuilderTargetsPath)
$msbuildArgs += ("/p:ls-TasksRoot={0}" -f $templateTaskRoot)
}
$msbuildArgs += '/flp1:v=d;logfile=msbuild.d.log'
$msbuildArgs += '/flp2:v=diag;logfile=msbuild.diag.log'
$msbuildArgs += ('/clp:v=m;ShowCommandLine')
if($extraBuildArgs){
$msbuildArgs += $extraBuildArgs
}
"Calling msbuild.exe with the following args: {0}" -f ($msbuildArgs -join ' ') | Write-Host
& msbuild $msbuildArgs
"`r`n MSBuild log files have been written to" | Write-Host -ForegroundColor Green
" msbuild.d.log" | Write-Host -ForegroundColor Green
" msbuild.diag.log" | Write-Host -ForegroundColor Green
}
}