contrib/packaging/wix/build.py
author Gregory Szorc <gregory.szorc@gmail.com>
Fri, 08 Mar 2019 10:48:22 -0800
changeset 41926 4371f543efda
child 42047 715d3220ac4f
permissions -rwxr-xr-x
wix: functionality to automate building WiX installers Like we did for Inno Setup, we want to make it easier to produce WiX installers. This commit does that. We introduce a new hgpackaging.wix module for performing all the high-level tasks required to produce WiX installers. This required miscellaneous enhancements to existing code in hgpackaging, including support for signing binaries. A new build.py script for calling into the module APIs has been created. It behaves very similarly to the Inno Setup build.py script. Unlike Inno Setup, we didn't have code in the repo previously to generate WiX installers. It appears that all existing automation for building WiX installers lives in the https://bitbucket.org/tortoisehg/thg-winbuild repository - most notably in its setup.py file. My strategy for inventing the code in this commit was to step through the code in that repo's setup.py and observe what it was doing. Despite the length of setup.py in that repository, the actual amount of steps required to produce a WiX installer is actually quite low. It consists of a basic py2exe build plus invocations of candle.exe and light.exe to produce the MSI. One rabbit hole that gave me fits was locating the Visual Studio 9 C Runtime merge modules. These merge modules are only present on your system if you have a full Visual Studio 2008 installation. Fortunately, I have a copy of Visual Studio 2008 and was able to install all the required updates. I then uploaded these merge modules to a personal repository on GitHub. That is where the added code references them from. We probably don't need to ship the merge modules. But that is for another day. The installs from the MSIs produced with the new automation differ from the last official MSI in the following ways: * Our HTML manual pages have UNIX line endings instead of Windows. * We ship modules in the mercurial.pure package. It appears the upstream packaging code is not including this package due to omission (they supply an explicit list of packages that has drifted out of sync with our setup.py). * We do not ship various distutils.* modules. This is because virtualenvs have a custom distutils/__init__.py that automagically imports distutils from its original location and py2exe gets confused by this. We don't use distutils in core Mercurial and don't provide a usable python.exe, so this omission should be acceptable. * The version of the enum package is different and we ship an enum.pyc instead of an enum/__init__.py. * The version of the docutils package is different and we ship a different set of files. * The version of Sphinx is drastically newer and we ship a number of files the old version did not. (I'm not sure why we ship Sphinx - I think it is a side-effect of the way the THG code was installing dependencies.) * We ship the idna package (dependent of requests which is a dependency of newer versions of Sphinx). * The version of imagesize is different and we ship an imagesize.pyc instead of an imagesize/__init__.pyc. * The version of the jinja2 package is different and the sets of files differs. * We ship the packaging package, which is a dependency for Sphinx. * The version of the pygments package is different and the sets of files differs. * We ship the requests package, which is a dependency for Sphinx. * We ship the snowballstemmer package, which is a dependency for Sphinx. * We ship the urllib3 package, which is a dependency for requests, which is a dependency for Sphinx. * We ship a newer version of the futures package, which includes a handful of extra modules that match Python 3 module names. # no-check-commit because foo_bar naming Differential Revision: https://phab.mercurial-scm.org/D6097
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41926
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python3
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
#
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
# This software may be used and distributed according to the terms of the
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# GNU General Public License version 2 or any later version.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
# no-check-code because Python 3 native.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
"""Code to build Mercurial WiX installer."""
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
import argparse
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
import os
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
import pathlib
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
import sys
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
if __name__ == '__main__':
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
    parser = argparse.ArgumentParser()
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
    parser.add_argument('--name',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
                        help='Application name',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
                        default='Mercurial')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
    parser.add_argument('--python',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
                        help='Path to Python executable to use',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
                        required=True)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
    parser.add_argument('--sign-sn',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
                        help='Subject name (or fragment thereof) of certificate '
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
                             'to use for signing')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
    parser.add_argument('--sign-cert',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
                        help='Path to certificate to use for signing')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
    parser.add_argument('--sign-password',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
                        help='Password for signing certificate')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
    parser.add_argument('--sign-timestamp-url',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
                        help='URL of timestamp server to use for signing')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
    parser.add_argument('--version',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
                        help='Version string to use')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
    args = parser.parse_args()
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
    here = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    41
    source_dir = here.parent.parent.parent
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    43
    sys.path.insert(0, str(source_dir / 'contrib' / 'packaging'))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    44
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    45
    from hgpackaging.wix import (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    46
        build_installer,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    47
        build_signed_installer,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
    )
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    50
    fn = build_installer
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    51
    kwargs = {
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
        'source_dir': source_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
        'python_exe': pathlib.Path(args.python),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    54
        'version': args.version,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
    }
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    56
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    57
    if args.sign_sn or args.sign_cert:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
        fn = build_signed_installer
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
        kwargs['name'] = args.name
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
        kwargs['subject_name'] = args.sign_sn
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
        kwargs['cert_path'] = args.sign_cert
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
        kwargs['cert_password'] = args.sign_password
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
        kwargs['timestamp_url'] = args.sign_timestamp_url
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    65
    fn(**kwargs)