If the package needs vc14, distribute it with vcruntime140.dll instead of msvcr1x0...
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Thu, 24 Nov 2016 10:55:35 +0000 (19:55 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Thu, 24 Nov 2016 10:55:35 +0000 (19:55 +0900)
installer/buildInstallers.ps1
installer/psqlodbc-setup/buildBootstrapper.ps1
installer/psqlodbc-setup/vcredist.wxs

index d9ebf194fc5b220a6403bcc21b5a3077f8a7d576..c6ab101c996f176ad53fdccedc64b9160158e2fc 100644 (file)
@@ -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"
            }
index b837bed1866a4d825d2513c2d65c3d2d2b551a29..a1220494748284a23d47b3f3d9be0a0c0296329c 100644 (file)
@@ -57,6 +57,7 @@ if ($withRedist) {
    $modules += "vcredist.wxs"
    $objs += "${objdir}\vcredist.wixobj"
    $wRedist = "yes"
+   write-host "with Redistributable"
 }
 $wUI = "no"
 if ($UI) {
index 7342729abf35aeaf7c65c86ce4723dae99489515..f588a3d135b80386daa0eb6aca137dbfb67f623c 100755 (executable)
@@ -1,38 +1,41 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<!-- ?define vcredist_x86 =  http://download.microsoft.com/download/d/d/9/dd9a82d0-52ef-40db-8dab-795376989c03/vcredist_x86.exe ?>\r
-<?define vcredist_x64 =  http://download.microsoft.com/download/d/d/9/dd9a82d0-52ef-40db-8dab-795376989c03/vcredist_x64.exe ? -->\r
-<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"\r
-     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">\r
-  <Fragment>\r
-       <!-- TODO: Put your code here. -->\r
-    <util:RegistrySearch Root="HKLM" Key="SOFTWARE\Microsoft\VisualStudio\10.0\VC\VCRedist\x86" Value="Installed" Variable="vc100_redist_x86" />\r
-    <util:RegistrySearch Root="HKLM" Key="SOFTWARE\Microsoft\VisualStudio\10.0\VC\VCRedist\x64" Value="Installed" Variable="vc100_redist_x64" Win64="yes"/>\r
-    <PackageGroup Id="vcredist">\r
-      <ExePackage Id="vc100_redist_x86"\r
-        Cache="no"\r
-        Compressed="yes"\r
-        PerMachine="yes"\r
-        Permanent="yes"\r
-        Vital="yes"\r
-        Name="Redist\vc100_redist_x86.exe"\r
-        SourceFile="vc100_redist_x86.exe"\r
-        InstallCommand="/q"\r
-        DetectCondition="vc100_redist_x86 AND (vc100_redist_x86 &gt;= 1)">\r
-        <ExitCode Value ="3010" Behavior="forceReboot" />\r
-      </ExePackage>\r
-      <ExePackage Id="vc100_redist_x64"\r
-        Cache="no"\r
-        Compressed="yes"\r
-        PerMachine="yes"\r
-        Permanent="yes"\r
-        Vital="yes"\r
-        Name="Redist\vc100_redist_x64.exe"\r
-        SourceFile="vc100_redist_x64.exe"\r
-        InstallCommand="/q"\r
-        InstallCondition="VersionNT64"\r
-        DetectCondition="vc100_redist_x64 AND (vc100_redist_x64 &gt;= 1)">\r
-        <ExitCode Value ="3010" Behavior="forceReboot" />\r
-      </ExePackage>\r
-    </PackageGroup>\r
-  </Fragment>\r
-</Wix>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<?ifndef VCVER?>
+<?define VCVER = 14?>
+<?endif?>
+<!-- ?define vcredist_x86 =  http://download.microsoft.com/download/d/d/9/dd9a82d0-52ef-40db-8dab-795376989c03/vcredist_x86.exe ?>
+<?define vcredist_x64 =  http://download.microsoft.com/download/d/d/9/dd9a82d0-52ef-40db-8dab-795376989c03/vcredist_x64.exe ? -->
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
+     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
+  <Fragment>
+       <!-- TODO: Put your code here. -->
+    <util:RegistrySearch Root="HKLM" Key="SOFTWARE\Microsoft\VisualStudio\$(var.VCVER).0\VC\VCRedist\x86" Value="Installed" Variable="vc$(var.VCVER)0_redist_x86" />
+    <util:RegistrySearch Root="HKLM" Key="SOFTWARE\Microsoft\VisualStudio\$(var.VCVER).0\VC\VCRedist\x64" Value="Installed" Variable="vc$(var.VCVER)0_redist_x64" Win64="yes"/>
+    <PackageGroup Id="vcredist">
+      <ExePackage Id="vc$(var.VCVER)0_redist_x86"
+        Cache="no"
+        Compressed="yes"
+        PerMachine="yes"
+        Permanent="yes"
+        Vital="yes"
+        Name="vc$(var.VCVER)0_redist_x86.exe"
+        SourceFile="Redist\vc$(var.VCVER)0_redist_x86.exe"
+        InstallCommand="/q"
+        DetectCondition="vc$(var.VCVER)0_redist_x86 AND (vc$(var.VCVER)0_redist_x86 &gt;= 1)">
+        <ExitCode Value ="3010" Behavior="forceReboot" />
+      </ExePackage>
+      <ExePackage Id="vc$(var.VCVER)0_redist_x64"
+        Cache="no"
+        Compressed="yes"
+        PerMachine="yes"
+        Permanent="yes"
+        Vital="yes"
+        Name="vc$(var.VCVER)0_redist_x64.exe"
+        SourceFile="Redist\vc$(var.VCVER)0_redist_x64.exe"
+        InstallCommand="/q"
+        InstallCondition="VersionNT64"
+        DetectCondition="vc$(var.VCVER)0_redist_x64 AND (vc$(var.VCVER)0_redist_x64 &gt;= 1)">
+        <ExitCode Value ="3010" Behavior="forceReboot" />
+      </ExePackage>
+    </PackageGroup>
+  </Fragment>
+</Wix>