Build and run C++ tests on MSVC
This commit is contained in:
44
build.ps1
44
build.ps1
@@ -3,9 +3,12 @@ Param(
|
||||
)
|
||||
|
||||
$Compiler = "cl.exe"
|
||||
$Linker = "lib.exe"
|
||||
|
||||
$GeneralFlags = "/Wall /WX /wd4996 /wd4464 /wd5105 /std:c11"
|
||||
$LibraryFlags = "/LD"
|
||||
$GeneralFlags = "/Wall /WX /wd4996 /wd4464 /wd5105 /EHs"
|
||||
$CStd = "/std:c11"
|
||||
$CppStd = "/std:c++14"
|
||||
$LibraryFlags = "/c"
|
||||
|
||||
$Kernel = (Get-ChildItem Env:OS).Value
|
||||
$Machine = (Get-ChildItem Env:PROCESSOR_ARCHITECTURE).Value
|
||||
@@ -15,14 +18,15 @@ $IncludeDirs = "/I src"
|
||||
$SrcFiles = "src/wapp.c"
|
||||
|
||||
$TestIncludeDirs = Get-ChildItem -Path tests -Recurse -Directory -ErrorAction SilentlyContinue -Force | %{$("/I " + '"' + $_.FullName + '"')}
|
||||
$TestSrcFiles = Get-ChildItem -Path tests -Recurse -Filter *.c -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
|
||||
$TestCSrcFiles = Get-ChildItem -Path tests -Recurse -Filter *.c -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
|
||||
$TestCppSrcFiles = Get-ChildItem -Path tests -Recurse -Filter *.cc -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
|
||||
|
||||
If ($Release -eq $True) {
|
||||
$GeneralFlags += " /O2 /Og"
|
||||
$BuildType = "release"
|
||||
$BuildType = "Release"
|
||||
} Else {
|
||||
$GeneralFlags += " /Zi /Od /fsanitize=address"
|
||||
$BuildType = "debug"
|
||||
$BuildType = "Debug"
|
||||
}
|
||||
|
||||
$BuildDir = "./libwapp-build/${Platform}-${BuildType}"
|
||||
@@ -30,12 +34,15 @@ $ObjDir = "$BuildDir/objects"
|
||||
$OutDir = "$BuildDir/output"
|
||||
$TestsDir = "$BuildDir/tests"
|
||||
|
||||
$OutBasename = "libwapp"
|
||||
$LibOutput = "$OutDir/libwapp.lib"
|
||||
$Objects = "/Fo:$ObjDir/"
|
||||
$Outputs = "/Fd:$OutDir/$OutBasename /Fe:$OutDir/$OutBasename"
|
||||
$LibOutputFlags = "/OUT:$LibOutput"
|
||||
|
||||
$TestOutBasename = "wapptest"
|
||||
$TestOutputs = "/Fo:$TestsDir/ /Fe:$TestsDir/$TestOutBasename"
|
||||
$TestCOutputBasename = "wapptest"
|
||||
$TestCOutputFlags = "/Fo:$TestsDir/ /Fe:$TestsDir/$TestCOutputBasename"
|
||||
|
||||
$TestCppOutputBasename = "wapptestcc"
|
||||
$TestCppOutputFlags = "/Fo:$TestsDir/ /Fe:$TestsDir/$TestCppOutputBasename"
|
||||
|
||||
If (Test-Path $BuildDir) {
|
||||
Remove-Item $BuildDir -Recurse -Force
|
||||
@@ -48,18 +55,23 @@ mkdir -p $TestsDir > $null
|
||||
# Run code generation
|
||||
Invoke-Expression "python -m codegen"
|
||||
|
||||
# Build and run tests
|
||||
Invoke-Expression "$Compiler $GeneralFlags $IncludeDirs $TestIncludeDirs $SrcFiles $TestSrcFiles $TestOutputs" -ErrorAction Stop
|
||||
# Build and run C tests
|
||||
Invoke-Expression "$Compiler $GeneralFlags $CStd $IncludeDirs $TestIncludeDirs $SrcFiles $TestCSrcFiles $TestCOutputFlags" -ErrorAction Stop
|
||||
Invoke-Expression "$TestsDir/$TestCOutputBasename.exe"
|
||||
|
||||
Invoke-Expression "$TestsDir/$TestOutBasename.exe"
|
||||
$Status = $LASTEXITCODE
|
||||
|
||||
Remove-Item $TestsDir -Recurse -Force
|
||||
|
||||
If ($Status -ne 0) {
|
||||
Remove-Item $TestsDir -Recurse -Force
|
||||
Write-Error "Tests failed"
|
||||
Exit 1
|
||||
}
|
||||
|
||||
# Build library
|
||||
Invoke-Expression "$Compiler $GeneralFlags $LibraryFlags $SrcFiles $Objects $Outputs"
|
||||
Invoke-Expression "$Compiler $GeneralFlags $CStd $LibraryFlags $SrcFiles $Objects"
|
||||
Invoke-Expression "$Linker $ObjDir/*.obj $LibOutputFlags"
|
||||
|
||||
# Build and run C++ tests
|
||||
Invoke-Expression "$Compiler $GeneralFlags $CppStd $IncludeDirs $TestIncludeDirs $LibOutput $TestCppSrcFiles $TestCppOutputFlags" -ErrorAction Stop
|
||||
Invoke-Expression "$TestsDir/$TestCppOutputBasename.exe"
|
||||
|
||||
Remove-Item $TestsDir -Recurse -Force
|
||||
|
||||
Reference in New Issue
Block a user