-
Notifications
You must be signed in to change notification settings - Fork 62
/
build.ps1
238 lines (191 loc) · 5.68 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
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
# reference to System.*
$SysDirectory = [System.IO.Directory]
$SysPath = [System.IO.Path]
$SysFile = [System.IO.File]
# Default to Debug
$Configuration = 'Debug'
# Color
$Success = 'Green'
$Warning = 'Yellow'
$Err = 'Red'
if ($args.Count -eq 0)
{
$TestType = 'All'
$Configuration = 'Release'
}
elseif ($args[0] -match 'DisableSkipStrongName')
{
$TestType = "DisableSkipStrongName"
}
elseif ($args[0] -match 'EnableSkipStrongName')
{
$TestType = "EnableSkipStrongName"
}
elseif ($args[0] -match 'SkipStrongName')
{
# SkipStrongName is a legacy options.
$TestType = "EnableSkipStrongName"
}
else
{
Write-Host 'Please choose Test or StrongName!' -ForegroundColor $Err
exit
}
$PROGRAMFILESX86 = [Environment]::GetFolderPath("ProgramFilesX86")
$env:ENLISTMENT_ROOT = Split-Path -Parent $MyInvocation.MyCommand.Definition
$ENLISTMENT_ROOT = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Figure out the directory and path for SN.exe
$SN = $null
$SNx64 = $null
$SNVersions = @()
ForEach ($directory in $SysDirectory::EnumerateDirectories($PROGRAMFILESX86 + "\Microsoft SDKs\Windows", "*A"))
{
# remove the first char 'v'
$directoryName = $SysPath::GetFileName($directory).substring(1)
# remove the last char 'A'
$directoryName = $directoryName.substring(0, $directoryName.LastIndexOf('A'))
# parse to double "10.0"
$versionNo = [System.Double]::Parse($directoryName)
$fileobject = $null
$fileobject = New-Object System.Object
$fileobject | Add-Member -type NoteProperty -Name version -Value $versionNo
$fileobject | Add-Member -type NoteProperty -Name directory -Value $directory
$SNVersions += $fileobject
}
# using the latest version
$SNVersions = $SNVersions | Sort-Object -Property version -Descending
ForEach ($ver in $SNVersions)
{
# only care about the folder has "bin" subfolder
$snBinDirectory = $ver.directory + "\bin"
if(!$SysDirectory::Exists($snBinDirectory))
{
continue
}
if($SysFile::Exists($snBinDirectory + "\sn.exe") -and $SysFile::Exists($snBinDirectory + "\x64\sn.exe"))
{
$SN = $snBinDirectory + "\sn.exe"
$SNx64 = $snBinDirectory + "\x64\sn.exe"
break
}
else
{
ForEach ($netFxDirectory in $SysDirectory::EnumerateDirectories($snBinDirectory, "NETFX * Tools") | Sort -Descending)
{
# currently, sorting descending for the NETFX version looks good.
if($SysFile::Exists($netFxDirectory + "\sn.exe") -and $SysFile::Exists($netFxDirectory + "\x64\sn.exe"))
{
$SN = $netFxDirectory + "\sn.exe"
$SNx64 = $netFxDirectory + "\x64\sn.exe"
break
}
}
}
if ($SN -ne $null -and $SNx64 -ne $null)
{
break
}
}
# Other variables
$ProductProj = $ENLISTMENT_ROOT + "\src\Microsoft.OpenAPI.OData.Reader\Microsoft.OpenApi.OData.Reader.csproj"
$TESTProj = $ENLISTMENT_ROOT + "\test\Microsoft.OpenAPI.OData.Reader.Tests\Microsoft.OpenApi.OData.Reader.Tests.csproj"
$TESTDIR = $ENLISTMENT_ROOT + "\bin\$Configuration\Test\net472"
$PRODUCTDIR = $ENLISTMENT_ROOT + "\bin\$Configuration\net472"
$ProductDlls = "Microsoft.OpenApi.OData.Reader.dll"
$XUnitTestDlls = "Microsoft.OpenApi.OData.Reader.Tests.dll"
Function GetDlls
{
$dlls = @()
ForEach($dll in $ProductDlls)
{
$dlls += $PRODUCTDIR + "\" + $dll
}
ForEach($dll in $XUnitTestDlls)
{
$dlls += $TESTDIR + "\" + $dll
}
return $dlls
}
Function SkipStrongName
{
Write-Host 'Skip strong name validations for Microsoft.OpenApi.OData assemblies...'
$dlls = GetDlls
ForEach ($dll in $dlls)
{
& $SN /Vr $dll
}
ForEach ($dll in $dlls)
{
& $SNx64 /Vr $dll
}
Write-Host "SkipStrongName Done" -ForegroundColor $Success
}
Function DisableSkipStrongName
{
$SnLog = $LOGDIR + "\DisableSkipStrongName.log"
Out-File $SnLog
Write-Host 'Disable skip strong name validations for Microsoft.OpenApi.OData assemblies...'
$dlls = GetDlls
ForEach ($dll in $dlls)
{
& $SN /Vu $dll | Out-File $SnLog -Append
}
ForEach ($dll in $dlls)
{
& $SNx64 /Vu $dll | Out-File $SnLog -Append
}
Write-Host "DisableSkipStrongName Done" -ForegroundColor $Success
}
Function Cleanup
{
#TODO: Add some clean tasks
Write-Host "Clean Done" -ForegroundColor $Success
}
Function CleanBeforeScorch
{
#TODO: Add some clean tasks
Write-Host "Clean Done" -ForegroundColor $Success
}
Function BuildProcess
{
Write-Host '**********Start To Build The Project*********'
$script:BUILD_START_TIME = Get-Date
Write-Host "Build Product ..."
& dotnet.exe build $ProductProj -c $Configuration
Write-Host "Build Test ..."
& dotnet.exe build $TESTProj -c $Configuration
Write-Host "Build Done" -ForegroundColor $Success
$script:BUILD_END_TIME = Get-Date
}
Function TestProcess
{
Write-Host '**********Start To Run The Test*********'
$script:TEST_START_TIME = Get-Date
& dotnet test $TESTProj -c $Configuration
Write-Host "Test Done" -ForegroundColor $Success
$script:TEST_END_TIME = Get-Date
}
# Main Process
if ($TestType -eq 'EnableSkipStrongName')
{
CleanBeforeScorch
BuildProcess
SkipStrongName
Exit
}
elseif ($TestType -eq 'DisableSkipStrongName')
{
CleanBeforeScorch
BuildProcess
DisableSkipStrongName
Exit
}
CleanBeforeScorch
BuildProcess
SkipStrongName
TestProcess
Cleanup
$buildTime = New-TimeSpan $script:BUILD_START_TIME -end $script:BUILD_END_TIME
$testTime = New-TimeSpan $script:TEST_START_TIME -end $script:TEST_END_TIME
Write-Host("Build time:`t" + $buildTime)
Write-Host("Test time:`t" + $testTime)