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