Get rid of copy and paste code in installer/ and unify them.
authorHiroshi Inoue <inoue@tpf.co.jp>
Tue, 12 Aug 2014 04:28:16 +0000 (13:28 +0900)
committerHiroshi Inoue <inoue@tpf.co.jp>
Tue, 19 Aug 2014 02:09:46 +0000 (11:09 +0900)
The powershell scripts had lots of duplication. Make the unified
code instead.
Original patch was provided by Craig Ringer.

installer/buildInstallers.ps1 [new file with mode: 0644]
installer/buildX64-installer.ps1 [deleted file]
installer/buildX86-installer.ps1 [deleted file]

diff --git a/installer/buildInstallers.ps1 b/installer/buildInstallers.ps1
new file mode 100644 (file)
index 0000000..187c840
--- /dev/null
@@ -0,0 +1,189 @@
+<#
+.SYNOPSIS
+    Build all installers of psqlodbc project.
+.DESCRIPTION
+    Build psqlodbc_x86.msi(msm), psqlodbc_x64.msi(msm).
+.PARAMETER cpu
+    Specify build cpu type, "both"(default), "x86" or "x64" is
+    available.
+.PARAMETER BuildBinaries
+    Specify wherther build binary dlls or not, $FALSE(default) or $TRUE is
+    available.
+.PARAMETER BuildConfigPath
+    Specify the configuration xml file name if you want to use
+    the configuration file other than standard one.
+    The relative path is relative to the current directory.
+.EXAMPLE
+    > .\buildInstallers
+   Build 32bit and 64bit installers.
+.EXAMPLE
+    > .\buildInstallers x86
+   Build 32bit installers.
+.NOTES
+    Author: Hiroshi Inoue
+    Date:   July 4, 2014
+#>
+#  build 32bit and/or 64bit installers
+#
+Param(
+[ValidateSet("x86", "x64", "both")]
+[string]$cpu="both",
+[Boolean]$BuildBinaries=$FALSE,
+[string]$BuildConfigPath
+)
+
+function buildInstaller($CPUTYPE)
+{
+   $VERSION = $configInfo.Configuration.version
+
+   $archinfo = $configInfo.Configuration.$CPUTYPE
+
+   $LIBPQVER=$archinfo.libpq.version
+   if ($LIBPQVER -eq "") {
+       $LIBPQVER=$LIBPQ_VERSION
+   }
+
+   $USE_LIBPQ=$archinfo.use_libpq
+
+   if ($CPUTYPE -eq "x64")
+   {
+       if ($USE_LIBPQ -eq "yes")
+       {
+           $LIBPQBINDIR=$archinfo.libpq.bin
+           if ($LIBPQBINDIR -eq "default") {
+               if ($env:PROCESSOR_ARCHITECTURE -ne "x86") {
+                   $pgmfs = "$env:ProgramFiles"
+                   $LIBPQBINDIR = "$pgmfs\PostgreSQL\$LIBPQVER\bin"
+               }
+               elseif ("${env:ProgramW6432}" -ne "") {
+                   $pgmfs = "$env:ProgramW6432"
+                   $LIBPQBINDIR = "$pgmfs\PostgreSQL\$LIBPQVER\bin"
+               }
+           }
+       }
+   
+   }
+   elseif ($CPUTYPE -eq "x86")
+   {
+       if ($USE_LIBPQ -eq "yes")
+       {
+           $LIBPQBINDIR=$archinfo.libpq.bin
+           if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
+               $pgmfs = "$env:ProgramFiles"
+           } else {
+               $pgmfs = "${env:ProgramFiles(x86)}"
+           }
+           if ($LIBPQBINDIR -eq "default") {
+               $LIBPQBINDIR = "$pgmfs\PostgreSQL\$LIBPQVER\bin"
+           }
+       }
+
+   }
+   else
+   {
+       throw "Unknown CPU type $CPUTYPE";
+   }
+
+   $USE_SSPI=$archinfo.use_sspi
+
+   $USE_GSS=$archinfo.use_gss
+   if ($USE_GSS -eq "yes")
+   {
+       $GSSBINDIR=$archinfo.gss.bin
+   }
+
+   Write-Host "CPUTYPE    : $CPUTYPE"
+   Write-Host "VERSION    : $VERSION"
+   Write-Host "USE LIBPQ  : $USE_LIBPQ ($LIBPQBINDIR)"
+   Write-Host "USE GSS    : $USE_GSS ($GSSBINDIR)"
+   Write-Host "USE SSPI   : $USE_SSPI"
+
+   if ($env:WIX -ne "")
+   {
+       $wix = "$env:WIX"
+       $env:Path += ";$WIX/bin"
+   }
+   # The subdirectory to install into
+   $SUBLOC=$VERSION.substring(0, 2) + $VERSION.substring(3, 2)
+
+   if (-not(Test-Path -Path $CPUTYPE)) {
+           New-Item -ItemType directory -Path $CPUTYPE
+   }
+
+   $PRODUCTCODE = [GUID]::NewGuid();
+   Write-Host "PRODUCTCODE: $PRODUCTCODE"
+
+   try {
+       pushd "$scriptPath"
+
+       Write-Host ".`nBuilding psqlODBC/$SUBLOC merge module..."
+
+       invoke-expression "candle -nologo -dPlatform=$CPUTYPE `"-dVERSION=$VERSION`" -dSUBLOC=$SUBLOC `"-dLIBPQBINDIR=$LIBPQBINDIR`" `"-dGSSBINDIR=$GSSBINDIR`" -o $CPUTYPE\psqlodbcm.wixobj psqlodbcm_cpu.wxs"
+       if ($LASTEXITCODE -ne 0) {
+           throw "Failed to build merge module"
+       }
+
+       Write-Host ".`nLinking psqlODBC merge module..."
+       invoke-expression "light -nologo -o $CPUTYPE\psqlodbc_$CPUTYPE.msm $CPUTYPE\psqlodbcm.wixobj"
+       if ($LASTEXITCODE -ne 0) {
+           throw "Failed to link merge module"
+       }
+
+       Write-Host ".`nBuilding psqlODBC installer database..."
+
+       invoke-expression "candle -nologo -dPlatform=$CPUTYPE `"-dVERSION=$VERSION`" -dSUBLOC=$SUBLOC `"-dPRODUCTCODE=$PRODUCTCODE`" -o $CPUTYPE\psqlodbc.wixobj psqlodbc_cpu.wxs"
+       if ($LASTEXITCODE -ne 0) {
+           throw "Failed to build installer database"
+       }
+
+       Write-Host ".`nLinking psqlODBC installer database..."
+       invoke-expression "light -nologo -ext WixUIExtension -cultures:en-us -o $CPUTYPE\psqlodbc_$CPUTYPE.msi $CPUTYPE\psqlodbc.wixobj"
+       if ($LASTEXITCODE -ne 0) {
+           throw "Failed to link installer database"
+       }
+
+       Write-Host ".`nModifying psqlODBC installer database..."
+       invoke-expression "cscript modify_msi.vbs $CPUTYPE\psqlodbc_$CPUTYPE.msi"
+       if ($LASTEXITCODE -ne 0) {
+           throw "Failed to modify installer database"
+       }
+
+       Write-Host ".`nDone!"
+   }
+   catch [Exception] {
+       Write-Host ".`Aborting build!"
+       throw $error[0]
+   }
+   finally {
+       popd
+   }
+}
+
+$scriptPath = (Split-Path $MyInvocation.MyCommand.Path)
+$configInfo = & "$scriptPath\..\winbuild\configuration.ps1" "$BuildConfigPath"
+
+if ($BuildBinaries) {
+   try {
+       pushd "$scriptpath"
+       $platform = $cpu
+       if ($cpu -eq "x86") {
+           $platform = "win32"
+       }
+       invoke-expression "..\winbuild\BuildAll.ps1 -Platform $platform -BuildConfigPath `"$BuildConfigPath`"" -ErrorAction Stop
+       if ($LASTEXITCODE -ne 0) {
+           throw "Failed to build binaries"
+       }
+   } catch [Exception] {
+       throw $error[0]
+   } finally {
+       popd
+   } 
+}
+
+if ($cpu -eq "both") {
+   buildInstaller "x86"
+   buildInstaller "x64"
+}
+else {
+   buildInstaller $cpu
+}
diff --git a/installer/buildX64-installer.ps1 b/installer/buildX64-installer.ps1
deleted file mode 100755 (executable)
index 1a325c1..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#  build 64bit installer
-Param(
-[string]$configPath
-)
-$scriptPath = (Split-Path $MyInvocation.MyCommand.Path)
-$configInfo = & "$scriptPath\..\winbuild\configuration.ps1" "$configPath"
-$VERSION = $configInfo.Configuration.version
-$x64info = $configInfo.Configuration.x64
-$USE_LIBPQ=$x64info.use_libpq
-$USE_GSS=$x64info.use_gss
-$USE_SSPI=$x64info.use_sspi
-$LIBPQVER=$x64info.libpq.version
-if ($LIBPQVER -eq "") {
-   $LIBPQVER=$LIBPQ_VERSION
-}
-if ($USE_LIBPQ -eq "yes")
-{
-   $LIBPQBINDIR=$x64info.libpq.bin
-   if ($LIBPQBINDIR -eq "default") {
-       if ($env:PROCESSOR_ARCHITECTURE -ne "x86") {
-           $pgmfs = "$env:ProgramFiles"
-           $LIBPQBINDIR = "$pgmfs\PostgreSQL\$LIBPQVER\bin"
-       }
-       elseif ("${env:ProgramW6432}" -ne "") {
-           $pgmfs = "$env:ProgramW6432"
-           $LIBPQBINDIR = "$pgmfs\PostgreSQL\$LIBPQVER\bin"
-       }
-   }
-}
-if ($USE_GSS -eq "yes")
-{
-   $GSSBINDIR=$x64info.gss.bin
-}
-
-Write-Host "VERSION    : $VERSION"
-Write-Host "USE LIBPQ  : $USE_LIBPQ ($LIBPQBINDIR)"
-Write-Host "USE GSS    : $USE_GSS ($GSSBINDIR)"
-Write-Host "USE SSPI   : $USE_SSPI"
-
-$CPUTYPE="x64"
-
-if ($env:WIX -ne "")
-{
-   $wix = "$env:WIX"
-   $env:Path += ";$WIX/bin"
-}
-# The subdirectory to install into
-$SUBLOC=$VERSION.substring(0, 2) + $VERSION.substring(3, 2)
-
-if (!(Test-Path -Path $CPUTYPE)) {
-    New-Item -ItemType directory -Path $CPUTYPE
-}
-
-<#
-   ProductCode History
-       ProductCode must be changed in case of major upgrade
-#>
-$PRODUCTID = @{}
-$PRODUCTID["09.02.0100"]="3E42F836-9204-4c42-B3C3-8680A0434875"
-$PRODUCTID["09.03.0100"]="1F896F2F-5756-4d22-B5A3-040796C9B485"
-$PRODUCTID["09.03.0200"]="1F896F2F-5756-4d22-B5A3-040796C9B485"
-$PRODUCTID["09.03.0210"]="1F896F2F-5756-4d22-B5A3-040796C9B485"
-$PRODUCTID["09.03.0300"]="1F896F2F-5756-4d22-B5A3-040796C9B485"
-
-$PRODUCTCODE=$PRODUCTID[$VERSION]
-if ("$PRODUCTCODE" -eq "") {
-   Write-Host "`nSpecify the ProductCode for the VERSION $VERSION"
-   return
-}
-Write-Host "PRODUCTCODE: $PRODUCTCODE"
-
-try {
-   pushd $scriptPath
-
-   Write-Host ".`nBuilding psqlODBC/$SUBLOC merge module..."
-
-   invoke-expression "candle -nologo -dPlatform=$CPUTYPE `"-dVERSION=$VERSION`" -dSUBLOC=$SUBLOC `"-dLIBPQBINDIR=$LIBPQBINDIR`" `"-dGSSBINDIR=$GSSBINDIR`" -o $CPUTYPE\psqlodbcm.wixobj psqlodbcm_cpu.wxs"
-
-   Write-Host ".`nLinking psqlODBC merge module..."
-   invoke-expression "light -nologo -o $CPUTYPE\psqlodbc_$CPUTYPE.msm $CPUTYPE\psqlodbcm.wixobj"
-
-   Write-Host ".`nBuilding psqlODBC installer database..."
-
-   invoke-expression "candle -nologo -dPlatform=$CPUTYPE `"-dVERSION=$VERSION`" -dSUBLOC=$SUBLOC `"-dPRODUCTCODE=$PRODUCTCODE`" -o $CPUTYPE\psqlodbc.wixobj psqlodbc_cpu.wxs"
-
-   Write-Host ".`nLinking psqlODBC installer database..."
-   invoke-expression "light -nologo -ext WixUIExtension -cultures:en-us -o $CPUTYPE\psqlodbc_$CPUTYPE.msi $CPUTYPE\psqlodbc.wixobj"
-
-   Write-Host ".`nModifying psqlODBC installer database..."
-   invoke-expression "cscript modify_msi.vbs $CPUTYPE\psqlodbc_$CPUTYPE.msi"
-
-   Write-Host ".`nDone!"
-}
-catch {
-   Write-Host ".`Aborting build!"
-   throw $error[0]
-}
-finally {
-   popd
-}
diff --git a/installer/buildX86-installer.ps1 b/installer/buildX86-installer.ps1
deleted file mode 100755 (executable)
index 1b3031a..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#  build 32bit installer
-Param(
-[string]$configPath
-)
-$scriptPath = (Split-Path $MyInvocation.MyCommand.Path)
-$configInfo = & "$scriptPath\..\winbuild\configuration.ps1" "$configPath"
-$VERSION = $configInfo.Configuration.version
-$x86info = $configInfo.Configuration.x86
-$USE_LIBPQ=$x86info.use_libpq
-$USE_GSS=$x86info.use_gss
-$USE_SSPI=$x86info.use_sspi
-$LIBPQVER=$x86info.libpq.version
-if ($LIBPQVER -eq "") {
-   $LIBPQVER=$LIBPQ_VERSION
-}
-if ($USE_LIBPQ -eq "yes")
-{
-   $LIBPQBINDIR=$x86info.libpq.bin
-   if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
-       $pgmfs = "$env:ProgramFiles"
-   } else {
-       $pgmfs = "${env:ProgramFiles(x86)}"
-   }
-   if ($LIBPQBINDIR -eq "default") {
-       $LIBPQBINDIR = "$pgmfs\PostgreSQL\$LIBPQVER\bin"
-   }
-}
-
-Write-Host "VERSION    : $VERSION"
-Write-Host "USE LIBPQ  : $USE_LIBPQ ($LIBPQBINDIR)"
-Write-Host "USE GSS    : $USE_GSS ($GSSBINDIR)"
-Write-Host "USE SSPI   : $USE_SSPI"
-
-$CPUTYPE="x86"
-
-if ($env:WIX -ne "")
-{
-   $wix = "$env:WIX"
-   $env:Path += ";$WIX/bin"
-}
-
-<#
-   The ProductCode History
-       ProductCode must be changed in case of major upgrade
-#>
-$PRODUCTID = @{}
-$PRODUCTID["09.02.0100"]="838E187D-8B7A-473d-B93C-C8E970B15D2B"
-$PRODUCTID["09.03.0100"]="D3527FA5-9C2B-4550-A59B-9534A78950F4"
-$PRODUCTID["09.03.0200"]="D3527FA5-9C2B-4550-A59B-9534A78950F4"
-$PRODUCTID["09.03.0210"]="D3527FA5-9C2B-4550-A59B-9534A78950F4"
-$PRODUCTID["09.03.0300"]="D3527FA5-9C2B-4550-A59B-9534A78950F4"
-$PRODUCTID["09.03.0400"]="D3527FA5-9C2B-4550-A59B-9534A78950F4"
-
-# The subdirectory to install into
-$SUBLOC=$VERSION.substring(0, 2) + $VERSION.substring(3, 2)
-
-$PRODUCTCODE=$PRODUCTID[$VERSION]
-if ("$PRODUCTCODE" -eq "") {
-   Write-Host ".`nSpecify the ProductCode for the VERSION $VERSION"
-   return
-}
-Write-Host "PRODUCTCODE: $PRODUCTCODE"
-
-try {
-   pushd $scroptPath
-
-   Write-Host ".`nBuilding psqlODBC/$SUBLOC merge module..."
-
-   invoke-expression "candle -nologo -dPlatform=`"x86`" `"-dVERSION=$VERSION`" -dSUBLOC=$SUBLOC `"-dLIBPQBINDIR=$LIBPQBINDIR`" -o $CPUTYPE\psqlodbcm.wixobj psqlodbcm_cpu.wxs"
-
-   invoke-expression "light -nologo -out $CPUTYPE\psqlodbc_$CPUTYPE.msm $CPUTYPE\psqlodbcm.wixobj"
-
-   Write-Host ".`nBuilding psqlODBC installer database..."
-
-   invoke-expression "candle -nologo -dPlatform=`"x86`" `"-dVERSION=$VERSION`" -dSUBLOC=$SUBLOC `"-dPRODUCTCODE=$PRODUCTCODE`" -o $CPUTYPE\psqlodbc.wixobj psqlodbc_cpu.wxs"
-
-   invoke-expression "light -nologo -ext WixUIExtension -cultures:en-us -o $CPUTYPE\psqlodbc_$CPUTYPE.msi $CPUTYPE\psqlodbc.wixobj"
-
-   Write-Host ".`nDone!"
-}
-catch {
-   Write-Host ".`nAborting build!"
-   throw $error[0]
-}
-finally {
-   popd
-}