From ed9fba0de4eda71c52e0fccb9610860befc36c4c Mon Sep 17 00:00:00 2001 From: amaitland Date: Sat, 15 Dec 2018 20:59:21 +1000 Subject: [PATCH] Revert "build.ps1 - Remove WriteException and try/catch" This reverts commit 82e200b919d845f7071c4a84309f58bea9a51261. --- build.ps1 | 1162 +++++++++++++++++++++++++++-------------------------- 1 file changed, 591 insertions(+), 571 deletions(-) diff --git a/build.ps1 b/build.ps1 index dcadbda..e54b55a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -26,713 +26,733 @@ Set-StrictMode -version latest $ErrorActionPreference = "Stop"; $Extension = $Extension.ToLower(); -$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition; -if ($CefVersion -eq "auto" -and $DownloadBinary -eq "local") +Function WriteException($exp) { - #Take the version from the local binary only, requires only one version in that folder to work - $name = (dir -Filter cef_binary_*_windows64.$Extension $CefBinaryDir)[0].Name; - $CefVersion = ($name -replace "cef_binary_", "") -replace "_windows64.$Extension"; + write-host "Caught an exception:" -ForegroundColor Yellow -NoNewline; + write-host " $($exp.Exception.Message)" -ForegroundColor Red; + write-host "`tException Type: $($exp.Exception.GetType().FullName)"; + $stack = $exp.ScriptStackTrace; + $stack = $stack.replace("`n","`n`t"); + write-host "`tStack Trace: $stack"; + throw $exp; } - -$Cef = Join-Path $WorkingDir 'cef' -$CefInclude = Join-Path $Cef 'include' -$Cef32 = Join-Path $WorkingDir 'cef_binary_3.y.z_windows32' -$Cef32vcx = Join-Path (Join-Path $Cef32 'libcef_dll_wrapper') 'libcef_dll_wrapper.vcxproj' -$Cef64 = Join-Path $WorkingDir 'cef_binary_3.y.z_windows64' -$Cef64vcx = Join-Path (Join-Path $Cef64 'libcef_dll_wrapper') 'libcef_dll_wrapper.vcxproj' - -function Write-Diagnostic +try { - param( - [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] - [string] $Message - ) - - Write-Host - Write-Host $Message -ForegroundColor Green - Write-Host -} + $WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition; + if ($CefVersion -eq "auto" -and $DownloadBinary -eq "local") + { + #Take the version from the local binary only, requires only one version in that folder to work + $name = (dir -Filter cef_binary_*_windows64.$Extension $CefBinaryDir)[0].Name; + $CefVersion = ($name -replace "cef_binary_", "") -replace "_windows64.$Extension"; + } -# Set CefVersion based on tag name - must start with leading "v" e.g. v3.3163.1663.g416ffeb -if ($env:APPVEYOR_REPO_TAG -eq "True") -{ - $CefVersion = "$env:APPVEYOR_REPO_TAG_NAME".Substring(1) # trim leading "v" - Write-Diagnostic "Setting version based on tag to $CefVersion" -} -# Take the cef version and strip the commit hash -$CefPackageVersion = $CefVersion.SubString(0, $CefVersion.LastIndexOf('.')) + $Cef = Join-Path $WorkingDir 'cef' + $CefInclude = Join-Path $Cef 'include' + $Cef32 = Join-Path $WorkingDir 'cef_binary_3.y.z_windows32' + $Cef32vcx = Join-Path (Join-Path $Cef32 'libcef_dll_wrapper') 'libcef_dll_wrapper.vcxproj' + $Cef64 = Join-Path $WorkingDir 'cef_binary_3.y.z_windows64' + $Cef64vcx = Join-Path (Join-Path $Cef64 'libcef_dll_wrapper') 'libcef_dll_wrapper.vcxproj' -# https://github.com/jbake/Powershell_scripts/blob/master/Invoke-BatchFile.ps1 -function Invoke-BatchFile -{ - param( - [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] - [string]$Path, - [Parameter(Position = 1, Mandatory = $true, ValueFromPipeline = $true)] - [string]$Parameters - ) - - $tempFile = [IO.Path]::GetTempFileName() - - # NOTE: A better solution would be to use PSCX's Push-EnvironmentBlock before calling - # this and popping it before calling this function again as repeated use of this function - # can (unsurprisingly) cause the PATH variable to max out at Windows upper limit. - $batFile = [IO.Path]::GetTempFileName() + '.cmd' - Set-Content -Path $batFile -Value "`"$Path`" $Parameters && set > `"$tempFile`"`r`n" - - & $batFile - - #Brace must be on same line for foreach-object to work - Get-Content $tempFile | Foreach-Object { - if ($_ -match "^(.*?)=(.*)$") - { - Set-Content "env:\$($matches[1])" $matches[2] - } - } - Remove-Item $tempFile - Remove-Item $batFile -} + function Write-Diagnostic + { + param( + [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] + [string] $Message + ) -function Die -{ - param( - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Message - ) + Write-Host + Write-Host $Message -ForegroundColor Green + Write-Host + } - Write-Host - Write-Error $Message - exit 1 + # Set CefVersion based on tag name - must start with leading "v" e.g. v3.3163.1663.g416ffeb + if ($env:APPVEYOR_REPO_TAG -eq "True") + { + $CefVersion = "$env:APPVEYOR_REPO_TAG_NAME".Substring(1) # trim leading "v" + Write-Diagnostic "Setting version based on tag to $CefVersion" + } -} + # Take the cef version and strip the commit hash + $CefPackageVersion = $CefVersion.SubString(0, $CefVersion.LastIndexOf('.')) -function Warn -{ - param( - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Message - ) + # https://github.com/jbake/Powershell_scripts/blob/master/Invoke-BatchFile.ps1 + function Invoke-BatchFile + { + param( + [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] + [string]$Path, + [Parameter(Position = 1, Mandatory = $true, ValueFromPipeline = $true)] + [string]$Parameters + ) - Write-Host - Write-Host $Message -ForegroundColor Yellow - Write-Host + $tempFile = [IO.Path]::GetTempFileName() -} + # NOTE: A better solution would be to use PSCX's Push-EnvironmentBlock before calling + # this and popping it before calling this function again as repeated use of this function + # can (unsurprisingly) cause the PATH variable to max out at Windows upper limit. + $batFile = [IO.Path]::GetTempFileName() + '.cmd' + Set-Content -Path $batFile -Value "`"$Path`" $Parameters && set > `"$tempFile`"`r`n" -function TernaryReturn -{ - param( - [Parameter(Position = 0, ValueFromPipeline = $true)] - [bool] $Yes, - [Parameter(Position = 1, ValueFromPipeline = $true)] - $Value, - [Parameter(Position = 2, ValueFromPipeline = $true)] - $Value2 - ) + & $batFile - if ($Yes) - { - return $Value + #Brace must be on same line for foreach-object to work + Get-Content $tempFile | Foreach-Object { + if ($_ -match "^(.*?)=(.*)$") + { + Set-Content "env:\$($matches[1])" $matches[2] + } + } + Remove-Item $tempFile + Remove-Item $batFile } - $Value2 + function Die + { + param( + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Message + ) -} + Write-Host + Write-Error $Message + exit 1 -function Bootstrap -{ - param() - - if ($Target -eq "nupkg-only") - { - return } - Write-Diagnostic "Bootstrapping" - - if (Test-Path($Cef)) + function Warn { - Remove-Item $Cef -Recurse | Out-Null - } + param( + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Message + ) - # Copy include files - Copy-Item $Cef64\include $CefInclude -Recurse | Out-Null - - # Create default directory structure - md 'cef\win32' | Out-Null - md 'cef\win32\debug' | Out-Null - md 'cef\win32\debug\VS2012' | Out-Null - md 'cef\win32\debug\VS2013' | Out-Null - md 'cef\win32\debug\VS2015' | Out-Null - md 'cef\win32\debug\VS2017' | Out-Null - md 'cef\win32\release' | Out-Null - md 'cef\win32\release\VS2012' | Out-Null - md 'cef\win32\release\VS2013' | Out-Null - md 'cef\win32\release\VS2015' | Out-Null - md 'cef\win32\release\VS2017' | Out-Null - md 'cef\x64' | Out-Null - md 'cef\x64\debug' | Out-Null - md 'cef\x64\debug\VS2012' | Out-Null - md 'cef\x64\debug\VS2013' | Out-Null - md 'cef\x64\debug\VS2015' | Out-Null - md 'cef\x64\debug\VS2017' | Out-Null - md 'cef\x64\release' | Out-Null - md 'cef\x64\release\VS2012' | Out-Null - md 'cef\x64\release\VS2013' | Out-Null - md 'cef\x64\release\VS2015' | Out-Null - md 'cef\x64\release\VS2017' | Out-Null -} + Write-Host + Write-Host $Message -ForegroundColor Yellow + Write-Host -function Msvs -{ - param( - [ValidateSet('v110', 'v120', 'v140', 'v141')] - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Toolchain, + } - [Parameter(Position = 1, ValueFromPipeline = $true)] - [ValidateSet('Debug', 'Release')] - [string] $Configuration, + function TernaryReturn + { + param( + [Parameter(Position = 0, ValueFromPipeline = $true)] + [bool] $Yes, + [Parameter(Position = 1, ValueFromPipeline = $true)] + $Value, + [Parameter(Position = 2, ValueFromPipeline = $true)] + $Value2 + ) - [Parameter(Position = 2, ValueFromPipeline = $true)] - [ValidateSet('x86', 'x64')] - [string] $Platform - ) + if ($Yes) + { + return $Value + } - Write-Diagnostic "Targeting $Toolchain using configuration $Configuration on platform $Platform" + $Value2 - $VisualStudioVersion = $null - $VXXCommonTools = $null - $CmakeGenerator = $null + } - switch -Exact ($Toolchain) + function Bootstrap { - 'v110' + param() + + if ($Target -eq "nupkg-only") { - if($env:VS110COMNTOOLS -eq $null) - { - Die "Visual Studio 2012 was not found" - } - $VisualStudioVersion = '11.0' - $VXXCommonTools = Join-Path $env:VS110COMNTOOLS '..\..\vc' - $CmakeGenerator = 'Visual Studio 11' + return } - 'v120' + + Write-Diagnostic "Bootstrapping" + + if (Test-Path($Cef)) { - if($env:VS120COMNTOOLS -eq $null) - { - Die "Visual Studio 2013 was not found" - } - $VisualStudioVersion = '12.0' - $VXXCommonTools = Join-Path $env:VS120COMNTOOLS '..\..\vc' - $CmakeGenerator = 'Visual Studio 12' + Remove-Item $Cef -Recurse | Out-Null } - 'v140' + + # Copy include files + Copy-Item $Cef64\include $CefInclude -Recurse | Out-Null + + # Create default directory structure + md 'cef\win32' | Out-Null + md 'cef\win32\debug' | Out-Null + md 'cef\win32\debug\VS2012' | Out-Null + md 'cef\win32\debug\VS2013' | Out-Null + md 'cef\win32\debug\VS2015' | Out-Null + md 'cef\win32\debug\VS2017' | Out-Null + md 'cef\win32\release' | Out-Null + md 'cef\win32\release\VS2012' | Out-Null + md 'cef\win32\release\VS2013' | Out-Null + md 'cef\win32\release\VS2015' | Out-Null + md 'cef\win32\release\VS2017' | Out-Null + md 'cef\x64' | Out-Null + md 'cef\x64\debug' | Out-Null + md 'cef\x64\debug\VS2012' | Out-Null + md 'cef\x64\debug\VS2013' | Out-Null + md 'cef\x64\debug\VS2015' | Out-Null + md 'cef\x64\debug\VS2017' | Out-Null + md 'cef\x64\release' | Out-Null + md 'cef\x64\release\VS2012' | Out-Null + md 'cef\x64\release\VS2013' | Out-Null + md 'cef\x64\release\VS2015' | Out-Null + md 'cef\x64\release\VS2017' | Out-Null + } + + function Msvs + { + param( + [ValidateSet('v110', 'v120', 'v140', 'v141')] + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Toolchain, + + [Parameter(Position = 1, ValueFromPipeline = $true)] + [ValidateSet('Debug', 'Release')] + [string] $Configuration, + + [Parameter(Position = 2, ValueFromPipeline = $true)] + [ValidateSet('x86', 'x64')] + [string] $Platform + ) + + Write-Diagnostic "Targeting $Toolchain using configuration $Configuration on platform $Platform" + + $VisualStudioVersion = $null + $VXXCommonTools = $null + $CmakeGenerator = $null + + switch -Exact ($Toolchain) { - if($env:VS140COMNTOOLS -eq $null) + 'v110' { - Die "Visual Studio 2015 was not found" + if($env:VS110COMNTOOLS -eq $null) + { + Die "Visual Studio 2012 was not found" + } + $VisualStudioVersion = '11.0' + $VXXCommonTools = Join-Path $env:VS110COMNTOOLS '..\..\vc' + $CmakeGenerator = 'Visual Studio 11' } - $VisualStudioVersion = '14.0' - $VXXCommonTools = Join-Path $env:VS140COMNTOOLS '..\..\vc' - $CmakeGenerator = 'Visual Studio 14' - } - 'v141' - { - $programFilesDir = (${env:ProgramFiles(x86)}, ${env:ProgramFiles} -ne $null)[0] - - $vswherePath = Join-Path $programFilesDir 'Microsoft Visual Studio\Installer\vswhere.exe' - #Check if we already have vswhere which is included in newer versions of VS2017 - if(-not (Test-Path $vswherePath)) + 'v120' { - Write-Diagnostic "Downloading VSWhere as no install found at $vswherePath" - - # Check if we already have a local copy and download if required - $vswherePath = Join-Path $WorkingDir \vswhere.exe - - # TODO: Check hash and download if hash differs - if(-not (Test-Path $vswherePath)) + if($env:VS120COMNTOOLS -eq $null) { - $client = New-Object System.Net.WebClient; - $client.DownloadFile('https://github.com/Microsoft/vswhere/releases/download/2.5.2/vswhere.exe', $vswherePath); + Die "Visual Studio 2013 was not found" } + $VisualStudioVersion = '12.0' + $VXXCommonTools = Join-Path $env:VS120COMNTOOLS '..\..\vc' + $CmakeGenerator = 'Visual Studio 12' } - - Write-Diagnostic "VSWhere path $vswherePath" - - $VS2017InstallPath = & $vswherePath -version 15 -property installationPath - - Write-Diagnostic "VS2017InstallPath: $VS2017InstallPath" - - if($VS2017InstallPath -eq $null -or !(Test-Path $VS2017InstallPath)) + 'v140' { - Die "Visual Studio 2017 was not found" + if($env:VS140COMNTOOLS -eq $null) + { + Die "Visual Studio 2015 was not found" + } + $VisualStudioVersion = '14.0' + $VXXCommonTools = Join-Path $env:VS140COMNTOOLS '..\..\vc' + $CmakeGenerator = 'Visual Studio 14' } + 'v141' + { + $programFilesDir = (${env:ProgramFiles(x86)}, ${env:ProgramFiles} -ne $null)[0] + + $vswherePath = Join-Path $programFilesDir 'Microsoft Visual Studio\Installer\vswhere.exe' + #Check if we already have vswhere which is included in newer versions of VS2017 + if(-not (Test-Path $vswherePath)) + { + Write-Diagnostic "Downloading VSWhere as no install found at $vswherePath" + + # Check if we already have a local copy and download if required + $vswherePath = Join-Path $WorkingDir \vswhere.exe + + # TODO: Check hash and download if hash differs + if(-not (Test-Path $vswherePath)) + { + $client = New-Object System.Net.WebClient; + $client.DownloadFile('https://github.com/Microsoft/vswhere/releases/download/2.5.2/vswhere.exe', $vswherePath); + } + } + + Write-Diagnostic "VSWhere path $vswherePath" + + $VS2017InstallPath = & $vswherePath -version 15 -property installationPath - $VisualStudioVersion = '15.0' - $VXXCommonTools = Join-Path $VS2017InstallPath VC\Auxiliary\Build - $CmakeGenerator = 'Visual Studio 15' + Write-Diagnostic "VS2017InstallPath: $VS2017InstallPath" + + if($VS2017InstallPath -eq $null -or !(Test-Path $VS2017InstallPath)) + { + Die "Visual Studio 2017 was not found" + } + + $VisualStudioVersion = '15.0' + $VXXCommonTools = Join-Path $VS2017InstallPath VC\Auxiliary\Build + $CmakeGenerator = 'Visual Studio 15' + } } - } - if ($VXXCommonTools -eq $null -or (-not (Test-Path($VXXCommonTools)))) - { - Die 'Error unable to find any visual studio environment' - } + if ($VXXCommonTools -eq $null -or (-not (Test-Path($VXXCommonTools)))) + { + Die 'Error unable to find any visual studio environment' + } - $CefProject = TernaryReturn ($Platform -eq 'x86') $Cef32vcx $Cef64vcx - $CefDir = TernaryReturn ($Platform -eq 'x86') $Cef32 $Cef64 + $CefProject = TernaryReturn ($Platform -eq 'x86') $Cef32vcx $Cef64vcx + $CefDir = TernaryReturn ($Platform -eq 'x86') $Cef32 $Cef64 - $Arch = TernaryReturn ($Platform -eq 'x64') 'x64' 'win32' - $CmakeArch = TernaryReturn ($Platform -eq 'x64') ' Win64' '' + $Arch = TernaryReturn ($Platform -eq 'x64') 'x64' 'win32' + $CmakeArch = TernaryReturn ($Platform -eq 'x64') ' Win64' '' - $VCVarsAll = Join-Path $VXXCommonTools vcvarsall.bat - if (-not (Test-Path $VCVarsAll)) - { - Warn "Toolchain $Toolchain is not installed on your development machine, skipping $Configuration $Platform build." - Return - } - - $VCXProj = $Cef32vcx - if ($Platform -eq 'x64') - { - $VCXProj = $Cef64vcx - } - - # Only configure build environment once - if ($env:CEFSHARP_BUILD_IS_BOOTSTRAPPED -ne "$Toolchain$Platform") - { - Invoke-BatchFile $VCVarsAll $Platform - Write-Diagnostic "pushd $CefDir" - pushd $CefDir - # Remove previously generated CMake data for the different platform/toolchain - rm CMakeCache.txt -ErrorAction:SilentlyContinue - rm -r CMakeFiles -ErrorAction:SilentlyContinue - Write-Diagnostic "Running cmake" - &"$($env:ChocolateyInstall)\bin\cmake.exe" --version - &"$($env:ChocolateyInstall)\bin\cmake.exe" -LAH -G "$CmakeGenerator$CmakeArch" -DUSE_SANDBOX=Off -DCEF_RUNTIME_LIBRARY_FLAG=/MD . - popd - $env:CEFSHARP_BUILD_IS_BOOTSTRAPPED = "$Toolchain$Platform" - } - - $Arguments = @( - "$CefProject", - "/t:rebuild", - "/p:VisualStudioVersion=$VisualStudioVersion", - "/p:Configuration=$Configuration", - "/p:PlatformToolset=$Toolchain", - "/p:Platform=$Arch", - "/p:PreferredToolArchitecture=$Arch", - "/p:ConfigurationType=StaticLibrary" - ) - - $StartInfo = New-Object System.Diagnostics.ProcessStartInfo - $StartInfo.FileName = "msbuild.exe" - $StartInfo.Arguments = $Arguments - - $StartInfo.EnvironmentVariables.Clear() - - #Brace must be on same line for foreach-object to work - Get-ChildItem -Path env:* | ForEach-Object { - $StartInfo.EnvironmentVariables.Add($_.Name, $_.Value) - } + $VCVarsAll = Join-Path $VXXCommonTools vcvarsall.bat + if (-not (Test-Path $VCVarsAll)) + { + Warn "Toolchain $Toolchain is not installed on your development machine, skipping $Configuration $Platform build." + Return + } - $StartInfo.UseShellExecute = $false - $StartInfo.CreateNoWindow = $false - $StartInfo.RedirectStandardError = $true - $StartInfo.RedirectStandardOutput = $true + $VCXProj = $Cef32vcx + if ($Platform -eq 'x64') + { + $VCXProj = $Cef64vcx + } - $Process = New-Object System.Diagnostics.Process - $Process.StartInfo = $startInfo - $Process.Start() + # Only configure build environment once + if ($env:CEFSHARP_BUILD_IS_BOOTSTRAPPED -ne "$Toolchain$Platform") + { + Invoke-BatchFile $VCVarsAll $Platform + Write-Diagnostic "pushd $CefDir" + pushd $CefDir + # Remove previously generated CMake data for the different platform/toolchain + rm CMakeCache.txt -ErrorAction:SilentlyContinue + rm -r CMakeFiles -ErrorAction:SilentlyContinue + Write-Diagnostic "Running cmake" + &"$($env:ChocolateyInstall)\bin\cmake.exe" --version + &"$($env:ChocolateyInstall)\bin\cmake.exe" -LAH -G "$CmakeGenerator$CmakeArch" -DUSE_SANDBOX=Off -DCEF_RUNTIME_LIBRARY_FLAG=/MD . + popd + $env:CEFSHARP_BUILD_IS_BOOTSTRAPPED = "$Toolchain$Platform" + } - $stdout = $Process.StandardOutput.ReadToEnd() - $stderr = $Process.StandardError.ReadToEnd() + $Arguments = @( + "$CefProject", + "/t:rebuild", + "/p:VisualStudioVersion=$VisualStudioVersion", + "/p:Configuration=$Configuration", + "/p:PlatformToolset=$Toolchain", + "/p:Platform=$Arch", + "/p:PreferredToolArchitecture=$Arch", + "/p:ConfigurationType=StaticLibrary" + ) + + $StartInfo = New-Object System.Diagnostics.ProcessStartInfo + $StartInfo.FileName = "msbuild.exe" + $StartInfo.Arguments = $Arguments + + $StartInfo.EnvironmentVariables.Clear() + + #Brace must be on same line for foreach-object to work + Get-ChildItem -Path env:* | ForEach-Object { + $StartInfo.EnvironmentVariables.Add($_.Name, $_.Value) + } - $Process.WaitForExit() + $StartInfo.UseShellExecute = $false + $StartInfo.CreateNoWindow = $false + $StartInfo.RedirectStandardError = $true + $StartInfo.RedirectStandardOutput = $true + + $Process = New-Object System.Diagnostics.Process + $Process.StartInfo = $startInfo + $Process.Start() + + $stdout = $Process.StandardOutput.ReadToEnd() + $stderr = $Process.StandardError.ReadToEnd() + + $Process.WaitForExit() + + if ($Process.ExitCode -ne 0) + { + Write-Host "stdout: $stdout" + Write-Host "stderr: $stderr" + Die "Build failed" + } - if ($Process.ExitCode -ne 0) - { - Write-Host "stdout: $stdout" - Write-Host "stderr: $stderr" - Die "Build failed" + CreateCefSdk $Toolchain $Configuration $Platform } - CreateCefSdk $Toolchain $Configuration $Platform -} + function VSX + { + param( + [ValidateSet('v110', 'v120', 'v140', 'v141')] + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Toolchain + ) -function VSX -{ - param( - [ValidateSet('v110', 'v120', 'v140', 'v141')] - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Toolchain - ) + Write-Diagnostic "Starting to build targeting toolchain $Toolchain" - Write-Diagnostic "Starting to build targeting toolchain $Toolchain" + if (! $NoDebugBuild) + { + Msvs "$Toolchain" 'Debug' 'x86' + } + Msvs "$Toolchain" 'Release' 'x86' + if (! $NoDebugBuild) + { + Msvs "$Toolchain" 'Debug' 'x64' + } + Msvs "$Toolchain" 'Release' 'x64' - if (! $NoDebugBuild) - { - Msvs "$Toolchain" 'Debug' 'x86' - } - Msvs "$Toolchain" 'Release' 'x86' - if (! $NoDebugBuild) - { - Msvs "$Toolchain" 'Debug' 'x64' + Write-Diagnostic "Finished build targeting toolchain $Toolchain" } - Msvs "$Toolchain" 'Release' 'x64' - Write-Diagnostic "Finished build targeting toolchain $Toolchain" -} - -function CreateCefSdk -{ - param( - [ValidateSet('v110', 'v120', 'v140', 'v141')] - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Toolchain, + function CreateCefSdk + { + param( + [ValidateSet('v110', 'v120', 'v140', 'v141')] + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Toolchain, - [Parameter(Position = 1, ValueFromPipeline = $true)] - [ValidateSet('Debug', 'Release')] - [string] $Configuration, + [Parameter(Position = 1, ValueFromPipeline = $true)] + [ValidateSet('Debug', 'Release')] + [string] $Configuration, - [Parameter(Position = 2, ValueFromPipeline = $true)] - [ValidateSet('x86', 'x64')] - [string] $Platform - ) + [Parameter(Position = 2, ValueFromPipeline = $true)] + [ValidateSet('x86', 'x64')] + [string] $Platform + ) - Write-Diagnostic "Creating sdk for $Toolchain" + Write-Diagnostic "Creating sdk for $Toolchain" - $VisualStudioVersion = $null - if($Toolchain -eq "v141") - { - $VisualStudioVersion = "VS2017" - } - elseif($Toolchain -eq "v140") - { - $VisualStudioVersion = "VS2015" - } - elseif ($Toolchain -eq "v110") - { - $VisualStudioVersion = "VS2012" - } - else - { - $VisualStudioVersion = "VS2013" - } - - $Arch = TernaryReturn ($Platform -eq 'x64') 'x64' 'win32' - $CefArchDir = TernaryReturn ($Platform -eq 'x64') $Cef64 $Cef32 + $VisualStudioVersion = $null + if($Toolchain -eq "v141") + { + $VisualStudioVersion = "VS2017" + } + elseif($Toolchain -eq "v140") + { + $VisualStudioVersion = "VS2015" + } + elseif ($Toolchain -eq "v110") + { + $VisualStudioVersion = "VS2012" + } + else + { + $VisualStudioVersion = "VS2013" + } - # cef_binary_3.y.z_windows32\out\debug\lib -> cef\win32\debug\vs2013 - Copy-Item $CefArchDir\libcef_dll_wrapper\$Configuration\libcef_dll_wrapper.lib $Cef\$Arch\$Configuration\$VisualStudioVersion | Out-Null + $Arch = TernaryReturn ($Platform -eq 'x64') 'x64' 'win32' + $CefArchDir = TernaryReturn ($Platform -eq 'x64') $Cef64 $Cef32 - # cef_binary_3.y.z_windows32\debug -> cef\win32\debug - Copy-Item $CefArchDir\$Configuration\libcef.lib $Cef\$Arch\$Configuration | Out-Null -} + # cef_binary_3.y.z_windows32\out\debug\lib -> cef\win32\debug\vs2013 + Copy-Item $CefArchDir\libcef_dll_wrapper\$Configuration\libcef_dll_wrapper.lib $Cef\$Arch\$Configuration\$VisualStudioVersion | Out-Null -function Nupkg -{ - Write-Diagnostic "Building nuget package" + # cef_binary_3.y.z_windows32\debug -> cef\win32\debug + Copy-Item $CefArchDir\$Configuration\libcef.lib $Cef\$Arch\$Configuration | Out-Null + } - $Nuget = Join-Path $env:LOCALAPPDATA .\nuget\NuGet.exe - if (-not (Test-Path $Nuget)) + function Nupkg { - Die "Please install nuget. More information available at: http://docs.nuget.org/docs/start-here/installing-nuget" - } + Write-Diagnostic "Building nuget package" - # Build 32bit packages - . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x86;CPlatform=windows32;' -OutputDirectory nuget + $Nuget = Join-Path $env:LOCALAPPDATA .\nuget\NuGet.exe + if (-not (Test-Path $Nuget)) + { + Die "Please install nuget. More information available at: http://docs.nuget.org/docs/start-here/installing-nuget" + } - # Build 64bit packages - . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x64;CPlatform=windows64;' -OutputDirectory nuget + # Build 32bit packages + . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x86;CPlatform=windows32;' -OutputDirectory nuget - # Build sdk - $Filename = Resolve-Path ".\nuget\cef.sdk.props" - $Text = (Get-Content $Filename) -replace '.*<\/CefSdkVer>', "cef.sdk.$CefPackageVersion" - [System.IO.File]::WriteAllLines($Filename, $Text) + # Build 64bit packages + . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x64;CPlatform=windows64;' -OutputDirectory nuget - . $Nuget pack nuget\cef.sdk.nuspec -NoPackageAnalysis -Version $CefPackageVersion -OutputDirectory nuget + # Build sdk + $Filename = Resolve-Path ".\nuget\cef.sdk.props" + $Text = (Get-Content $Filename) -replace '.*<\/CefSdkVer>', "cef.sdk.$CefPackageVersion" + [System.IO.File]::WriteAllLines($Filename, $Text) - if ($env:APPVEYOR_REPO_TAG -eq "True") - { - appveyor PushArtifact "nuget\cef.redist.x86.$CefPackageVersion.nupkg" - appveyor PushArtifact "nuget\cef.redist.x64.$CefPackageVersion.nupkg" - appveyor PushArtifact "nuget\cef.sdk.$CefPackageVersion.nupkg" + . $Nuget pack nuget\cef.sdk.nuspec -NoPackageAnalysis -Version $CefPackageVersion -OutputDirectory nuget + + if ($env:APPVEYOR_REPO_TAG -eq "True") + { + appveyor PushArtifact "nuget\cef.redist.x86.$CefPackageVersion.nupkg" + appveyor PushArtifact "nuget\cef.redist.x64.$CefPackageVersion.nupkg" + appveyor PushArtifact "nuget\cef.sdk.$CefPackageVersion.nupkg" + } } -} -function DownloadNuget() -{ - $folder = Join-Path $env:LOCALAPPDATA .\nuget; - $Nuget = Join-Path $folder .\NuGet.exe - if (-not (Test-Path $Nuget)) + function DownloadNuget() { - if (-not (Test-Path $folder)) + $folder = Join-Path $env:LOCALAPPDATA .\nuget; + $Nuget = Join-Path $folder .\NuGet.exe + if (-not (Test-Path $Nuget)) { - mkdir $folder + if (-not (Test-Path $folder)) + { + mkdir $folder + } + + $Client = New-Object System.Net.WebClient; + $Client.DownloadFile('http://nuget.org/nuget.exe', $Nuget); } - - $Client = New-Object System.Net.WebClient; - $Client.DownloadFile('http://nuget.org/nuget.exe', $Nuget); } -} -function DownloadCefBinaryAndUnzip() -{ - $Client = New-Object System.Net.WebClient; + function DownloadCefBinaryAndUnzip() + { + $Client = New-Object System.Net.WebClient; - $CefBuildServerUrl = "http://opensource.spotify.com/cefbuilds/" - $CefBuildServerJsonPackageList = $CefBuildServerUrl + "index.json" + $CefBuildServerUrl = "http://opensource.spotify.com/cefbuilds/" + $CefBuildServerJsonPackageList = $CefBuildServerUrl + "index.json" - $CefBuildsJson = Invoke-WebRequest -Uri $CefBuildServerJsonPackageList | ConvertFrom-Json - $CefWin32CefVersion = $CefBuildsJson.windows32.versions | Where-Object {$_.cef_version -eq $CefVersion} - $CefWin64CefVersion = $CefBuildsJson.windows64.versions | Where-Object {$_.cef_version -eq $CefVersion} + $CefBuildsJson = Invoke-WebRequest -Uri $CefBuildServerJsonPackageList | ConvertFrom-Json + $CefWin32CefVersion = $CefBuildsJson.windows32.versions | Where-Object {$_.cef_version -eq $CefVersion} + $CefWin64CefVersion = $CefBuildsJson.windows64.versions | Where-Object {$_.cef_version -eq $CefVersion} - $Cef32FileName = ($CefWin32CefVersion.files | Where-Object {$_.type -eq "standard"}).name - $Cef32FileHash = ($CefWin32CefVersion.files | Where-Object {$_.type -eq "standard"}).sha1 - $Cef32FileSize = (($CefWin32CefVersion.files | Where-Object {$_.type -eq "standard"}).size /1MB) - $Cef64FileName = ($CefWin64CefVersion.files | Where-Object {$_.type -eq "standard"}).name - $Cef64FileHash = ($CefWin64CefVersion.files | Where-Object {$_.type -eq "standard"}).sha1 - $Cef64FileSize = (($CefWin64CefVersion.files | Where-Object {$_.type -eq "standard"}).size /1MB) + $Cef32FileName = ($CefWin32CefVersion.files | Where-Object {$_.type -eq "standard"}).name + $Cef32FileHash = ($CefWin32CefVersion.files | Where-Object {$_.type -eq "standard"}).sha1 + $Cef32FileSize = (($CefWin32CefVersion.files | Where-Object {$_.type -eq "standard"}).size /1MB) + $Cef64FileName = ($CefWin64CefVersion.files | Where-Object {$_.type -eq "standard"}).name + $Cef64FileHash = ($CefWin64CefVersion.files | Where-Object {$_.type -eq "standard"}).sha1 + $Cef64FileSize = (($CefWin64CefVersion.files | Where-Object {$_.type -eq "standard"}).size /1MB) - # Make sure there is a 32bit and 64bit version for the specified build - if ($CefWin32CefVersion.cef_version -ne $CefWin64CefVersion.cef_version) - { - Die 'Win32 version is $CefWin32CefVersion.cef_version and Win64 version is $CefWin64CefVersion.cef_version - both must be the same' - } + # Make sure there is a 32bit and 64bit version for the specified build + if ($CefWin32CefVersion.cef_version -ne $CefWin64CefVersion.cef_version) + { + Die 'Win32 version is $CefWin32CefVersion.cef_version and Win64 version is $CefWin64CefVersion.cef_version - both must be the same' + } - set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" + set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" - $LocalFile = Join-Path $WorkingDir $Cef32FileName + $LocalFile = Join-Path $WorkingDir $Cef32FileName - if (-not (Test-Path $LocalFile)) - { - Write-Diagnostic "Downloading $Cef32FileName; this will take a while as the file is $Cef32FileSize MB." - $Client.DownloadFile($CefBuildServerUrl + $Cef32FileName, $LocalFile); - - $Cef32LocalFileHash = (Get-FileHash -Path $LocalFile -Algorithm SHA1).Hash - - Write-Diagnostic "Download $Cef32FileName complete" - Write-Diagnostic "Expected SHA1 for $Cef32FileName $Cef32FileHash" - Write-Diagnostic "Actual SHA1 for $Cef32FileName $Cef32LocalFileHash" - - if($Cef32LocalFileHash -ne $Cef32FileHash) - { - Die "SHA1 hash did not match" + if (-not (Test-Path $LocalFile)) + { + Write-Diagnostic "Downloading $Cef32FileName; this will take a while as the file is $Cef32FileSize MB." + $Client.DownloadFile($CefBuildServerUrl + $Cef32FileName, $LocalFile); + + $Cef32LocalFileHash = (Get-FileHash -Path $LocalFile -Algorithm SHA1).Hash + + Write-Diagnostic "Download $Cef32FileName complete" + Write-Diagnostic "Expected SHA1 for $Cef32FileName $Cef32FileHash" + Write-Diagnostic "Actual SHA1 for $Cef32FileName $Cef32LocalFileHash" + + if($Cef32LocalFileHash -ne $Cef32FileHash) + { + Die "SHA1 hash did not match" + } } - } - if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) - { - # Extract bzip file - sz e $LocalFile + if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) + { + # Extract bzip file + sz e $LocalFile - # Extract tar file - $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) - sz x $TarFile + # Extract tar file + $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) + sz x $TarFile - # Sleep for a short period to allow 7z to release it's file handles - sleep -m 2000 + # Sleep for a short period to allow 7z to release it's file handles + sleep -m 2000 - # Remove tar file - Remove-Item $TarFile + # Remove tar file + Remove-Item $TarFile - $Folder = Join-Path $WorkingDir ($Cef32FileName.Substring(0, $Cef32FileName.length - 8)) - Move-Item ($Folder + '\*') $Cef32 -force - Remove-Item $Folder - } + $Folder = Join-Path $WorkingDir ($Cef32FileName.Substring(0, $Cef32FileName.length - 8)) + Move-Item ($Folder + '\*') $Cef32 -force + Remove-Item $Folder + } - $LocalFile = Join-Path $WorkingDir $Cef64FileName + $LocalFile = Join-Path $WorkingDir $Cef64FileName - if (-not (Test-Path $LocalFile)) - { - Write-Diagnostic "Downloading $Cef64FileName; this will take a while as the file is $Cef64FileSize MB." - $Client.DownloadFile($CefBuildServerUrl + $Cef64FileName, $LocalFile); - - $Cef64LocalFileHash = (Get-FileHash -Path $LocalFile -Algorithm SHA1).Hash - - Write-Diagnostic "Download $Cef64FileName complete" - Write-Diagnostic "Expected SHA1 for $Cef64FileName $Cef64FileHash" - Write-Diagnostic "Actual SHA1 for $Cef64FileName $Cef64LocalFileHash" - - if($Cef64LocalFileHash -ne $Cef64FileHash) - { - Die "SHA1 hash did not match" + if (-not (Test-Path $LocalFile)) + { + Write-Diagnostic "Downloading $Cef64FileName; this will take a while as the file is $Cef64FileSize MB." + $Client.DownloadFile($CefBuildServerUrl + $Cef64FileName, $LocalFile); + + $Cef64LocalFileHash = (Get-FileHash -Path $LocalFile -Algorithm SHA1).Hash + + Write-Diagnostic "Download $Cef64FileName complete" + Write-Diagnostic "Expected SHA1 for $Cef64FileName $Cef64FileHash" + Write-Diagnostic "Actual SHA1 for $Cef64FileName $Cef64LocalFileHash" + + if($Cef64LocalFileHash -ne $Cef64FileHash) + { + Die "SHA1 hash did not match" + } } - } - if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) - { - # Extract bzip file - sz e $LocalFile + if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) + { + # Extract bzip file + sz e $LocalFile - # Extract tar file - $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) - sz x $TarFile + # Extract tar file + $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) + sz x $TarFile - # Sleep for a short period to allow 7z to release it's file handles - sleep -m 2000 + # Sleep for a short period to allow 7z to release it's file handles + sleep -m 2000 - # Remove tar file - Remove-Item $TarFile + # Remove tar file + Remove-Item $TarFile - $Folder = Join-Path $WorkingDir ($Cef64FileName.Substring(0, $Cef64FileName.length - 8)) - Move-Item ($Folder + '\*') $Cef64 -force - Remove-Item $Folder + $Folder = Join-Path $WorkingDir ($Cef64FileName.Substring(0, $Cef64FileName.length - 8)) + Move-Item ($Folder + '\*') $Cef64 -force + Remove-Item $Folder + } } -} -function CopyFromLocalCefBuild() -{ - # Example file names from cefsource build: - # 32-bit: cef_binary_3.2924.1538.gbfdeccd_windows32.tar.bz2 - # 64-bit: cef_binary_3.2924.1538.gbfdeccd_windows64.tar.bz2 - - Write-Host $CefVersion + function CopyFromLocalCefBuild() + { + # Example file names from cefsource build: + # 32-bit: cef_binary_3.2924.1538.gbfdeccd_windows32.tar.bz2 + # 64-bit: cef_binary_3.2924.1538.gbfdeccd_windows64.tar.bz2 - $Cef32FileName = "cef_binary_$($CefVersion)_windows32." + $Extension; - $Cef64FileName = "cef_binary_$($CefVersion)_windows64." + $Extension; + Write-Host $CefVersion - set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" + $Cef32FileName = "cef_binary_$($CefVersion)_windows32." + $Extension; + $Cef64FileName = "cef_binary_$($CefVersion)_windows64." + $Extension; - if ([System.IO.Path]::IsPathRooted($CefBinaryDir)) - { - $CefBuildDir = $CefBinaryDir - } - else - { - $CefBuildDir = Join-Path $WorkingDir "$CefBinaryDir/" - } + set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" - $LocalFile = Join-Path $WorkingDir $Cef32FileName + if ([System.IO.Path]::IsPathRooted($CefBinaryDir)) + { + $CefBuildDir = $CefBinaryDir + } + else + { + $CefBuildDir = Join-Path $WorkingDir "$CefBinaryDir/" + } - if (-not (Test-Path $LocalFile)) - { - Write-Diagnostic "Copy $Cef32FileName (approx 200mb)" - Copy-Item ($CefBuildDir+$Cef32FileName) $LocalFile - Write-Diagnostic "Copy of $Cef32FileName complete" - } + $LocalFile = Join-Path $WorkingDir $Cef32FileName - if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) - { - # Extract bzip file - sz x $LocalFile; + if (-not (Test-Path $LocalFile)) + { + Write-Diagnostic "Copy $Cef32FileName (approx 200mb)" + Copy-Item ($CefBuildDir+$Cef32FileName) $LocalFile + Write-Diagnostic "Copy of $Cef32FileName complete" + } - if ($Extension -eq "tar.bz2") + if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) { - # Extract tar file - $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) - sz x $TarFile + # Extract bzip file + sz x $LocalFile; - # Sleep for a short period to allow 7z to release it's file handles - sleep -m 2000 + if ($Extension -eq "tar.bz2") + { + # Extract tar file + $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) + sz x $TarFile - # Remove tar file - Remove-Item $TarFile - } + # Sleep for a short period to allow 7z to release it's file handles + sleep -m 2000 - $Folder = Join-Path $WorkingDir ($Cef32FileName.Substring(0, $Cef32FileName.length - ($Extension.Length+1))) - Move-Item ($Folder + '\*') $Cef32 -force - Remove-Item $Folder - } + # Remove tar file + Remove-Item $TarFile + } - $LocalFile = Join-Path $WorkingDir $Cef64FileName + $Folder = Join-Path $WorkingDir ($Cef32FileName.Substring(0, $Cef32FileName.length - ($Extension.Length+1))) + Move-Item ($Folder + '\*') $Cef32 -force + Remove-Item $Folder + } - if (-not (Test-Path $LocalFile)) - { - Write-Diagnostic "Copy $Cef64FileName (approx 200mb)" - Copy-Item ($CefBuildDir+$Cef64FileName) $LocalFile; - Write-Diagnostic "Copy of $Cef64FileName complete" - } + $LocalFile = Join-Path $WorkingDir $Cef64FileName - if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) - { - # Extract bzip file - sz x $LocalFile; + if (-not (Test-Path $LocalFile)) + { + Write-Diagnostic "Copy $Cef64FileName (approx 200mb)" + Copy-Item ($CefBuildDir+$Cef64FileName) $LocalFile; + Write-Diagnostic "Copy of $Cef64FileName complete" + } - if ($Extension -eq "tar.bz2") + if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) { - # Extract tar file - $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) - sz x $TarFile + # Extract bzip file + sz x $LocalFile; - # Sleep for a short period to allow 7z to release it's file handles - sleep -m 2000 + if ($Extension -eq "tar.bz2") + { + # Extract tar file + $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) + sz x $TarFile - # Remove tar file - Remove-Item $TarFile + # Sleep for a short period to allow 7z to release it's file handles + sleep -m 2000 + + # Remove tar file + Remove-Item $TarFile + } + $Folder = Join-Path $WorkingDir ($Cef64FileName.Substring(0, $Cef64FileName.length - ($Extension.Length+1))) + Move-Item ($Folder + '\*') $Cef64 -force + Remove-Item $Folder } - $Folder = Join-Path $WorkingDir ($Cef64FileName.Substring(0, $Cef64FileName.length - ($Extension.Length+1))) - Move-Item ($Folder + '\*') $Cef64 -force - Remove-Item $Folder } -} -function CheckDependencies() -{ - # Check for cmake - if ((Get-Command "cmake.exe" -ErrorAction SilentlyContinue) -eq $null) + function CheckDependencies() { - Die "Unable to find cmake.exe in your PATH" - } + # Check for cmake + if ((Get-Command "cmake.exe" -ErrorAction SilentlyContinue) -eq $null) + { + Die "Unable to find cmake.exe in your PATH" + } - # Check for 7zip - if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) - { - Die "$env:ProgramFiles\7-Zip\7z.exe is required" + # Check for 7zip + if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) + { + Die "$env:ProgramFiles\7-Zip\7z.exe is required" + } } -} -CheckDependencies + CheckDependencies -switch -Exact ($DownloadBinary) -{ - "none" - { - } - "download" + switch -Exact ($DownloadBinary) { - DownloadCefBinaryAndUnzip - } - "local" - { - CopyFromLocalCefBuild + "none" + { + } + "download" + { + DownloadCefBinaryAndUnzip + } + "local" + { + CopyFromLocalCefBuild + } } -} -DownloadNuget + DownloadNuget -Bootstrap + Bootstrap -switch -Exact ($Target) -{ - "nupkg" - { - VSX v141 - VSX v140 - Nupkg - } - "nupkg-only" - { - Nupkg - } - "vs2013" - { - VSX v120 - } - "vs2012" - { - VSX v110 - } - "vs2015" - { - VSX v140 - } - "vs2017" + switch -Exact ($Target) { - VSX v141 + "nupkg" + { + #VSX v110 + #VSX v120 + VSX v141 + VSX v140 + Nupkg + } + "nupkg-only" + { + Nupkg + } + "vs2013" + { + VSX v120 + } + "vs2012" + { + VSX v110 + } + "vs2015" + { + VSX v140 + } + "vs2017" + { + VSX v141 + } } +} +catch +{ + WriteException $_; } \ No newline at end of file