Upgrade MSI builder from WiX3 to WiX 4.

pull/12058/head
Jussi Pakkanen 1 year ago
parent 7c955618dd
commit b4c9269dab
  1. 98
      packaging/createmsi.py

@ -31,7 +31,7 @@ sys.path.append(os.getcwd())
from mesonbuild import coredata from mesonbuild import coredata
# Elementtree does not support CDATA. So hack it. # Elementtree does not support CDATA. So hack it.
WINVER_CHECK = '<![CDATA[Installed OR (VersionNT64 > 602)]]>' WINVER_CHECK = 'Installed OR (VersionNT64 &gt; 602)>'
def gen_guid(): def gen_guid():
''' '''
@ -102,7 +102,7 @@ class PackageGenerator:
'Title': 'Meson', 'Title': 'Meson',
'Description': 'Meson executables', 'Description': 'Meson executables',
'Level': '1', 'Level': '1',
'Absent': 'disallow', 'AllowAbsent': 'no',
}, },
self.staging_dirs[1]: { self.staging_dirs[1]: {
'Id': 'NinjaProgram', 'Id': 'NinjaProgram',
@ -160,49 +160,44 @@ class PackageGenerator:
''' '''
Generate package files for MSI installer package Generate package files for MSI installer package
''' '''
self.root = ET.Element('Wix', {'xmlns': 'http://schemas.microsoft.com/wix/2006/wi'}) self.root = ET.Element('Wix', {
product = ET.SubElement(self.root, 'Product', { 'xmlns': 'http://wixtoolset.org/schemas/v4/wxs',
'xmlns:ui': 'http://wixtoolset.org/schemas/v4/wxs/ui'
})
package = ET.SubElement(self.root, 'Package', {
'Name': self.product_name, 'Name': self.product_name,
'Manufacturer': 'The Meson Development Team', 'Manufacturer': 'The Meson Development Team',
'Id': self.guid,
'UpgradeCode': self.update_guid, 'UpgradeCode': self.update_guid,
'Language': '1033', 'Language': '1033',
'Codepage': '1252', 'Codepage': '1252',
'Version': self.version, 'Version': self.version,
}) })
package = ET.SubElement(product, 'Package', { ET.SubElement(package, 'SummaryInformation', {
'Id': '*',
'Keywords': 'Installer', 'Keywords': 'Installer',
'Description': f'Meson {self.version} installer', 'Description': f'Meson {self.version} installer',
'Comments': 'Meson is a high performance build system',
'Manufacturer': 'The Meson Development Team', 'Manufacturer': 'The Meson Development Team',
'InstallerVersion': '500',
'Languages': '1033',
'Compressed': 'yes',
'SummaryCodepage': '1252',
}) })
condition = ET.SubElement(product, 'Condition', {'Message': 'This application is only supported on Windows 10 or higher.'}) ET.SubElement(package,
'Launch',
{'Message': 'This application is only supported on Windows 10 or higher.',
'Condition': 'X'*len(WINVER_CHECK)})
condition.text = 'X'*len(WINVER_CHECK) ET.SubElement(package, 'MajorUpgrade',
ET.SubElement(product, 'MajorUpgrade', {'DowngradeErrorMessage':
{'DowngradeErrorMessage': 'A newer version of Meson is already installed.'}) 'A newer version of Meson is already installed.'})
package.set('Platform', 'x64') ET.SubElement(package, 'Media', {
ET.SubElement(product, 'Media', {
'Id': '1', 'Id': '1',
'Cabinet': 'meson.cab', 'Cabinet': 'meson.cab',
'EmbedCab': 'yes', 'EmbedCab': 'yes',
}) })
targetdir = ET.SubElement(product, 'Directory', { targetdir = ET.SubElement(package, 'StandardDirectory', {
'Id': 'TARGETDIR', 'Id': 'ProgramFiles64Folder',
'Name': 'SourceDir',
}) })
progfiledir = ET.SubElement(targetdir, 'Directory', { installdir = ET.SubElement(targetdir, 'Directory', {
'Id': self.progfile_dir,
})
installdir = ET.SubElement(progfiledir, 'Directory', {
'Id': 'INSTALLDIR', 'Id': 'INSTALLDIR',
'Name': 'Meson', 'Name': 'Meson',
}) })
@ -213,16 +208,12 @@ class PackageGenerator:
'Language': '0', 'Language': '0',
}) })
ET.SubElement(product, 'Property', { ET.SubElement(package, 'ui:WixUI', {
'Id': 'WIXUI_INSTALLDIR',
'Value': 'INSTALLDIR',
})
ET.SubElement(product, 'UIRef', {
'Id': 'WixUI_FeatureTree', 'Id': 'WixUI_FeatureTree',
}) })
for s_d in self.staging_dirs: for s_d in self.staging_dirs:
assert os.path.isdir(s_d) assert os.path.isdir(s_d)
top_feature = ET.SubElement(product, 'Feature', { top_feature = ET.SubElement(package, 'Feature', {
'Id': 'Complete', 'Id': 'Complete',
'Title': 'Meson ' + self.version, 'Title': 'Meson ' + self.version,
'Description': 'The complete package', 'Description': 'The complete package',
@ -277,10 +268,10 @@ class PackageGenerator:
component_id = f'ApplicationFiles{self.component_num}' component_id = f'ApplicationFiles{self.component_num}'
comp_xml_node = ET.SubElement(parent_xml_node, 'Component', { comp_xml_node = ET.SubElement(parent_xml_node, 'Component', {
'Id': component_id, 'Id': component_id,
'Bitness': 'always64',
'Guid': gen_guid(), 'Guid': gen_guid(),
}) })
self.feature_components[staging_dir].append(component_id) self.feature_components[staging_dir].append(component_id)
comp_xml_node.set('Win64', 'yes')
if self.component_num == 0: if self.component_num == 0:
ET.SubElement(comp_xml_node, 'Environment', { ET.SubElement(comp_xml_node, 'Environment', {
'Id': 'Environment', 'Id': 'Environment',
@ -311,23 +302,40 @@ class PackageGenerator:
''' '''
Generate the Meson build MSI package. Generate the Meson build MSI package.
''' '''
wixdir = 'c:\\Program Files\\Wix Toolset v3.11\\bin' subprocess.check_call(['wix',
if not os.path.isdir(wixdir): 'build',
wixdir = 'c:\\Program Files (x86)\\Wix Toolset v3.11\\bin' '-bindvariable', 'WixUILicenseRtf=packaging\\License.rtf',
if not os.path.isdir(wixdir): '-ext', 'WixToolset.UI.wixext',
print("ERROR: This script requires WIX") '-culture', 'en-us',
sys.exit(1) '-arch', 'x64',
subprocess.check_call([os.path.join(wixdir, 'candle'), self.main_xml]) '-o',
subprocess.check_call([os.path.join(wixdir, 'light'), self.final_output,
'-ext', 'WixUIExtension', self.main_xml,
'-cultures:en-us', ])
'-dWixUILicenseRtf=packaging\\License.rtf',
'-out', self.final_output,
self.main_o]) def install_wix():
subprocess.check_call(['dotnet',
'nuget',
'add',
'source',
'https://api.nuget.org/v3/index.json'])
subprocess.check_call(['dotnet',
'tool',
'install',
'--global',
'wix'])
subprocess.check_call(['wix',
'extension',
'add',
'WixToolset.UI.wixext',
])
if __name__ == '__main__': if __name__ == '__main__':
if not os.path.exists('meson.py'): if not os.path.exists('meson.py'):
sys.exit(print('Run me in the top level source dir.')) sys.exit(print('Run me in the top level source dir.'))
if not shutil.which('wix'):
install_wix()
subprocess.check_call(['pip', 'install', '--upgrade', 'pyinstaller']) subprocess.check_call(['pip', 'install', '--upgrade', 'pyinstaller'])
p = PackageGenerator() p = PackageGenerator()

Loading…
Cancel
Save