contrib/packaging/wix/build.py
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 05 Nov 2019 08:42:42 -0800
branchstable
changeset 43421 be384a2052aa
parent 43076 2372284d9457
permissions -rwxr-xr-x
py3: don't use bytes with vars() or __dict__ Inspired by D7227. These were all the remaining instances I could find. Differential Revision: https://phab.mercurial-scm.org/D7230
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41921
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
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    20
    parser.add_argument('--name', help='Application name', default='Mercurial')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    21
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    22
        '--python', help='Path to Python executable to use', required=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    23
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    24
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    25
        '--sign-sn',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    26
        help='Subject name (or fragment thereof) of certificate '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    27
        'to use for signing',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    28
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    29
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    30
        '--sign-cert', help='Path to certificate to use for signing'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    31
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    32
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    33
        '--sign-password', help='Password for signing certificate'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    34
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    35
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    36
        '--sign-timestamp-url',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    37
        help='URL of timestamp server to use for signing',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    38
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    39
    parser.add_argument('--version', help='Version string to use')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    40
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    41
        '--extra-packages-script',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    42
        help=(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    43
            'Script to execute to include extra packages in ' 'py2exe binary.'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    44
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    45
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    46
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    47
        '--extra-wxs', help='CSV of path_to_wxs_file=working_dir_for_wxs_file'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    48
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    49
    parser.add_argument(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    50
        '--extra-features',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    51
        help=(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    52
            'CSV of extra feature names to include '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    53
            'in the installer from the extra wxs files'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    54
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    55
    )
41921
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
    args = parser.parse_args()
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
    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
    60
    source_dir = here.parent.parent.parent
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
    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
    63
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
    from hgpackaging.wix import (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    65
        build_installer,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    66
        build_signed_installer,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    67
    )
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    69
    fn = build_installer
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    70
    kwargs = {
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
        'source_dir': source_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    72
        'python_exe': pathlib.Path(args.python),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    73
        'version': args.version,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    74
    }
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    75
42091
57645939df59 packaging: ensure that --python is an absolute path when building on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 42049
diff changeset
    76
    if not os.path.isabs(args.python):
57645939df59 packaging: ensure that --python is an absolute path when building on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 42049
diff changeset
    77
        raise Exception('--python arg must be an absolute path')
57645939df59 packaging: ensure that --python is an absolute path when building on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 42049
diff changeset
    78
42047
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    79
    if args.extra_packages_script:
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    80
        kwargs['extra_packages_script'] = args.extra_packages_script
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
    81
    if args.extra_wxs:
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
    82
        kwargs['extra_wxs'] = dict(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    83
            thing.split("=") for thing in args.extra_wxs.split(',')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42091
diff changeset
    84
        )
42049
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
    85
    if args.extra_features:
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
    86
        kwargs['extra_features'] = args.extra_features.split(',')
42047
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41921
diff changeset
    87
41921
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    88
    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
    89
        fn = build_signed_installer
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    90
        kwargs['name'] = args.name
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    91
        kwargs['subject_name'] = args.sign_sn
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    92
        kwargs['cert_path'] = args.sign_cert
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    93
        kwargs['cert_password'] = args.sign_password
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    94
        kwargs['timestamp_url'] = args.sign_timestamp_url
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    95
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    96
    fn(**kwargs)