diff options
Diffstat (limited to '')
-rw-r--r-- | .ci/verify_arch.ps1 | 82 | ||||
-rw-r--r-- | appveyor.yml | 7 |
2 files changed, 87 insertions, 2 deletions
diff --git a/.ci/verify_arch.ps1 b/.ci/verify_arch.ps1 new file mode 100644 index 0000000..183a8c5 --- /dev/null +++ b/.ci/verify_arch.ps1 @@ -0,0 +1,82 @@ +param( + [Parameter(Mandatory=$true)] + [string] $Path, + [Parameter(Mandatory=$true)] + [ValidateSet('x64', 'x86')] + [string] $Arch +) + +$ErrorActionPreference = "Stop"; +Set-PSDebug -Strict + +function Get-MachineType { + param( + [Parameter(Mandatory=$true)] + [string] $Arch + ) + + $machine_type = switch ($Arch) { + 'x64' { 0x8664 } + 'x86' { 0x14c } + default { throw "Unsupported architecture: $Arch" } + } + return $machine_type +} + +function Parse-MachineType { + param( + [Parameter(Mandatory=$true)] + [string] $Path + ) + + $header_offset_offset = 0x3c + $machine_type_offset = 4 # Two words + + $bytes = [System.IO.File]::ReadAllBytes($Path) + $header_offset = [System.BitConverter]::ToUInt32($bytes, $header_offset_offset) + $machine_type = [System.BitConverter]::ToUInt16($bytes, $header_offset + $machine_type_offset) + + return $machine_type +} + +function Verify-Architecture { + param( + [Parameter(Mandatory=$true)] + [string] $Path, + [Parameter(Mandatory=$true)] + [string] $Arch + ) + + $actual = Parse-MachineType -Path $Path + $actual_hex = "0x{0:x}" -f $actual + $expected = Get-MachineType -Arch $Arch + $expected_hex = "0x{0:x}" -f $expected + + if ($actual -eq $expected) { + Write-Host "File '$Path' matches architecture '$Arch'." + } else { + Write-Host "File '$Path' DOES NOT match architecture '$Arch'." + Write-Error "Expected machine type '$expected_hex', actual machine type is '$actual_hex'." + } +} + +function Test-AppVeyor { + return Test-Path env:APPVEYOR +} + +function Verify-ArchitectureAppVeyor { + if (Test-AppVeyor) { + $appveyor_cwd = pwd + } + + try { + Verify-Architecture -Path $script:Path -Arch $script:Arch + } finally { + if (Test-AppVeyor) { + cd $appveyor_cwd + Set-PSDebug -Off + } + } +} + +Verify-ArchitectureAppVeyor diff --git a/appveyor.yml b/appveyor.yml index 8b70c13..1a8b1e3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,14 +18,17 @@ environment: build_script: - echo Simple CMake projects - - '"%python_exe%" ./cmake/build/build.py --install C:\install\simple --configuration Release -- cmake/examples/simple' + - '"%python_exe%" ./cmake/build/build.py --install C:\install\simple --configuration Release -- cmake/examples/simple -A x64' - C:\install\simple\bin\foo.exe + - ps: .\.ci\verify_arch.ps1 -Path C:\install\simple\bin\foo.exe -Arch x64 - '"%python_exe%" ./cmake/build/build.py --install C:\install\static --configuration Debug -- cmake/examples/static -A Win32' - C:\install\static\bin\foo.exe + - ps: .\.ci\verify_arch.ps1 -Path C:\install\static\bin\foo.exe -Arch x86 - - '"%python_exe%" ./cmake/build/build.py --install C:\install\dynamic --configuration Release -- cmake/examples/dynamic' + - '"%python_exe%" ./cmake/build/build.py --install C:\install\dynamic --configuration Release -- cmake/examples/dynamic -A x64' - C:\install\dynamic\bin\foo.exe + - ps: .\.ci\verify_arch.ps1 -Path C:\install\dynamic\bin\foo.exe -Arch x64 - '"%python_exe%" ./boost/build/build.py download 1.58.0' - '"%python_exe%" ./boost/build/build.py download --cache . 1.72.0' |