From c5b9afa083d8b44b75c46dd31521c98bbeb7e3c8 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Thu, 24 Nov 2016 19:55:35 +0900 Subject: [PATCH] If the package needs vc14, distribute it with vcruntime140.dll instead of msvcr1x0.dll or with Visual C++ Redistributable 2015. --- installer/buildInstallers.ps1 | 64 +++++++++------ .../psqlodbc-setup/buildBootstrapper.ps1 | 1 + installer/psqlodbc-setup/vcredist.wxs | 79 ++++++++++--------- 3 files changed, 84 insertions(+), 60 deletions(-) diff --git a/installer/buildInstallers.ps1 b/installer/buildInstallers.ps1 index d9ebf19..c6ab101 100644 --- a/installer/buildInstallers.ps1 +++ b/installer/buildInstallers.ps1 @@ -10,6 +10,8 @@ Specify when you'd like to build drivers before building installers. .PARAMETER ExcludeRuntime Specify when you'd like to exclude a msvc runtime dll from the installer. +.PARAMETER RedistUCRT + Specify when you'd like to redistribute Visual C++ 2015(or later) Redistributable. .PARAMETER BuildConfigPath Specify the configuration xml file name if you want to use the configuration file other than standard one. @@ -31,24 +33,35 @@ Param( [string]$cpu="both", [switch]$AlongWithDrivers, [switch]$ExcludeRuntime, +[switch]$RedistUCRT, [string]$BuildConfigPath ) -function findRuntime($runtime_version, $pgmvc) +[int]$ucrt_version=14 +[String]$str_msvcr="msvcr" +[String]$str_vcrun="vcruntime" +[String]$str_msvcp="msvcp" +[String]$msrun_ptn="msvcr|vcruntime" + +function msvcrun([int]$runtime_version) +{ + [String]$str = if ($runtime_version -lt $ucrt_version) {$str_msvcr} else {$str_vcrun} + return $str +} + +function findRuntime([int]$runtime_version, [String]$pgmvc) { # where's the dll? - $rt_dllname="msvcr${runtime_version}0.dll" + [String]$rt_dllname = (msvcrun $runtime_version) + "${runtime_version}0.dll" if ("$pgmvc" -ne "") { $dllspecified = "${pgmvc}\${rt_dllname}" if (Test-Path -Path $dllspecified) { - $dllspecified - return "" + return $dllspecified, "" } } $dllinredist = "${LIBPQBINDIR}\${rt_dllname}" if (Test-Path -Path $dllinredist) { - $dllinredist - return "" + return $dllinredist, "" } if ($env:PROCESSOR_ARCHITECTURE -eq "x86") { $pgmvc = "$env:ProgramFiles" @@ -57,8 +70,7 @@ function findRuntime($runtime_version, $pgmvc) } $dllinredist = "$pgmvc\Microsoft Visual Studio ${runtime_version}.0\VC\redist\${CPUTYPE}\Microsoft.VC${runtime_version}0.CRT\${rt_dllname}" if (Test-Path -Path $dllinredist) { - $dllinredist - return "" + return $dllinredist, "" } else { $messageSpec = "Please specify Configuration.$CPUTYPE.runtime_folder element of the configuration file where msvc runtime dll $rt_dllname can be found" if ($CPUTYPE -eq "x86") { @@ -81,8 +93,7 @@ function findRuntime($runtime_version, $pgmvc) throw "${messageSpec}`nneither $dllinredist nor $dllinsystem exists unfortunately" } } - "" - return $rt_dllname + return "", $rt_dllname } function getVersion($connInfo) @@ -112,32 +123,38 @@ function buildInstaller($CPUTYPE) if (-not $ExcludeRuntime) { $toolset = $configInfo.Configuration.BuildResult.PlatformToolset if ($toolset -match "^v(\d+)0") { - $runtime_version0 = $matches[1] + $runtime_version0 = [int]$matches[1] } else { - $runtime_version0 = "10" + $runtime_version0 = 10 } # where's the msvc runtime dll psqlodbc links? - if ([int] $runtime_version0 -lt 14) { + if ($runtime_version0 -ge $ucrt_version -and $RedistUCRT) { + $script:wRedist=$true + } else { $dlls=findRuntime $runtime_version0 $pgmvc $PODBCMSVCDLL=$dlls[0] - $PODBCMSVPDLL=$PODBCMSVCDLL.Replace("msvcr", "msvcp") $PODBCMSVCSYS=$dlls[1] - $PODBCMSVPSYS=$PODBCMSVCSYS.Replace("msvcr", "msvcp") + $PODBCMSVPDLL=$PODBCMSVCDLL.Replace((msvcrun $runtime_version0), $str_msvcp) + $PODBCMSVPSYS=$PODBCMSVCSYS.Replace((msvcrun $runtime_version0), $str_msvcp) } # where's the runtime dll libpq links? - $msvclist=& ${dumpbinexe} /imports $LIBPQBINDIR\libpq.dll | select-string -pattern "^\s*msvcr(\d+)0\.dll" | % {$_.matches[0].Groups[1].Value} + $msvclist=& ${dumpbinexe} /imports $LIBPQBINDIR\libpq.dll | select-string -pattern "^\s*($msrun_ptn)(\d+)0\.dll" | % {$_.matches[0].Groups[2].Value} if ($msvclist -ne $Null -and $msvclist.length -gt 0) { if ($msvclist.GetType().Name -eq "String") { - $runtime_version1=$msvclist + $runtime_version1=[int]$msvclist } else { - $runtime_version1=$msvclist[0] + $runtime_version1=[int]$msvclist[0] } - if ($runtime_version1 -ne $runtime_version0) { + if ($runtime_version1 -ge $ucrt_version -and $RedistUCRT) { + $script:wRedist=$true + } elseif ($runtime_version1 -ne $runtime_version0) { $dlls=findRuntime $runtime_version1 $pgmvc $LIBPQMSVCDLL=$dlls[0] $LIBPQMSVCSYS=$dlls[1] - Write-Host "LIBPQ requires msvcr${runtime_version1}0.dll" + Write-Host "LIBPQ requires $LIBPQMSVCDLL$LIBPQMSYCSYS" } + } else { + $script:wRedist=$true } } @@ -157,7 +174,7 @@ function buildInstaller($CPUTYPE) $maxmem=10 $libpqmem=Get-RelatedDlls "libpq.dll" $LIBPQBINDIR for ($i=0; $i -lt $libpqmem.length; ) { - if ($libpqmem[$i] -match "^msvcr\d+0.dll") { + if ($libpqmem[$i] -match "^($msrun_ptn)\d+0.dll") { $libpqmem[$i]=$Null } else { $i++ @@ -255,13 +272,16 @@ Import-Module ${scriptPath}\..\winbuild\MSProgram-Get.psm1 try { $dumpbinexe = Find-Dumpbin + $wRedist=$false $VERSION = getVersion $configInfo if ($cpu -eq "both") { buildInstaller "x86" buildInstaller "x64" + $VERSION = $configInfo.Configuration.version + write-host "wRedist=$wRedist" try { pushd "$scriptPath" - psqlodbc-setup\buildBootstrapper.ps1 -version $VERSION + psqlodbc-setup\buildBootstrapper.ps1 -version $VERSION -withRedist:$wRedist if ($LASTEXITCODE -ne 0) { throw "Failed to build bootstrapper" } diff --git a/installer/psqlodbc-setup/buildBootstrapper.ps1 b/installer/psqlodbc-setup/buildBootstrapper.ps1 index b837bed..a122049 100644 --- a/installer/psqlodbc-setup/buildBootstrapper.ps1 +++ b/installer/psqlodbc-setup/buildBootstrapper.ps1 @@ -57,6 +57,7 @@ if ($withRedist) { $modules += "vcredist.wxs" $objs += "${objdir}\vcredist.wixobj" $wRedist = "yes" + write-host "with Redistributable" } $wUI = "no" if ($UI) { diff --git a/installer/psqlodbc-setup/vcredist.wxs b/installer/psqlodbc-setup/vcredist.wxs index 7342729..f588a3d 100755 --- a/installer/psqlodbc-setup/vcredist.wxs +++ b/installer/psqlodbc-setup/vcredist.wxs @@ -1,38 +1,41 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + -- 2.39.5