From 7da471177faa4a84ba06ad849ebd03622029a288 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Mon, 14 Oct 2024 16:05:02 +0200 Subject: [PATCH] Use WiX 5 (#66) * Make product code automatically random Instead of externally generating it and using it explicitly. * Componentize the merge module This prevents upgrades from leaving files from the previous version behind that are not in the new version. * Configure drivers on x64 The Way It Should Be Done Use the ODBCDriver element only, without additional Registry settings. This works, although it does not solve the file name issue and therefore still requires removing the short file names from the File table. It also works for installing the x86 driver on an x64 system. Whether it works on an x86 system remains unknown. * Configure drivers on x86 In The Exact Same Way Tested on Windows 10 x86; the driver installs correctly and works at first glance (in Access, to be precise). Registry and file system look good. The comment saying it "probably would be safe" is probably correct. * Use candle's -arch option to select build platform According to docs, using Package/@Platform "is discouraged". The -arch option also provides the default bitness for components, making the Component/@Win64 attribute unnecessary in single-architecture packages. * Reindent * Save some attributes * Replace upgrade logic with MajorUpgrade element This element compiles into approximately the same entries in the Upgrade, CustomAction, and InstallExecuteSequence tables. * Remove unused GUID I think this was the product code, a long time ago. * Make MSI file smaller By about 20 percent. * Better select where to remove short file names Use the FileName column itself instead of the file ID. This is less susceptible to changes in file IDs (and component IDs) that may happen when relying more on default behaviors in future WiX versions. * Build with WiX 5 This is a preview. It appears to build a working x64 installer; I have tested nothing else yet. * Clean up modify_msi.vbs Also, put blame where it belongs, which is Windows Installer. If this was a bug in WiX, then the fix would be to enforce 8.3 file names for ODBC drivers, and we wouldn't like that very much either, would we? * Increase WiX-5-ness - Remove most Component elements in favor of naked files - Replace PGFOLDER variable with ProgramFiles6432Folder The Condition element on Component has become an attribute in WiX 5, and the combination of preprocessor and component condition (i.e. include a non-x64 condition only in a non-x64 package) to install PGXA only from a package native to the underlying OS does not work anymore. Replace it with a pure component condition that includes the package architecture. The Template summary property has this information already, but it is not available from within the installation, and I'm not about to start writing custom actions. * Update build workflow for WiX 5 --- .github/workflows/main.yml | 6 + installer/README.txt | 12 +- installer/buildInstallers.ps1 | 21 +-- installer/modify_msi.vbs | 54 ++++---- installer/psqlodbc_cpu.wxs | 173 ++++++++++--------------- installer/psqlodbcm_cpu.wxs | 234 +++++++++++++--------------------- 6 files changed, 200 insertions(+), 300 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ca452049..8d3db77b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -275,6 +275,12 @@ jobs: with: arch: x86 + - name: Install WiX + shell: cmd + run: | + dotnet tool install --global wix + wix extension add --global WixToolset.UI.wixext + - name: build psqlodbc standard shell: powershell working-directory: psqlodbc diff --git a/installer/README.txt b/installer/README.txt index 3a1b1872..ffaaee4e 100644 --- a/installer/README.txt +++ b/installer/README.txt @@ -1,11 +1,15 @@ This directory contains the psqlODBC installer for Windows. To build the -installer, you will need a copy of WiX installed somewhere in your system -path. The installer has been tested with WiX version 3.0.2420 and WiX 3.8 at -the time writing. +installer, you will need a copy of WiX installed. The installer has been +tested with WiX version 5.0.2 at the time of writing. WiX may be downloaded from: - http://wix.codeplex.com/ + http://wixtoolset.org/ + +In addition to the base package, the UI extension is required: + + dotnet tool install --global wix + wix extension add --global WixToolset.UI.wixext HOW TO BUILD diff --git a/installer/buildInstallers.ps1 b/installer/buildInstallers.ps1 index 6373db61..20e15ef0 100644 --- a/installer/buildInstallers.ps1 +++ b/installer/buildInstallers.ps1 @@ -256,46 +256,31 @@ function buildInstaller([string]$CPUTYPE) [string []]$libpqRelArgs=@() for ($i=0; $i -lt $maxmem; $i++) { - $libpqRelArgs += ("-dLIBPQMEM$i=" + $libpqmem[$i]) + $libpqRelArgs += "-d", ("LIBPQMEM$i=" + $libpqmem[$i]) } if (-not(Test-Path -Path $CPUTYPE)) { New-Item -ItemType directory -Path $CPUTYPE | Out-Null } - $PRODUCTCODE = [GUID]::NewGuid() - Write-Host "PRODUCTCODE: $PRODUCTCODE" - try { pushd "$scriptPath" Write-Host ".`nBuilding psqlODBC/$SUBLOC merge module..." $BINBASE = GetObjbase ".." $INSTBASE = GetObjbase ".\$CPUTYPE" "installer\$CPUTYPE" - candle -nologo $libpqRelArgs "-dPlatform=$CPUTYPE" "-dVERSION=$VERSION" "-dSUBLOC=$SUBLOC" "-dLIBPQBINDIR=$LIBPQBINDIR" "-dLIBPQMSVCDLL=$LIBPQMSVCDLL" "-dLIBPQMSVCSYS=$LIBPQMSVCSYS" "-dPODBCMSVCDLL=$PODBCMSVCDLL" "-dPODBCMSVPDLL=$PODBCMSVPDLL" "-dPODBCMSVCSYS=$PODBCMSVCSYS" "-dPODBCMSVPSYS=$PODBCMSVPSYS" "-dNoPDB=$NoPDB" "-dBINBASE=$BINBASE" -o $INSTBASE\psqlodbcm.wixobj psqlodbcm_cpu.wxs + wix build --nologo -arch $CPUTYPE $libpqRelArgs -d "VERSION=$VERSION" -d "SUBLOC=$SUBLOC" -d "LIBPQBINDIR=$LIBPQBINDIR" -d "LIBPQMSVCDLL=$LIBPQMSVCDLL" -d "LIBPQMSVCSYS=$LIBPQMSVCSYS" -d "PODBCMSVCDLL=$PODBCMSVCDLL" -d "PODBCMSVPDLL=$PODBCMSVPDLL" -d "PODBCMSVCSYS=$PODBCMSVCSYS" -d "PODBCMSVPSYS=$PODBCMSVPSYS" -d "NoPDB=$NoPDB" -d "BINBASE=$BINBASE" -o $INSTBASE\psqlodbc_$CPUTYPE.msm psqlodbcm_cpu.wxs if ($LASTEXITCODE -ne 0) { throw "Failed to build merge module" } - Write-Host ".`nLinking psqlODBC merge module..." - light -sval -nologo -o $INSTBASE\psqlodbc_$CPUTYPE.msm $INSTBASE\psqlodbcm.wixobj - if ($LASTEXITCODE -ne 0) { - throw "Failed to link merge module" - } - Write-Host ".`nBuilding psqlODBC installer database..." - candle -nologo "-dPlatform=$CPUTYPE" "-dVERSION=$VERSION" "-dSUBLOC=$SUBLOC" "-dPRODUCTCODE=$PRODUCTCODE" "-dINSTBASE=$INSTBASE" -o $INSTBASE\psqlodbc.wixobj psqlodbc_cpu.wxs + wix build --nologo -arch $CPUTYPE -ext WixToolset.UI.wixext -d "VERSION=$VERSION" -d "SUBLOC=$SUBLOC" -d "INSTBASE=$INSTBASE" -o $INSTBASE\psqlodbc_$CPUTYPE.msi psqlodbc_cpu.wxs if ($LASTEXITCODE -ne 0) { throw "Failed to build installer database" } - Write-Host ".`nLinking psqlODBC installer database..." - light -sval -nologo -ext WixUIExtension -cultures:en-us -o $INSTBASE\psqlodbc_$CPUTYPE.msi $INSTBASE\psqlodbc.wixobj - if ($LASTEXITCODE -ne 0) { - throw "Failed to link installer database" - } - Write-Host ".`nModifying psqlODBC installer database..." cscript modify_msi.vbs $INSTBASE\psqlodbc_$CPUTYPE.msi if ($LASTEXITCODE -ne 0) { diff --git a/installer/modify_msi.vbs b/installer/modify_msi.vbs index c1353fc8..8934411c 100755 --- a/installer/modify_msi.vbs +++ b/installer/modify_msi.vbs @@ -2,7 +2,7 @@ ' When the dll name of the driver is not of 8.3-format ' the modification of the FileName is needed ' -' This is to work-around a bug in the WiX Toolset, see +' This is to work-around an oversight in Windows Installer, see ' http://wixtoolset.org/issues/1422/ ' ' We remove the short name from the filename field in the File-table @@ -10,45 +10,43 @@ ' speaking, that makes the contents of the table invalid, because a short ' name is mandatory, but Windows Installer seems nevertheless install it ' just fine. -' -option Explicit -Const msiOpenDatabaseModeTransact = 1 +Option Explicit +Const msiOpenDatabaseModeTransact = 1 Const msiViewModifyInsert = 1 Const msiViewModifyUpdate = 2 +Const query = "SELECT * FROM File" -Dim msiPath : msiPath = Wscript.Arguments(0) +Dim installer, database +Dim view, record +Dim pos, filename -Dim installer Set installer = Wscript.CreateObject("WindowsInstaller.Installer") -Dim database -Set database = installer.OpenDatabase(msiPath, msiOpenDatabaseModeTransact) - -Dim query -query = "Select * FROM File" -Dim view +Set database = installer.OpenDatabase(WScript.Arguments(0), _ + msiOpenDatabaseModeTransact) Set view = database.OpenView(query) view.Execute -Dim record + Set record = view.Fetch -Dim gFile, pos -Do While not record Is Nothing -gFile = record.StringData(1) -If Left(gFile, 8) = "psqlodbc" Then - gFile = record.StringData(3) - ' Check if the FileName field is ShortName|LongName - pos = InStr(record.StringData(3), "|") - If pos > 0 Then - ' Omit the ShortName part - gFile = Mid(record.StringData(3), pos + 1) - WScript.echo record.StringData(3) & " -> " & gFile - ' And update the field - record.StringData(3) = gFile +Do While Not record Is Nothing + + filename = record.StringData(3) + pos = InStr(filename, "|psqlodbc") + + If (pos > 0) Then + + ' Remove the ShortName part + filename = Mid(filename, pos + 1) + WScript.echo record.StringData(3) & " -> " & filename + + record.StringData(3) = filename view.Modify msiViewModifyUpdate, record + End If -End If -Set record = view.Fetch + + Set record = view.Fetch + Loop database.Commit diff --git a/installer/psqlodbc_cpu.wxs b/installer/psqlodbc_cpu.wxs index b49b92c1..60075cfd 100644 --- a/installer/psqlodbc_cpu.wxs +++ b/installer/psqlodbc_cpu.wxs @@ -1,107 +1,92 @@ - + - - - - - - - - - - - - - - + + - - - - + + - - - + + + + + + - + - - + Comments="PostgreSQL ODBC Driver" /> - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - + + + + + + + + + + + + + - + + + + + + + + + - + @@ -113,47 +98,19 @@ - - - - - $(var.ALLUSERS) - + - - - - + + + + - - - - - - - - - - - - - SELFFOUND AND NOT Installed - NEWERFOUND AND NOT Installed - REINSTALLMODE AND NOT Installed - UPGRADEFOUND AND REINSTALLMODE - UPGRADEFOUND AND NOT Installed - - - + + + + \ No newline at end of file diff --git a/installer/psqlodbcm_cpu.wxs b/installer/psqlodbcm_cpu.wxs index 1edbf1e4..f2cd82ea 100644 --- a/installer/psqlodbcm_cpu.wxs +++ b/installer/psqlodbcm_cpu.wxs @@ -1,194 +1,144 @@ - - - - - - - - - - + - - + + + - - - + + - - + + - + Codepage="1252" /> - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + - - - + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + \ No newline at end of file