From 82e200b919d845f7071c4a84309f58bea9a51261 Mon Sep 17 00:00:00 2001 From: amaitland Date: Sat, 15 Dec 2018 20:08:56 +1000 Subject: [PATCH] build.ps1 - Remove WriteException and try/catch See if we get better error details from just the raw cmake output --- build.ps1 | 1162 ++++++++++++++++++++++++++--------------------------- 1 file changed, 571 insertions(+), 591 deletions(-) diff --git a/build.ps1 b/build.ps1 index e54b55a..dcadbda 100644 --- a/build.ps1 +++ b/build.ps1 @@ -26,733 +26,713 @@ Set-StrictMode -version latest $ErrorActionPreference = "Stop"; $Extension = $Extension.ToLower(); -Function WriteException($exp) +$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition; +if ($CefVersion -eq "auto" -and $DownloadBinary -eq "local") { - 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; + #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"; } -try + +$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 { - $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"; - } + param( + [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] + [string] $Message + ) + + Write-Host + Write-Host $Message -ForegroundColor Green + Write-Host +} +# 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" +} - $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' +# Take the cef version and strip the commit hash +$CefPackageVersion = $CefVersion.SubString(0, $CefVersion.LastIndexOf('.')) - function Write-Diagnostic - { - param( - [Parameter(Position = 0, Mandatory = $true, 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 + ) + + $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 +} - Write-Host - Write-Host $Message -ForegroundColor Green - Write-Host - } +function Die +{ + param( + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Message + ) - # 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" - } + Write-Host + Write-Error $Message + exit 1 - # Take the cef version and strip the commit hash - $CefPackageVersion = $CefVersion.SubString(0, $CefVersion.LastIndexOf('.')) +} - # 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 - ) +function Warn +{ + param( + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Message + ) - $tempFile = [IO.Path]::GetTempFileName() + Write-Host + Write-Host $Message -ForegroundColor Yellow + Write-Host - # 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 +function TernaryReturn +{ + param( + [Parameter(Position = 0, ValueFromPipeline = $true)] + [bool] $Yes, + [Parameter(Position = 1, ValueFromPipeline = $true)] + $Value, + [Parameter(Position = 2, ValueFromPipeline = $true)] + $Value2 + ) - #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 + if ($Yes) + { + return $Value } - function Die - { - param( - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Message - ) + $Value2 - Write-Host - Write-Error $Message - exit 1 +} - } +function Bootstrap +{ + param() - function Warn + if ($Target -eq "nupkg-only") { - param( - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Message - ) - - Write-Host - Write-Host $Message -ForegroundColor Yellow - Write-Host - + return } - function TernaryReturn - { - param( - [Parameter(Position = 0, ValueFromPipeline = $true)] - [bool] $Yes, - [Parameter(Position = 1, ValueFromPipeline = $true)] - $Value, - [Parameter(Position = 2, ValueFromPipeline = $true)] - $Value2 - ) + Write-Diagnostic "Bootstrapping" - if ($Yes) - { - return $Value - } + if (Test-Path($Cef)) + { + Remove-Item $Cef -Recurse | Out-Null + } - $Value2 + # 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, - function Bootstrap - { - param() + [Parameter(Position = 1, ValueFromPipeline = $true)] + [ValidateSet('Debug', 'Release')] + [string] $Configuration, - if ($Target -eq "nupkg-only") - { - return - } + [Parameter(Position = 2, ValueFromPipeline = $true)] + [ValidateSet('x86', 'x64')] + [string] $Platform + ) - Write-Diagnostic "Bootstrapping" + Write-Diagnostic "Targeting $Toolchain using configuration $Configuration on platform $Platform" - if (Test-Path($Cef)) - { - Remove-Item $Cef -Recurse | Out-Null - } + $VisualStudioVersion = $null + $VXXCommonTools = $null + $CmakeGenerator = $null - # 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) + switch -Exact ($Toolchain) + { + 'v110' { - 'v110' + if($env:VS110COMNTOOLS -eq $null) { - 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' + Die "Visual Studio 2012 was not found" } - 'v120' + $VisualStudioVersion = '11.0' + $VXXCommonTools = Join-Path $env:VS110COMNTOOLS '..\..\vc' + $CmakeGenerator = 'Visual Studio 11' + } + 'v120' + { + if($env:VS120COMNTOOLS -eq $null) { - 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' + Die "Visual Studio 2013 was not found" } - 'v140' + $VisualStudioVersion = '12.0' + $VXXCommonTools = Join-Path $env:VS120COMNTOOLS '..\..\vc' + $CmakeGenerator = 'Visual Studio 12' + } + 'v140' + { + if($env:VS140COMNTOOLS -eq $null) { - 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' + Die "Visual Studio 2015 was not found" } - 'v141' - { - $programFilesDir = (${env:ProgramFiles(x86)}, ${env:ProgramFiles} -ne $null)[0] + $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" + $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" - $VS2017InstallPath = & $vswherePath -version 15 -property installationPath + # Check if we already have a local copy and download if required + $vswherePath = Join-Path $WorkingDir \vswhere.exe - Write-Diagnostic "VS2017InstallPath: $VS2017InstallPath" - - if($VS2017InstallPath -eq $null -or !(Test-Path $VS2017InstallPath)) + # TODO: Check hash and download if hash differs + if(-not (Test-Path $vswherePath)) { - Die "Visual Studio 2017 was not found" + $client = New-Object System.Net.WebClient; + $client.DownloadFile('https://github.com/Microsoft/vswhere/releases/download/2.5.2/vswhere.exe', $vswherePath); } - - $VisualStudioVersion = '15.0' - $VXXCommonTools = Join-Path $VS2017InstallPath VC\Auxiliary\Build - $CmakeGenerator = 'Visual Studio 15' } + + Write-Diagnostic "VSWhere path $vswherePath" + + $VS2017InstallPath = & $vswherePath -version 15 -property installationPath + + 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 - } + $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 - } + $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" - } + # 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) - } + $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) + } - $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" - } + $StartInfo.UseShellExecute = $false + $StartInfo.CreateNoWindow = $false + $StartInfo.RedirectStandardError = $true + $StartInfo.RedirectStandardOutput = $true - CreateCefSdk $Toolchain $Configuration $Platform - } + $Process = New-Object System.Diagnostics.Process + $Process.StartInfo = $startInfo + $Process.Start() + + $stdout = $Process.StandardOutput.ReadToEnd() + $stderr = $Process.StandardError.ReadToEnd() - function VSX + $Process.WaitForExit() + + if ($Process.ExitCode -ne 0) { - param( - [ValidateSet('v110', 'v120', 'v140', 'v141')] - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Toolchain - ) + Write-Host "stdout: $stdout" + Write-Host "stderr: $stderr" + Die "Build failed" + } - Write-Diagnostic "Starting to build targeting toolchain $Toolchain" + CreateCefSdk $Toolchain $Configuration $Platform +} - if (! $NoDebugBuild) - { - Msvs "$Toolchain" 'Debug' 'x86' - } - Msvs "$Toolchain" 'Release' 'x86' - if (! $NoDebugBuild) - { - Msvs "$Toolchain" 'Debug' 'x64' - } - Msvs "$Toolchain" 'Release' 'x64' +function VSX +{ + param( + [ValidateSet('v110', 'v120', 'v140', 'v141')] + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Toolchain + ) - Write-Diagnostic "Finished build targeting toolchain $Toolchain" - } + Write-Diagnostic "Starting to build targeting toolchain $Toolchain" - function CreateCefSdk + if (! $NoDebugBuild) { - param( - [ValidateSet('v110', 'v120', 'v140', 'v141')] - [Parameter(Position = 0, ValueFromPipeline = $true)] - [string] $Toolchain, - - [Parameter(Position = 1, ValueFromPipeline = $true)] - [ValidateSet('Debug', 'Release')] - [string] $Configuration, + Msvs "$Toolchain" 'Debug' 'x86' + } + Msvs "$Toolchain" 'Release' 'x86' + if (! $NoDebugBuild) + { + Msvs "$Toolchain" 'Debug' 'x64' + } + Msvs "$Toolchain" 'Release' 'x64' - [Parameter(Position = 2, ValueFromPipeline = $true)] - [ValidateSet('x86', 'x64')] - [string] $Platform - ) + Write-Diagnostic "Finished build targeting toolchain $Toolchain" +} - Write-Diagnostic "Creating sdk for $Toolchain" +function CreateCefSdk +{ + param( + [ValidateSet('v110', 'v120', 'v140', 'v141')] + [Parameter(Position = 0, ValueFromPipeline = $true)] + [string] $Toolchain, - $VisualStudioVersion = $null - if($Toolchain -eq "v141") - { - $VisualStudioVersion = "VS2017" - } - elseif($Toolchain -eq "v140") - { - $VisualStudioVersion = "VS2015" - } - elseif ($Toolchain -eq "v110") - { - $VisualStudioVersion = "VS2012" - } - else - { - $VisualStudioVersion = "VS2013" - } + [Parameter(Position = 1, ValueFromPipeline = $true)] + [ValidateSet('Debug', 'Release')] + [string] $Configuration, - $Arch = TernaryReturn ($Platform -eq 'x64') 'x64' 'win32' - $CefArchDir = TernaryReturn ($Platform -eq 'x64') $Cef64 $Cef32 + [Parameter(Position = 2, ValueFromPipeline = $true)] + [ValidateSet('x86', 'x64')] + [string] $Platform + ) - # 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 + Write-Diagnostic "Creating sdk for $Toolchain" - # cef_binary_3.y.z_windows32\debug -> cef\win32\debug - Copy-Item $CefArchDir\$Configuration\libcef.lib $Cef\$Arch\$Configuration | Out-Null + $VisualStudioVersion = $null + if($Toolchain -eq "v141") + { + $VisualStudioVersion = "VS2017" } - - function Nupkg + elseif($Toolchain -eq "v140") { - Write-Diagnostic "Building nuget package" - - $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" - } + $VisualStudioVersion = "VS2015" + } + elseif ($Toolchain -eq "v110") + { + $VisualStudioVersion = "VS2012" + } + else + { + $VisualStudioVersion = "VS2013" + } - # Build 32bit packages - . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x86;CPlatform=windows32;' -OutputDirectory nuget + $Arch = TernaryReturn ($Platform -eq 'x64') 'x64' 'win32' + $CefArchDir = TernaryReturn ($Platform -eq 'x64') $Cef64 $Cef32 - # Build 64bit packages - . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x64;CPlatform=windows64;' -OutputDirectory nuget + # 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 - # Build sdk - $Filename = Resolve-Path ".\nuget\cef.sdk.props" - $Text = (Get-Content $Filename) -replace '.*<\/CefSdkVer>', "cef.sdk.$CefPackageVersion" - [System.IO.File]::WriteAllLines($Filename, $Text) + # cef_binary_3.y.z_windows32\debug -> cef\win32\debug + Copy-Item $CefArchDir\$Configuration\libcef.lib $Cef\$Arch\$Configuration | Out-Null +} - . $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 Nupkg +{ + Write-Diagnostic "Building nuget package" - function DownloadNuget() + $Nuget = Join-Path $env:LOCALAPPDATA .\nuget\NuGet.exe + if (-not (Test-Path $Nuget)) { - $folder = Join-Path $env:LOCALAPPDATA .\nuget; - $Nuget = Join-Path $folder .\NuGet.exe - if (-not (Test-Path $Nuget)) - { - if (-not (Test-Path $folder)) - { - mkdir $folder - } - - $Client = New-Object System.Net.WebClient; - $Client.DownloadFile('http://nuget.org/nuget.exe', $Nuget); - } + Die "Please install nuget. More information available at: http://docs.nuget.org/docs/start-here/installing-nuget" } - function DownloadCefBinaryAndUnzip() - { - $Client = New-Object System.Net.WebClient; + # Build 32bit packages + . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x86;CPlatform=windows32;' -OutputDirectory nuget - $CefBuildServerUrl = "http://opensource.spotify.com/cefbuilds/" - $CefBuildServerJsonPackageList = $CefBuildServerUrl + "index.json" + # Build 64bit packages + . $Nuget pack nuget\cef.redist.nuspec -NoPackageAnalysis -Version $CefPackageVersion -Properties 'Configuration=Release;Platform=x64;CPlatform=windows64;' -OutputDirectory nuget - $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} + # Build sdk + $Filename = Resolve-Path ".\nuget\cef.sdk.props" + $Text = (Get-Content $Filename) -replace '.*<\/CefSdkVer>', "cef.sdk.$CefPackageVersion" + [System.IO.File]::WriteAllLines($Filename, $Text) - $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) + . $Nuget pack nuget\cef.sdk.nuspec -NoPackageAnalysis -Version $CefPackageVersion -OutputDirectory nuget - # Make sure there is a 32bit and 64bit version for the specified build - if ($CefWin32CefVersion.cef_version -ne $CefWin64CefVersion.cef_version) + 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)) + { + if (-not (Test-Path $folder)) { - Die 'Win32 version is $CefWin32CefVersion.cef_version and Win64 version is $CefWin64CefVersion.cef_version - both must be the same' + mkdir $folder } + + $Client = New-Object System.Net.WebClient; + $Client.DownloadFile('http://nuget.org/nuget.exe', $Nuget); + } +} - set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" +function DownloadCefBinaryAndUnzip() +{ + $Client = New-Object System.Net.WebClient; - $LocalFile = Join-Path $WorkingDir $Cef32FileName + $CefBuildServerUrl = "http://opensource.spotify.com/cefbuilds/" + $CefBuildServerJsonPackageList = $CefBuildServerUrl + "index.json" - 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" - } - } + $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} - if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) - { - # Extract bzip file - sz e $LocalFile + $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) - # Extract tar file - $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) - sz x $TarFile + # 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' + } - # Sleep for a short period to allow 7z to release it's file handles - sleep -m 2000 + set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" - # Remove tar file - Remove-Item $TarFile + $LocalFile = Join-Path $WorkingDir $Cef32FileName - $Folder = Join-Path $WorkingDir ($Cef32FileName.Substring(0, $Cef32FileName.length - 8)) - Move-Item ($Folder + '\*') $Cef32 -force - Remove-Item $Folder + 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" } + } - $LocalFile = Join-Path $WorkingDir $Cef64FileName + if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) + { + # Extract bzip file + sz e $LocalFile - 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" - } - } + # Extract tar file + $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) + sz x $TarFile - if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) - { - # Extract bzip file - sz e $LocalFile + # Sleep for a short period to allow 7z to release it's file handles + sleep -m 2000 - # 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 - 8)) + Move-Item ($Folder + '\*') $Cef32 -force + Remove-Item $Folder + } - # Remove tar file - Remove-Item $TarFile + $LocalFile = Join-Path $WorkingDir $Cef64FileName - $Folder = Join-Path $WorkingDir ($Cef64FileName.Substring(0, $Cef64FileName.length - 8)) - Move-Item ($Folder + '\*') $Cef64 -force - Remove-Item $Folder + 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" } } - function CopyFromLocalCefBuild() + if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) { - # 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 + # Extract bzip file + sz e $LocalFile - Write-Host $CefVersion + # Extract tar file + $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) + sz x $TarFile - $Cef32FileName = "cef_binary_$($CefVersion)_windows32." + $Extension; - $Cef64FileName = "cef_binary_$($CefVersion)_windows64." + $Extension; + # Sleep for a short period to allow 7z to release it's file handles + sleep -m 2000 - set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" + # Remove tar file + Remove-Item $TarFile - if ([System.IO.Path]::IsPathRooted($CefBinaryDir)) - { - $CefBuildDir = $CefBinaryDir - } - else - { - $CefBuildDir = Join-Path $WorkingDir "$CefBinaryDir/" - } + $Folder = Join-Path $WorkingDir ($Cef64FileName.Substring(0, $Cef64FileName.length - 8)) + Move-Item ($Folder + '\*') $Cef64 -force + Remove-Item $Folder + } +} - $LocalFile = Join-Path $WorkingDir $Cef32FileName +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 - if (-not (Test-Path $LocalFile)) - { - Write-Diagnostic "Copy $Cef32FileName (approx 200mb)" - Copy-Item ($CefBuildDir+$Cef32FileName) $LocalFile - Write-Diagnostic "Copy of $Cef32FileName complete" - } + Write-Host $CefVersion - if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) - { - # Extract bzip file - sz x $LocalFile; + $Cef32FileName = "cef_binary_$($CefVersion)_windows32." + $Extension; + $Cef64FileName = "cef_binary_$($CefVersion)_windows64." + $Extension; - if ($Extension -eq "tar.bz2") - { - # Extract tar file - $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) - sz x $TarFile + set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" - # Sleep for a short period to allow 7z to release it's file handles - sleep -m 2000 + if ([System.IO.Path]::IsPathRooted($CefBinaryDir)) + { + $CefBuildDir = $CefBinaryDir + } + else + { + $CefBuildDir = Join-Path $WorkingDir "$CefBinaryDir/" + } - # Remove tar file - Remove-Item $TarFile - } + $LocalFile = Join-Path $WorkingDir $Cef32FileName - $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 $Cef32FileName (approx 200mb)" + Copy-Item ($CefBuildDir+$Cef32FileName) $LocalFile + Write-Diagnostic "Copy of $Cef32FileName complete" + } - $LocalFile = Join-Path $WorkingDir $Cef64FileName + if (-not (Test-Path (Join-Path $Cef32 '\include\cef_version.h'))) + { + # Extract bzip file + sz x $LocalFile; - if (-not (Test-Path $LocalFile)) + if ($Extension -eq "tar.bz2") { - Write-Diagnostic "Copy $Cef64FileName (approx 200mb)" - Copy-Item ($CefBuildDir+$Cef64FileName) $LocalFile; - Write-Diagnostic "Copy of $Cef64FileName complete" - } + # Extract tar file + $TarFile = ($LocalFile).Substring(0, $LocalFile.length - 4) + sz x $TarFile - if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) - { - # 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 - } - $Folder = Join-Path $WorkingDir ($Cef64FileName.Substring(0, $Cef64FileName.length - ($Extension.Length+1))) - Move-Item ($Folder + '\*') $Cef64 -force - Remove-Item $Folder - } + $LocalFile = Join-Path $WorkingDir $Cef64FileName + + if (-not (Test-Path $LocalFile)) + { + Write-Diagnostic "Copy $Cef64FileName (approx 200mb)" + Copy-Item ($CefBuildDir+$Cef64FileName) $LocalFile; + Write-Diagnostic "Copy of $Cef64FileName complete" } - function CheckDependencies() + if (-not (Test-Path (Join-Path $Cef64 '\include\cef_version.h'))) { - # Check for cmake - if ((Get-Command "cmake.exe" -ErrorAction SilentlyContinue) -eq $null) - { - Die "Unable to find cmake.exe in your PATH" - } + # Extract bzip file + sz x $LocalFile; - # Check for 7zip - if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) + if ($Extension -eq "tar.bz2") { - Die "$env:ProgramFiles\7-Zip\7z.exe is required" + # 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 + + # 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 } +} - CheckDependencies - - switch -Exact ($DownloadBinary) +function CheckDependencies() +{ + # Check for cmake + if ((Get-Command "cmake.exe" -ErrorAction SilentlyContinue) -eq $null) { - "none" - { - } - "download" - { - DownloadCefBinaryAndUnzip - } - "local" - { - CopyFromLocalCefBuild - } + Die "Unable to find cmake.exe in your PATH" } - DownloadNuget + # Check for 7zip + if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) + { + Die "$env:ProgramFiles\7-Zip\7z.exe is required" + } +} - Bootstrap +CheckDependencies - switch -Exact ($Target) +switch -Exact ($DownloadBinary) +{ + "none" { - "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 - } + } + "download" + { + DownloadCefBinaryAndUnzip + } + "local" + { + CopyFromLocalCefBuild } } -catch + +DownloadNuget + +Bootstrap + +switch -Exact ($Target) { - WriteException $_; + "nupkg" + { + VSX v141 + VSX v140 + Nupkg + } + "nupkg-only" + { + Nupkg + } + "vs2013" + { + VSX v120 + } + "vs2012" + { + VSX v110 + } + "vs2015" + { + VSX v140 + } + "vs2017" + { + VSX v141 + } } \ No newline at end of file