annotate contrib/packaging/hgpackaging/wix.py @ 41922:c569f769c41d

wix: remove sphinx and dependencies Sphinx was cargo culted into our install environment as part of emulating TortoiseHG's behavior. THG seems to install Sphinx in order to generate THG specific documentation. We don't appear to need Sphinx or any of its dependencies in the official WiX installers. So remove it. This shaves ~1MB off the size of the MSI installers. .. bc:: The Windows MSI installers no longer include the Python sphinx package and its various dependencies. Differential Revision: https://phab.mercurial-scm.org/D6099
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 08 Mar 2019 10:25:05 -0800
parents 4371f543efda
children 9d4ae5044b4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41921
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1 # wix.py - WiX installer functionality
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2 #
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3 # 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
4 #
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5 # 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
6 # 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
7
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 # no-check-code because Python 3 native.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
9
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
10 import os
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
11 import pathlib
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
12 import re
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
13 import subprocess
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
14
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
15 from .downloads import (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
16 download_entry,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
17 )
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
18 from .py2exe import (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
19 build_py2exe,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
20 )
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
21 from .util import (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
22 extract_zip_to_directory,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
23 sign_with_signtool,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
24 )
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
25
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27 SUPPORT_WXS = [
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
28 ('contrib.wxs', r'contrib'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
29 ('dist.wxs', r'dist'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
30 ('doc.wxs', r'doc'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
31 ('help.wxs', r'mercurial\help'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
32 ('i18n.wxs', r'i18n'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
33 ('locale.wxs', r'mercurial\locale'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
34 ('templates.wxs', r'mercurial\templates'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
35 ]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
36
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 EXTRA_PACKAGES = {
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
39 'distutils',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
40 'enum',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
41 'pygments',
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
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 def find_version(source_dir: pathlib.Path):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
46 version_py = source_dir / 'mercurial' / '__version__.py'
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 with version_py.open('r', encoding='utf-8') as fh:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
49 source = fh.read().strip()
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 m = re.search('version = b"(.*)"', source)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
52 return m.group(1)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
53
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
54
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
55 def normalize_version(version):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
56 """Normalize Mercurial version string so WiX accepts it.
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 Version strings have to be numeric X.Y.Z.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
59 """
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
60
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
61 if '+' in version:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62 version, extra = version.split('+', 1)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
63 else:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
64 extra = None
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
65
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
66 # 4.9rc0
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
67 if version[:-1].endswith('rc'):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
68 version = version[:-3]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
69
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
70 versions = [int(v) for v in version.split('.')]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
71 while len(versions) < 3:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
72 versions.append(0)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
73
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
74 major, minor, build = versions[:3]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
75
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
76 if extra:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
77 # <commit count>-<hash>+<date>
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
78 build = int(extra.split('-')[0])
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
79
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
80 return '.'.join('%d' % x for x in (major, minor, build))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
81
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
82
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
83 def ensure_vc90_merge_modules(build_dir):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
84 x86 = (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85 download_entry('vc9-crt-x86-msm', build_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
86 local_name='microsoft.vcxx.crt.x86_msm.msm')[0],
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
87 download_entry('vc9-crt-x86-msm-policy', build_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
88 local_name='policy.x.xx.microsoft.vcxx.crt.x86_msm.msm')[0]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
89 )
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
90
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
91 x64 = (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
92 download_entry('vc9-crt-x64-msm', build_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
93 local_name='microsoft.vcxx.crt.x64_msm.msm')[0],
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
94 download_entry('vc9-crt-x64-msm-policy', build_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
95 local_name='policy.x.xx.microsoft.vcxx.crt.x64_msm.msm')[0]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
96 )
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
97 return {
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
98 'x86': x86,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
99 'x64': x64,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
100 }
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
101
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
102
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
103 def run_candle(wix, cwd, wxs, source_dir, defines=None):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
104 args = [
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
105 str(wix / 'candle.exe'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
106 '-nologo',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
107 str(wxs),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
108 '-dSourceDir=%s' % source_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
109 ]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
110
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
111 if defines:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
112 args.extend('-d%s=%s' % define for define in sorted(defines.items()))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
113
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
114 subprocess.run(args, cwd=str(cwd), check=True)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
115
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
116
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
117 def make_post_build_signing_fn(name, subject_name=None, cert_path=None,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
118 cert_password=None, timestamp_url=None):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
119 """Create a callable that will use signtool to sign hg.exe."""
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
120
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
121 def post_build_sign(source_dir, build_dir, dist_dir, version):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
122 description = '%s %s' % (name, version)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
123
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
124 sign_with_signtool(dist_dir / 'hg.exe', description,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
125 subject_name=subject_name, cert_path=cert_path,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
126 cert_password=cert_password,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
127 timestamp_url=timestamp_url)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
128
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
129 return post_build_sign
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
130
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
131
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
132 def build_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
133 msi_name='mercurial', version=None, post_build_fn=None):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
134 """Build a WiX MSI installer.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
135
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
136 ``source_dir`` is the path to the Mercurial source tree to use.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
137 ``arch`` is the target architecture. either ``x86`` or ``x64``.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
138 ``python_exe`` is the path to the Python executable to use/bundle.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
139 ``version`` is the Mercurial version string. If not defined,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
140 ``mercurial/__version__.py`` will be consulted.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
141 ``post_build_fn`` is a callable that will be called after building
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
142 Mercurial but before invoking WiX. It can be used to e.g. facilitate
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
143 signing. It is passed the paths to the Mercurial source, build, and
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
144 dist directories and the resolved Mercurial version.
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
145 """
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
146 arch = 'x64' if r'\x64' in os.environ.get('LIB', '') else 'x86'
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
147
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
148 hg_build_dir = source_dir / 'build'
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
149 dist_dir = source_dir / 'dist'
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
150
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
151 requirements_txt = (source_dir / 'contrib' / 'packaging' /
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
152 'wix' / 'requirements.txt')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
153
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
154 build_py2exe(source_dir, hg_build_dir,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
155 python_exe, 'wix', requirements_txt,
41922
c569f769c41d wix: remove sphinx and dependencies
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41921
diff changeset
156 extra_packages=EXTRA_PACKAGES)
41921
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
157
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
158 version = version or normalize_version(find_version(source_dir))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
159 print('using version string: %s' % version)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
160
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
161 if post_build_fn:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
162 post_build_fn(source_dir, hg_build_dir, dist_dir, version)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
163
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
164 build_dir = hg_build_dir / ('wix-%s' % arch)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
165
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
166 build_dir.mkdir(exist_ok=True)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
167
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
168 wix_pkg, wix_entry = download_entry('wix', hg_build_dir)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
169 wix_path = hg_build_dir / ('wix-%s' % wix_entry['version'])
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
170
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
171 if not wix_path.exists():
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
172 extract_zip_to_directory(wix_pkg, wix_path)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
173
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
174 ensure_vc90_merge_modules(hg_build_dir)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
175
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
176 source_build_rel = pathlib.Path(os.path.relpath(source_dir, build_dir))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
177
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
178 defines = {'Platform': arch}
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
179
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
180 for wxs, rel_path in SUPPORT_WXS:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
181 wxs = source_dir / 'contrib' / 'packaging' / 'wix' / wxs
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
182 wxs_source_dir = source_dir / rel_path
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
183 run_candle(wix_path, build_dir, wxs, wxs_source_dir, defines=defines)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
184
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
185 source = source_dir / 'contrib' / 'packaging' / 'wix' / 'mercurial.wxs'
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
186 defines['Version'] = version
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
187 defines['Comments'] = 'Installs Mercurial version %s' % version
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
188 defines['VCRedistSrcDir'] = str(hg_build_dir)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
189
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
190 run_candle(wix_path, build_dir, source, source_build_rel, defines=defines)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
191
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
192 msi_path = source_dir / 'dist' / (
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
193 '%s-%s-%s.msi' % (msi_name, version, arch))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
194
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
195 args = [
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
196 str(wix_path / 'light.exe'),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
197 '-nologo',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
198 '-ext', 'WixUIExtension',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
199 '-sw1076',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
200 '-spdb',
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
201 '-o', str(msi_path),
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
202 ]
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
203
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
204 for source, rel_path in SUPPORT_WXS:
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
205 assert source.endswith('.wxs')
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
206 args.append(str(build_dir / ('%s.wixobj' % source[:-4])))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
207
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
208 args.append(str(build_dir / 'mercurial.wixobj'))
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
209
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
210 subprocess.run(args, cwd=str(source_dir), check=True)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
211
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
212 print('%s created' % msi_path)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
213
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
214 return {
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
215 'msi_path': msi_path,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
216 }
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
217
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
218
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
219 def build_signed_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
220 name: str, version=None, subject_name=None,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
221 cert_path=None, cert_password=None,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
222 timestamp_url=None):
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
223 """Build an installer with signed executables."""
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
224
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
225 post_build_fn = make_post_build_signing_fn(
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
226 name,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
227 subject_name=subject_name,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
228 cert_path=cert_path,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
229 cert_password=cert_password,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
230 timestamp_url=timestamp_url)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
231
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
232 info = build_installer(source_dir, python_exe=python_exe,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
233 msi_name=name.lower(), version=version,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
234 post_build_fn=post_build_fn)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
235
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
236 description = '%s %s' % (name, version)
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
237
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
238 sign_with_signtool(info['msi_path'], description,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
239 subject_name=subject_name, cert_path=cert_path,
4371f543efda wix: functionality to automate building WiX installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
240 cert_password=cert_password, timestamp_url=timestamp_url)