author | Raphaël Gomès <rgomes@octobus.net> |
Tue, 09 Jul 2019 11:49:49 +0200 | |
changeset 42748 | 7cae6bc29ff9 |
parent 42091 | 57645939df59 |
child 43076 | 2372284d9457 |
permissions | -rwxr-xr-x |
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 |
|
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') |
42047
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41921
diff
changeset
|
37 |
parser.add_argument('--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
|
38 |
help=('Script to execute to include extra packages in ' |
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41921
diff
changeset
|
39 |
'py2exe binary.')) |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
40 |
parser.add_argument('--extra-wxs', |
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
41 |
help='CSV of path_to_wxs_file=working_dir_for_wxs_file') |
42049
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
42 |
parser.add_argument('--extra-features', |
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
43 |
help=('CSV of extra feature names to include ' |
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
44 |
'in the installer from the extra wxs files')) |
41921
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
|
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 |
args = parser.parse_args() |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
|
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 |
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
|
49 |
source_dir = here.parent.parent.parent |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
|
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
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
|
52 |
|
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
from hgpackaging.wix import ( |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 |
build_installer, |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
build_signed_installer, |
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 |
|
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
fn = build_installer |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
kwargs = { |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 |
'source_dir': source_dir, |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 |
'python_exe': pathlib.Path(args.python), |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
'version': args.version, |
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 |
|
42091
57645939df59
packaging: ensure that --python is an absolute path when building on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
42049
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
|
42047
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41921
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
if args.extra_wxs: |
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
71 |
kwargs['extra_wxs'] = dict( |
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
72 |
thing.split("=") for thing in args.extra_wxs.split(',')) |
42049
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
73 |
if args.extra_features: |
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
74 |
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
|
75 |
|
41921
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
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
|
77 |
fn = build_signed_installer |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 |
kwargs['name'] = args.name |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 |
kwargs['subject_name'] = args.sign_sn |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 |
kwargs['cert_path'] = args.sign_cert |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
kwargs['cert_password'] = args.sign_password |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
kwargs['timestamp_url'] = args.sign_timestamp_url |
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
|
4371f543efda
wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 |
fn(**kwargs) |