From b6c674e71696575f30efeb4f7f9b130a029cc854 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Thu, 2 Aug 2018 14:42:14 +0200 Subject: [PATCH] Update windows build scripts --- .gitignore | 6 +--- appveyor.yml | 40 ++++++++++++++++--------- tools/win32/build.ps1 | 12 ++++---- tools/win32/configure.ps1 | 43 ++++++++++++++++++--------- tools/win32/download-openssl.ps1 | 50 ++++++++++++++++++++++++-------- tools/win32/test.ps1 | 14 +++++---- 6 files changed, 111 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index b3d357ecc..0e2ed3ffd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,11 +11,7 @@ tickets.pickle ## Build artifacts -build/ -build-debug/ -build-release/ -build32/ -build64/ +build*/ debug/ release/ cmake-build-debug diff --git a/appveyor.yml b/appveyor.yml index 05c72cd75..6e7f09b73 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,9 +2,11 @@ version: 2.9.0.dev.{build} os: Visual Studio 2017 +platform: x64 environment: CMAKE_GENERATOR: "Visual Studio 15 2017 Win64" + VSCMD_VER: 15.0 BOOST_ROOT: 'C:\Libraries\boost_1_65_1' BOOST_LIBRARYDIR: 'C:\Libraries\boost_1_65_1\lib64-msvc-14.1' BISON_BINARY: 'C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_bison.exe' @@ -16,36 +18,46 @@ branches: cache: - build -> appveyor.yml -- vendor -> tools\win32\download-openssl.ps1 - C:\ProgramData\chocolatey\lib\winflexbison3 install: -- ps: | - if (-not (Test-Path "vendor\OpenSSL")) { - .\tools\win32\download-openssl.ps1 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } - } - ps: | if (-not (Test-Path "C:\ProgramData\chocolatey\lib\winflexbison3")) { - choco install winflexbison3 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + & choco install winflexbison3 + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } } +# why that env handling, see +# https://help.appveyor.com/discussions/questions/18777-how-to-use-vcvars64bat-from-powershell#comment_44999171 before_build: - ps: | - .\tools\win32\configure.ps1 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + $bits = $env:PLATFORM -replace "^x", "" + cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars${bits}.bat`" && set > `"${env:TEMP}\vcvars.txt`"" + Get-Content "$env:TEMP\vcvars.txt" | Foreach-Object { + if ($_ -match "^(VSCMD.*?)=(.*)$") { + Set-Content ("env:" + $matches[1]) $matches[2] + } + } + + if (-not (Test-Path ".\build\vendor\OpenSSL")) { + & .\tools\win32\download-openssl.ps1 + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + } + + & .\tools\win32\configure.ps1 + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + del build\Icinga*.msi build_script: - ps: | - .\tools\win32\build.ps1 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + & .\tools\win32\build.ps1 + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } test_script: - ps: | - .\tools\win32\test.ps1 - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } + & .\tools\win32\test.ps1 + if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } # Disable until we really need them # https://github.com/Icinga/icinga2/issues/6106 diff --git a/tools/win32/build.ps1 b/tools/win32/build.ps1 index 111071518..d9dba5f94 100644 --- a/tools/win32/build.ps1 +++ b/tools/win32/build.ps1 @@ -1,7 +1,9 @@ -[string]$pwd = Get-Location +if (-not (Test-Path env:ICINGA2_BUILDPATH)) { + $env:ICINGA2_BUILDPATH = '.\build' +} -if (-not (Test-Path build)) { - Write-Host "Path '$pwd\build' does not exist!" +if (-not (Test-Path $env:ICINGA2_BUILDPATH)) { + Write-Host "Path '$env:ICINGA2_BUILDPATH' does not exist!" exit 1 } @@ -12,5 +14,5 @@ if (-not ($env:PATH -contains $env:CMAKE_PATH)) { $env:PATH = $env:CMAKE_PATH + ';' + $env:PATH } -cmake.exe --build build --target PACKAGE --config RelWithDebInfo -if ($lastexitcode -ne 0) { exit $lastexitcode } \ No newline at end of file +cmake.exe --build "$env:ICINGA2_BUILDPATH" --target PACKAGE --config RelWithDebInfo +if ($lastexitcode -ne 0) { exit $lastexitcode } diff --git a/tools/win32/configure.ps1 b/tools/win32/configure.ps1 index cdd66512f..1f40875ce 100644 --- a/tools/win32/configure.ps1 +++ b/tools/win32/configure.ps1 @@ -1,8 +1,12 @@ -if (-not (Test-Path build)) { - mkdir build +if (-not (Test-Path env:ICINGA2_BUILDPATH)) { + $env:ICINGA2_BUILDPATH = '.\build' } -if (-not (Test-Path install)) { - mkdir install + +if (-not (Test-Path "$env:ICINGA2_BUILDPATH")) { + mkdir "$env:ICINGA2_BUILDPATH" | out-null +} +if (-not (Test-Path "$env:ICINGA2_BUILDPATH\install")) { + mkdir "$env:ICINGA2_BUILDPATH\install" | out-null } if (-not (Test-Path env:CMAKE_PATH)) { $env:CMAKE_PATH = 'C:\Program Files\CMake\bin' @@ -11,13 +15,24 @@ if (-not ($env:PATH -contains $env:CMAKE_PATH)) { $env:PATH = $env:CMAKE_PATH + ';' + $env:PATH } -[string]$pwd = Get-Location - if (-not (Test-Path env:CMAKE_GENERATOR)) { $env:CMAKE_GENERATOR = 'Visual Studio 15 2017 Win64' } if (-not (Test-Path env:OPENSSL_ROOT_DIR)) { - $env:OPENSSL_ROOT_DIR = $pwd + '\vendor\OpenSSL' + if (Test-Path env:VSCMD_ARG_TGT_ARCH) { + $OpenSSL_arch = $env:VSCMD_ARG_TGT_ARCH + } else { + throw "Missing env variable VSCMD_ARG_TGT_ARCH" + } + + if (Test-Path env:VSCMD_VER) { + $VSmajor = $env:VSCMD_VER -replace "\..*$", "" + $OpenSSL_vcbuild = "vc${VSmajor}0" + } else { + throw "Missing env variable VSCMD_VER" + } + + $env:OPENSSL_ROOT_DIR = "$env:ICINGA2_BUILDPATH\vendor\OpenSSL-$OpenSSL_arch-$OpenSSL_vcbuild" } if (-not (Test-Path env:BOOST_ROOT)) { $env:BOOST_ROOT = 'c:\local\boost_1_65_1' @@ -32,12 +47,15 @@ if (-not (Test-Path env:BISON_BINARY)) { $env:BISON_BINARY = 'C:\ProgramData\chocolatey\bin\win_bison.exe' } -cd build +$sourcePath = Get-Location -& cmake.exe .. ` +cd "$env:ICINGA2_BUILDPATH" + +#-DCMAKE_INSTALL_PREFIX="C:\Program Files\Icinga2" ` + +& cmake.exe "$sourcePath" ` -DCMAKE_BUILD_TYPE=RelWithDebInfo ` -G $env:CMAKE_GENERATOR -DCPACK_GENERATOR=WIX ` - -DCMAKE_INSTALL_PREFIX="..\install" ` -DICINGA2_WITH_MYSQL=OFF -DICINGA2_WITH_PGSQL=OFF ` -DOPENSSL_ROOT_DIR="$env:OPENSSL_ROOT_DIR" ` -DBOOST_ROOT="$env:BOOST_ROOT" ` @@ -45,9 +63,8 @@ cd build -DFLEX_EXECUTABLE="$env:FLEX_BINARY" ` -DBISON_EXECUTABLE="$env:BISON_BINARY" +cd "$sourcePath" + if ($lastexitcode -ne 0) { - cd .. exit $lastexitcode } - -cd .. diff --git a/tools/win32/download-openssl.ps1 b/tools/win32/download-openssl.ps1 index 1ebe348f9..0e074e6ae 100644 --- a/tools/win32/download-openssl.ps1 +++ b/tools/win32/download-openssl.ps1 @@ -1,7 +1,19 @@ -[string]$pwd = Get-Location +$ErrorActionPreference = "Stop" + $OpenSSL_version = '1.1.0g-1' -$OpenSSL_arch = 'x64' -$OpenSSL_vcbuild = 'vc150' + +if (Test-Path env:VSCMD_ARG_TGT_ARCH) { + $OpenSSL_arch = $env:VSCMD_ARG_TGT_ARCH +} else { + throw "Missing env variable VSCMD_ARG_TGT_ARCH" +} +if (Test-Path env:VSCMD_VER) { + $VSmajor = $env:VSCMD_VER -replace "\..*$", "" + $OpenSSL_vcbuild = "vc${VSmajor}0" +} else { + throw "Missing env variable VSCMD_VER" +} + $OpenSSL_fileversion = $OpenSSL_version.Replace('.', '_').Split('-')[0] $OpenSSL_file = [string]::Format( 'openssl-{0}-binary-icinga-{1}-{2}.zip', @@ -15,12 +27,23 @@ $OpenSSL_url = [string]::Format( $OpenSSL_file ) -$OpenSSL_zip_location = $pwd + '\vendor\' + $OpenSSL_file -$vendor_path = $pwd + '\vendor' -$OpenSSL_vendor_path = $vendor_path + '\OpenSSL' +if (-not (Test-Path env:ICINGA2_BUILDPATH)) { + $env:ICINGA2_BUILDPATH = '.\build' +} + +$vendor_path = $env:ICINGA2_BUILDPATH + '\vendor' +$OpenSSL_zip_location = $env:ICINGA2_BUILDPATH + '\vendor\' + $OpenSSL_file +$OpenSSL_vendor_path = "$vendor_path\OpenSSL-$OpenSSL_arch-$OpenSSL_vcbuild" +# Tune Powershell TLS protocols +$AllProtocols = [System.Net.SecurityProtocolType]'Tls11,Tls12' +[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols + +if (-not (Test-Path $env:ICINGA2_BUILDPATH)) { + mkdir $env:ICINGA2_BUILDPATH | out-null +} if (-not (Test-Path $vendor_path)) { - mkdir $vendor_path + mkdir $vendor_path | out-null } if (Test-Path $OpenSSL_zip_location) { @@ -30,21 +53,24 @@ if (Test-Path $OpenSSL_zip_location) { $progressPreference = 'silentlyContinue' Invoke-WebRequest -Uri $OpenSSL_url -OutFile $OpenSSL_zip_location - if ($lastexitcode -ne 0){ exit $lastexitcode } $progressPreference = 'Continue' - + if (Test-Path $OpenSSL_vendor_path) { Remove-Item -Recurse $OpenSSL_vendor_path } } if (-not (Test-Path $OpenSSL_vendor_path)) { - mkdir $OpenSSL_vendor_path + mkdir $OpenSSL_vendor_path | out-null Write-Output "Extracting ZIP to $OpenSSL_vendor_path" Add-Type -AssemblyName System.IO.Compression.FileSystem - [System.IO.Compression.ZipFile]::ExtractToDirectory($OpenSSL_zip_location, $OpenSSL_vendor_path) - if ($lastexitcode -ne 0){ exit $lastexitcode } + $pwd = Get-Location + [System.IO.Compression.ZipFile]::ExtractToDirectory( + (Join-Path -path $pwd -childpath $OpenSSL_zip_location), + (Join-Path -path $pwd -childpath $OpenSSL_vendor_path) + ) + if ($lastexitcode -ne 0){ exit $lastexitcode } } else { Write-Output "OpenSSL is already available at $OpenSSL_vendor_path" } diff --git a/tools/win32/test.ps1 b/tools/win32/test.ps1 index 913c82c58..81fe8e6fa 100644 --- a/tools/win32/test.ps1 +++ b/tools/win32/test.ps1 @@ -1,7 +1,11 @@ +if (-not (Test-Path env:ICINGA2_BUILDPATH)) { + $env:ICINGA2_BUILDPATH = 'build' +} + [string]$pwd = Get-Location -if (-not (Test-Path build)) { - Write-Host "Path '$pwd\build' does not exist!" +if (-not (Test-Path $env:ICINGA2_BUILDPATH)) { + Write-Host "Path '$pwd\$env:ICINGA2_BUILDPATH' does not exist!" exit 1 } @@ -12,12 +16,12 @@ if (-not ($env:PATH -contains $env:CMAKE_PATH)) { $env:PATH = $env:CMAKE_PATH + ';' + $env:PATH } -cd build +cd "$env:ICINGA2_BUILDPATH" -ctest.exe -C RelWithDebInfo -T test -O build/Test.xml --output-on-failure +ctest.exe -C RelWithDebInfo -T test -O $env:ICINGA2_BUILDPATH/Test.xml --output-on-failure if ($lastexitcode -ne 0) { cd .. exit $lastexitcode } -cd .. \ No newline at end of file +cd .. -- 2.40.0