view contrib/packaging/wix/build.py @ 42047:715d3220ac4f

wix: add a hook for a prebuild script to inject extra libraries I need this to build packages for Google so we can bundle some extensions in the installed image. My assumption is that this is most interesting for the .msi images so I only wired it up there. I'm not thrilled with the interface this provides, but it was an easy way to retain debug messages on Windows while also having enough structure to know what lines are actually module names for py2exe. Still pending on my end: I need to bundle a couple of config files, and at least one data file. I'm open to advice on how to do those things, and how to do this better. Differential Revision: https://phab.mercurial-scm.org/D6164
author Augie Fackler <augie@google.com>
date Wed, 20 Mar 2019 13:18:37 -0400
parents 4371f543efda
children 978b03d5f66e
line wrap: on
line source

#!/usr/bin/env python3
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

# no-check-code because Python 3 native.

"""Code to build Mercurial WiX installer."""

import argparse
import os
import pathlib
import sys


if __name__ == '__main__':
    parser = argparse.ArgumentParser()

    parser.add_argument('--name',
                        help='Application name',
                        default='Mercurial')
    parser.add_argument('--python',
                        help='Path to Python executable to use',
                        required=True)
    parser.add_argument('--sign-sn',
                        help='Subject name (or fragment thereof) of certificate '
                             'to use for signing')
    parser.add_argument('--sign-cert',
                        help='Path to certificate to use for signing')
    parser.add_argument('--sign-password',
                        help='Password for signing certificate')
    parser.add_argument('--sign-timestamp-url',
                        help='URL of timestamp server to use for signing')
    parser.add_argument('--version',
                        help='Version string to use')
    parser.add_argument('--extra-packages-script',
                        help=('Script to execute to include extra packages in '
                              'py2exe binary.'))

    args = parser.parse_args()

    here = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))
    source_dir = here.parent.parent.parent

    sys.path.insert(0, str(source_dir / 'contrib' / 'packaging'))

    from hgpackaging.wix import (
        build_installer,
        build_signed_installer,
    )

    fn = build_installer
    kwargs = {
        'source_dir': source_dir,
        'python_exe': pathlib.Path(args.python),
        'version': args.version,
    }

    if args.extra_packages_script:
        kwargs['extra_packages_script'] = args.extra_packages_script

    if args.sign_sn or args.sign_cert:
        fn = build_signed_installer
        kwargs['name'] = args.name
        kwargs['subject_name'] = args.sign_sn
        kwargs['cert_path'] = args.sign_cert
        kwargs['cert_password'] = args.sign_password
        kwargs['timestamp_url'] = args.sign_timestamp_url

    fn(**kwargs)