Skip to content

Commit

Permalink
generate stable Guids for files in lib.wxs to fix MSI issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jay0lee committed Oct 16, 2024
1 parent 090b593 commit ae95c8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ jobs:
export MSI_FILENAME="${GITHUB_WORKSPACE}/gam-${GAMVERSION}-windows-${GAM_ARCHIVE_ARCH}.msi"
# auto-generate a lib.wxs based on the files PyInstaller created for the lib/ directory
/c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.14/bin/heat.exe dir "${gampath}/lib" -ke -srd -cg Lib -gg -dr lib -directoryid lib -out lib-fixme.wxs
sed 's/Guid=\".*\"/Guid="*"/g' lib-fixme.wxs > lib.wxs
$python tools/gen-wix-xml-filelist.py lib.wxs
echo "-- begin lib.wxs --"
cat lib.wxs
echo "-- end lib.wxs --"
Expand Down
73 changes: 19 additions & 54 deletions src/tools/gen-wix-xml-filelist.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
import os
import sys
import uuid
from lxml import etree
import sys

source_dir = sys.argv[1]
template_file = sys.argv[2]
target_file = sys.argv[3]

existing_components = {
'gam.exe': ''' <Component Id="gam_exe" Guid="d046ea24-c9f8-40ca-84db-70b0119933ff">
<File Name="gam.exe" KeyPath="yes" />
<Environment Id="PATH" Name="PATH" Value="[INSTALLFOLDER]" Permanent="yes" Part="last" Action="set" System="yes" />
</Component>
''',
'LICENSE': ''' <Component Id="license" Guid="c76864c5-d005-44d5-bb7c-a27e5923792d">
<File Name="LICENSE" KeyPath="yes" />
</Component>
''',
'gam-setup.bat': ''' <Component Id="gam_setup_bat" Guid="5e6bbacb-d86f-4d80-a10b-89b81ee63fcb">
<File Name="gam-setup.bat" KeyPath="yes" />
</Component>
''',
'GamCommands.txt': ''' <Component Id="GamCommands_txt" Guid="a2dca862-b222-469e-a637-95ea2a1c53e7">
<File Name="GamCommands.txt" KeyPath="yes" />
</Component>
''',
'GamUpdate.txt': ''' <Component Id="GamUpdate_txt" Guid="1b7cdd48-0fff-4943-a219-102fcd14c755">
<File Name="GamUpdate.txt" KeyPath="yes" />
</Component>
''',
'cacerts.pem': ''' <Component Id="cacerts_pem" Guid="61fe2b2d-1646-4bed-b844-193965e97727">
<File Name="cacerts.pem" KeyPath="yes" />
</Component>
''',
}

component_xml = ''
all_files = []
for root, dirs, files in os.walk(source_dir):
for filename in files:
relpath = os.path.relpath(root, source_dir)
if relpath == '.':
all_files.append(filename)
else:
all_files.append(os.path.join(relpath, filename))
all_files.sort()
for filename in all_files:
component_xml += existing_components.get(filename,
f' <Component>\n <File Name="{filename}" KeyPath="yes"/>\n </Component>\n')

with open(template_file, 'r') as f:
template = f.read()

full_xml = template.replace('REPLACE_ME_WITH_FILE_COMPONENTS', component_xml)
# Hacky solution to create a Guid for all files
# so Wix is happy and Guid is stable every time.
# uuid5 is used for the Guid and the input is the
# source filename so the Guid will be the same
# every time as long as the source file name is
# the same.

with open(target_file, 'w') as f:
f.write(full_xml)
rewrite_file = sys.argv[1]

with open(rewrite_file, 'rb') as f:
input_xml = f.read()
root = etree.fromstring(input_xml)
for elem in root.getiterator():
if 'Guid' in elem.attrib:
source = elem.getchildren()[0].attrib['Source']
stable_uuid = str(uuid.uuid5(uuid.NAMESPACE_URL, source))
elem.attrib['Guid'] = stable_uuid
with open(rewrite_file, 'w') as f:
f.write(etree.tostring(root).decode())

0 comments on commit ae95c8f

Please sign in to comment.