forked from ponylang/ponyc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.ps1
506 lines (460 loc) · 20.1 KB
/
make.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
Param(
[Parameter(Position=0, HelpMessage="Enter the action to take, e.g. libs, cleanlibs, configure, build, clean, distclean, test, install.")]
[string]
$Command = 'build',
[Parameter(HelpMessage="The build configuration (Release, Debug, RelWithDebInfo, MinSizeRel).")]
[string]
$Config = "Release",
[Parameter(HelpMessage="The CMake generator, e.g. `"Visual Studio 16 2019`"")]
[string]
$Generator = "default",
[Parameter(HelpMessage="The architecture to use for compiling, e.g. `"x64`"")]
[string]
$Arch = "x64",
[Parameter(HelpMessage="The location to install to")]
[string]
$Prefix = "default",
[Parameter(HelpMessage="The version to use when packaging")]
[string]
$Version = "default",
[Parameter(HelpMessage="Whether or not to turn on LTO")]
[string]
$Lto = "no",
[Parameter(HelpMessage="Whether or not to run tests in LLDB debugger")]
[string]
$Uselldb = "no",
[Parameter(HelpMessage="Tests to run")]
[string]
$TestsToRun = 'libponyrt.tests,libponyc.tests,libponyc.run.tests.debug,libponyc.run.tests.release,stdlib-debug,stdlib-release,grammar'
)
$srcDir = Split-Path $script:MyInvocation.MyCommand.Path
switch ($Version)
{
"default" { $Version = (Get-Content $srcDir\VERSION) + "-" + (git rev-parse --short --verify HEAD) }
"nightly" { $Version = "nightly" + (Get-Date).ToString("yyyyMMdd") }
"date" { $Version = (Get-Date).ToString("yyyyMMdd") }
}
# Sanitize config to conform to CMake build configs.
switch ($Config.ToLower())
{
"release" { $Config = "Release"; break; }
"debug" { $Config = "Debug"; break; }
"relwithdebinfo" { $Config = "RelWithDebInfo"; break; }
"minsizerel" { $Config = "MinSizeRel"; break; }
default { throw "'$Config' is not a valid config; use Release, Debug, RelWithDebInfo, or MinSizeRel)." }
}
$config_lower = $Config.ToLower()
if ($null -eq (Get-Command "cmake.exe" -ErrorAction SilentlyContinue)) {
Write-Output "Warning, unable to find cmake.exe in your PATH, trying to discover one in Visual Studio installation."
Push-Location
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhere -PathType Leaf ) {
$cmakePath = $(Get-Item $( Invoke-Expression '& "$vswhere" -prerelease -latest -requires Microsoft.VisualStudio.Component.VC.CMake.Project -find Common7/IDE/**/cmake.exe ' )).Directory.FullName
if ($null -ne $cmakePath) {
$env:Path = "$env:Path;$cmakePath"
Write-Output "Success, CMake added to current PATH from $cmakePath"
} else {
Write-Output "Your latest Visual Studio installation does not include CMake package."
}
} else {
Write-Output "No Visual Studio 2017+ was found in the system."
}
Pop-Location
}
if ($Generator -eq "default")
{
$Generator = cmake --help | Where-Object { $_ -match '\*\s+(.*\S)\s+(\[arch\])?\s+=' } | Foreach-Object { $Matches[1].Trim() } | Select-Object -First 1
}
if ($Generator -match 'Visual Studio')
{
$buildDir = Join-Path -Path $srcDir -ChildPath "build\build"
}
else
{
$buildDir = Join-Path -Path $srcDir -ChildPath "build\build_$config_lower"
}
# Some CI services build inside the temp directory, which MSVC doesn't like.
$tempPath = [IO.Path]::GetFullPath($env:TEMP)
$buildPath = [IO.Path]::GetFullPath((Join-Path -Path $srcDir -ChildPath "build"))
if ($buildPath.StartsWith($tempPath, [StringComparison]::OrdinalIgnoreCase))
{
$newTempPath = Join-Path -Path $srcDir -ChildPath "tempdir"
if (!(Test-Path $newTempPath -PathType Leaf))
{
New-Item $newTempPath -ItemType Directory
}
$env:TMP = $newTempPath
$env:TEMP = $newTempPath
}
$libsDir = Join-Path -Path $srcDir -ChildPath "build\libs"
$outDir = Join-Path -Path $srcDir -ChildPath "build\$config_lower"
Write-Output "Source directory: $srcDir"
Write-Output "Build directory: $buildDir"
Write-Output "Libs directory: $libsDir"
Write-Output "Output directory: $outDir"
Write-Output "Temp directory: $env:TEMP"
if ($Prefix -eq "default")
{
$Prefix = Join-Path -Path $srcDir -ChildPath "build\install"
}
elseif (![System.IO.Path]::IsPathRooted($Prefix))
{
$Prefix = Join-Path -Path $srcDir -ChildPath $Prefix
}
Write-Output "make.ps1 $Command -Config $Config -Generator `"$Generator`" -Prefix `"$Prefix`" -Version `"$Version`""
if (($Command.ToLower() -ne "libs") -and ($Command.ToLower() -ne "distclean") -and !(Test-Path -Path $libsDir))
{
throw "Libs directory '$libsDir' does not exist; you may need to run 'make.ps1 libs' first."
}
if ($Generator.Contains("Win64") -or $Generator.Contains("Win32"))
{
$Arch = ""
}
switch ($Command.ToLower())
{
"dummy" { break }
"libs"
{
if (!(Test-Path -Path $libsDir))
{
New-Item -ItemType "directory" -Path $libsDir | Out-Null
}
$libsBuildDir = Join-Path -Path $srcDir -ChildPath "build\build_libs"
if (!(Test-Path -Path $libsBuildDir))
{
New-Item -ItemType "directory" -Path $libsBuildDir | Out-Null
}
$libsSrcDir = Join-Path -Path $srcDir -ChildPath "lib"
Write-Output "Configuring libraries..."
if ($Arch.Length -gt 0)
{
& cmake.exe -B "$libsBuildDir" -S "$libsSrcDir" -G "$Generator" -A $Arch -Thost=x64 -DCMAKE_INSTALL_PREFIX="$libsDir" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;WebAssembly;RISCV"
$err = $LastExitCode
}
else
{
& cmake.exe -B "$libsBuildDir" -S "$libsSrcDir" -G "$Generator" -Thost=x64 -DCMAKE_INSTALL_PREFIX="$libsDir" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;WebAssembly;RISCV"
$err = $LastExitCode
}
if ($err -ne 0) { throw "Error: exit code $err" }
# Write-Output "Building libraries..."
Write-Output "cmake.exe --build `"$libsBuildDir`" --target install --config Release"
& cmake.exe --build "$libsBuildDir" --target install --config Release
$err = $LastExitCode
if ($err -ne 0) { throw "Error: exit code $err" }
break
}
"cleanlibs"
{
if (Test-Path -Path $libsDir)
{
Write-Output "Removing $libsDir..."
Remove-Item -Path $libsDir -Recurse -Force
}
break
}
"configure"
{
$lto_flag = ""
if ($Lto -eq "yes")
{
$lto_flag = "-DPONY_USE_LTO=true"
}
if ($Arch.Length -gt 0)
{
Write-Output "cmake.exe -B `"$buildDir`" -S `"$srcDir`" -G `"$Generator`" -A $Arch -Thost=x64 -DCMAKE_INSTALL_PREFIX=`"$Prefix`" -DCMAKE_BUILD_TYPE=`"$Config`" -DPONYC_VERSION=`"$Version`""
& cmake.exe -B "$buildDir" -S "$srcDir" -G "$Generator" -A $Arch -Thost=x64 -DCMAKE_INSTALL_PREFIX="$Prefix" -DCMAKE_BUILD_TYPE="$Config" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPONYC_VERSION="$Version" $lto_flag --no-warn-unused-cli
}
else
{
Write-Output "cmake.exe -B `"$buildDir`" -S `"$srcDir`" -G `"$Generator`" -Thost=x64 -DCMAKE_INSTALL_PREFIX=`"$Prefix`" -DCMAKE_BUILD_TYPE=`"$Config`" -DPONYC_VERSION=`"$Version`""
& cmake.exe -B "$buildDir" -S "$srcDir" -G "$Generator" -Thost=x64 -DCMAKE_INSTALL_PREFIX="$Prefix" -DCMAKE_BUILD_TYPE="$Config" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPONYC_VERSION="$Version" $lto_flag --no-warn-unused-cli
}
$err = $LastExitCode
if ($err -ne 0) { throw "Error: exit code $err" }
break
}
"build"
{
Write-Output "cmake.exe --build `"$buildDir`" --config $Config --target ALL_BUILD"
& cmake.exe --build "$buildDir" --config $Config --target ALL_BUILD
$err = $LastExitCode
if ($err -ne 0) { throw "Error: exit code $err" }
break
}
"clean"
{
if (Test-Path $buildDir)
{
Write-Output "cmake.exe --build `"buildDir`" --config $Config --target clean"
& cmake.exe --build "$buildDir" --config $Config --target clean
}
if (Test-Path $outDir)
{
Write-Output "Remove-Item -Path $outDir -Recurse -Force"
Remove-Item -Path "$outDir" -Recurse -Force
}
break
}
"distclean"
{
if (Test-Path ($srcDir + "\build"))
{
Write-Output "Remove-Item -Path `"$srcDir\build`" -Recurse -Force"
Remove-Item -Path "$srcDir\build" -Recurse -Force
}
break
}
"test"
{
$numTestSuitesRun = 0
$failedTestSuites = @()
& $outDir\ponyc.exe --version
if ($Uselldb -eq "yes")
{
$lldbcmd = 'C:\msys64\mingw64\bin\lldb.exe'
$lldbargs = @('--batch', '--one-line', 'run', '--one-line-on-crash', '"frame variable"', '--one-line-on-crash', '"register read"', '--one-line-on-crash', '"bt all"', '--one-line-on-crash', '"quit 1"', '--')
}
# libponyrt.tests
if ($TestsToRun -match 'libponyrt.tests')
{
$numTestSuitesRun += 1;
try
{
if ($Uselldb -eq "yes")
{
Write-Output "$lldbcmd $lldbargs $outDir\libponyrt.tests.exe --gtest_shuffle"
$lldboutput = & $lldbcmd $lldbargs $outDir\libponyrt.tests.exe --gtest_shuffle
Write-Output $lldboutput
$err = ($lldboutput | Select-String -Pattern 'exited with status = (\S+)').Matches[0].Groups[1].Value
}
else
{
Write-Output "$outDir\libponyrt.tests.exe --gtest_shuffle"
& $outDir\libponyrt.tests.exe --gtest_shuffle
$err = $LastExitCode
}
}
catch
{
$err = -1
}
if ($err -ne 0) { $failedTestSuites += 'libponyrt.tests' }
}
# libponyc.tests
if ($TestsToRun -match 'libponyc.tests')
{
$numTestSuitesRun += 1;
try
{
if ($Uselldb -eq "yes")
{
Write-Output "$lldbcmd $lldbargs $outDir\libponyc.tests.exe --gtest_shuffle"
$lldboutput = & $lldbcmd $lldbargs $outDir\libponyc.tests.exe --gtest_shuffle
Write-Output $lldboutput
$err = ($lldboutput | Select-String -Pattern 'exited with status = (\S+)').Matches[0].Groups[1].Value
}
else
{
Write-Output "$outDir\libponyc.tests.exe --gtest_shuffle"
& $outDir\libponyc.tests.exe --gtest_shuffle
$err = $LastExitCode
}
}
catch
{
$err = -1
}
if ($err -ne 0) { $failedTestSuites += 'libponyc.tests' }
}
# libponyc.run.tests
if ($TestsToRun -match 'libponyc.run.tests')
{
foreach ($runConfig in ('debug', 'release'))
{
if (-not ($TestsToRun -match "libponyc.run.tests.$runConfig"))
{
continue
}
$numTestSuitesRun += 1;
$runOutDir = "$outDir\full-program-tests\$runConfig"
$debugFlag = if ($runConfig -eq 'debug') { 'true' } else { 'false' }
$debuggercmd = ''
if ($Uselldb -eq "yes")
{
$debuggercmd = "$lldbcmd $lldbargs"
$debuggercmd = $debuggercmd -replace ' ', '%20'
$debuggercmd = $debuggercmd -replace '"', '%22'
}
if (-not (Test-Path $runOutDir)) { New-Item -ItemType Directory -Force -Path $runOutDir }
Write-Output "$buildDir\test\full-program-runner\full-program-runner.exe --debug=$debugFlag --debugger=$debuggercmd --timeout_s=60 --max_parallel=1 --debug=$debugFlag --test_lib=$outDir\test_lib --ponyc=$outDir\ponyc.exe --output=$runOutDir $srcDir\test\full-program-tests"
& $buildDir\test\full-program-runner\full-program-runner.exe --debugger=$debuggercmd --timeout_s=60 --max_parallel=1 --debug=$debugFlag --test_lib=$outDir\test_lib --ponyc=$outDir\ponyc.exe --output=$runOutDir $srcDir\test\full-program-tests
$err = $LastExitCode
if ($err -ne 0) { $failedTestSuites += "libponyc.run.tests.$runConfig" }
}
}
# stdlib-debug
if ($TestsToRun -match 'stdlib-debug')
{
$numTestSuitesRun += 1;
Write-Output "$outDir\ponyc.exe -d --checktree -b stdlib-debug -o $outDir $srcDir\packages\stdlib"
& $outDir\ponyc.exe -d --checktree -b stdlib-debug -o $outDir $srcDir\packages\stdlib
if ($LastExitCode -eq 0)
{
try
{
if ($Uselldb -eq "yes")
{
Write-Output "$lldbcmd $lldbargs $outDir\stdlib-debug.exe --sequential --exclude=`"net/`""
$lldboutput = & $lldbcmd $lldbargs $outDir\stdlib-debug.exe --sequential --exclude="net/"
Write-Output $lldboutput
$err = ($lldboutput | Select-String -Pattern 'exited with status = (\S+)').Matches[0].Groups[1].Value
}
else
{
Write-Output "$outDir\stdlib-debug.exe --sequential --exclude=`"net/`""
& $outDir\stdlib-debug.exe --sequential --exclude="net/"
$err = $LastExitCode
}
}
catch
{
$err = -1
}
if ($err -ne 0) { $failedTestSuites += 'stdlib-debug' }
}
else
{
$failedTestSuites += 'compile stdlib-debug'
}
}
# stdlib-release
if ($TestsToRun -match 'stdlib-release')
{
$numTestSuitesRun += 1;
Write-Output "$outDir\ponyc.exe --checktree -b stdlib-release -o $outDir $srcDir\packages\stdlib"
& $outDir\ponyc.exe --checktree -b stdlib-release -o $outDir $srcDir\packages\stdlib
if ($LastExitCode -eq 0)
{
try
{
if ($Uselldb -eq "yes")
{
Write-Output "$lldbcmd $lldbargs $outDir\stdlib-release.exe --sequential --exclude=`"net/`""
$lldboutput = & $lldbcmd $lldbargs $outDir\stdlib-release.exe --sequential --exclude="net/"
Write-Output $lldboutput
$err = ($lldboutput | Select-String -Pattern 'exited with status = (\S+)').Matches[0].Groups[1].Value
}
else
{
Write-Output "$outDir\stdlib-release.exe --sequential --exclude=`"net/`""
& $outDir\stdlib-release.exe --sequential --exclude="net/"
$err = $LastExitCode
}
}
catch
{
$err = -1
}
if ($err -ne 0) { $failedTestSuites += 'stdlib-release' }
}
else
{
$failedTestSuites += 'compile stdlib-release'
}
}
# grammar
if ($TestsToRun -match 'grammar')
{
$numTestSuitesRun += 1
Get-Content -Path "$srcDir\pony.g" -Encoding ASCII | Out-File -Encoding UTF8 "$outDir\pony.g.orig"
& $outDir\ponyc.exe --antlr | Out-File -Encoding UTF8 "$outDir\pony.g.test"
if ($LastExitCode -eq 0)
{
$origHash = (Get-FileHash -Path "$outDir\pony.g.orig").Hash
$testHash = (Get-FileHash -Path "$outDir\pony.g.test").Hash
Write-Output "grammar original hash: $origHash"
Write-Output "grammar generated hash: $testHash"
if ($origHash -ne $testHash)
{
$failedTestSuites += 'generated grammar file differs from baseline'
}
}
else
{
$failedTestSuites += 'generate grammar'
}
}
#
$numTestSuitesFailed = $failedTestSuites.Length
Write-Output "Test suites run: $numTestSuitesRun, num failed: $numTestSuitesFailed"
if ($numTestSuitesFailed -ne 0)
{
$failedTestSuitesList = [string]::Join(', ', $failedTestSuites)
Write-Output "Test suites failed: ($failedTestSuitesList)"
exit $numTestSuitesFailed
}
break
}
"stress-test-release"
{
$lldbcmd = 'C:\msys64\mingw64\bin\lldb.exe'
$lldbargs = @('--batch', '--one-line', 'run', '--one-line-on-crash', '"frame variable"', '--one-line-on-crash', '"register read"', '--one-line-on-crash', '"bt all"', '--one-line-on-crash', '"quit 1"', '--')
& $outDir\ponyc.exe --bin-name=ubench --output=$outDir test\rt-stress\string-message-ubench
& $lldbcmd $lldbargs $outDir\ubench.exe --pingers 320 --initial-pings 5 --report-count 40 --report-interval 300 --ponynoscale --ponynoblock
$err = $LastExitCode
if ($err -ne 0) { throw "Stress test failed: exit code $err" }
break
}
"stress-test-with-cd-release"
{
$lldbcmd = 'C:\msys64\mingw64\bin\lldb.exe'
$lldbargs = @('--batch', '--one-line', 'run', '--one-line-on-crash', '"frame variable"', '--one-line-on-crash', '"register read"', '--one-line-on-crash', '"bt all"', '--one-line-on-crash', '"quit 1"', '--')
& $outDir\ponyc.exe --bin-name=ubench --output=$outDir test\rt-stress\string-message-ubench
& $lldbcmd $lldbargs $outDir\ubench.exe --pingers 320 --initial-pings 5 --report-count 40 --report-interval 300 --ponynoscale
$err = $LastExitCode
if ($err -ne 0) { throw "Stress test failed: exit code $err" }
break
}
"stress-test-debug"
{
$lldbcmd = 'C:\msys64\mingw64\bin\lldb.exe'
$lldbargs = @('--batch', '--one-line', 'run', '--one-line-on-crash', '"frame variable"', '--one-line-on-crash', '"register read"', '--one-line-on-crash', '"bt all"', '--one-line-on-crash', '"quit 1"', '--')
& $outDir\ponyc.exe --debug --bin-name=ubench --output=$outDir test\rt-stress\string-message-ubench
& $lldbcmd $lldbargs $outDir\ubench.exe --pingers 320 --initial-pings 5 --report-count 40 --report-interval 300 --ponynoscale --ponynoblock
$err = $LastExitCode
if ($err -ne 0) { throw "Stress test failed: exit code $err" }
break
}
"stress-test-with-cd-debug"
{
$lldbcmd = 'C:\msys64\mingw64\bin\lldb.exe'
$lldbargs = @('--batch', '--one-line', 'run', '--one-line-on-crash', '"frame variable"', '--one-line-on-crash', '"register read"', '--one-line-on-crash', '"bt all"', '--one-line-on-crash', '"quit 1"', '--')
& $outDir\ponyc.exe --debug --bin-name=ubench --output=$outDir test\rt-stress\string-message-ubench
& $lldbcmd $lldbargs $outDir\ubench.exe --pingers 320 --initial-pings 5 --report-count 40 --report-interval 300 --ponynoscale
$err = $LastExitCode
if ($err -ne 0) { throw "Stress test failed: exit code $err" }
break
}
"install"
{
Write-Output "cmake.exe --build `"$buildDir`" --config $Config --target install"
& cmake.exe --build "$buildDir" --config $Config --target install
$err = $LastExitCode
if ($err -ne 0) { throw "Error: exit code $err" }
break
}
"package"
{
$package = "ponyc-x86-64-pc-windows-msvc.zip"
Write-Output "Creating $buildDir\..\$package"
# Remove unneeded files; we do it this way because Compress-Archive cannot add a single file to anything other than the root directory
Get-ChildItem -File -Path "$Prefix\bin\*" -Exclude ponyc.exe | Remove-Item
Compress-Archive -Path "$Prefix\bin", "$Prefix\lib", "$Prefix\packages", "$Prefix\examples" -DestinationPath "$buildDir\..\$package" -Force
break
}
default
{
throw "Unknown command '$Command'. use: {libs, cleanlibs, configure, build, clean, test, install, package, distclean}"
}
}