annotate contrib/packaging/hgpackaging/wix.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents 1711f5813a63
children ce96be208ea4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
1 # wix.py - WiX installer functionality
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
2 #
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
3 # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
4 #
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
5 # This software may be used and distributed according to the terms of the
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
6 # GNU General Public License version 2 or any later version.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
7
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
8 # no-check-code because Python 3 native.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
9
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
10 import os
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
11 import pathlib
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
12 import re
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
13 import subprocess
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
14 import tempfile
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
15 import typing
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
16 import xml.dom.minidom
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
17
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
18 from .downloads import download_entry
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
19 from .py2exe import build_py2exe
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
20 from .util import (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
21 extract_zip_to_directory,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
22 sign_with_signtool,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
23 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
24
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
25
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
26 SUPPORT_WXS = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
27 ('contrib.wxs', r'contrib'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
28 ('dist.wxs', r'dist'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
29 ('doc.wxs', r'doc'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
30 ('help.wxs', r'mercurial\help'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
31 ('i18n.wxs', r'i18n'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
32 ('locale.wxs', r'mercurial\locale'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
33 ('templates.wxs', r'mercurial\templates'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
34 ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
35
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
36
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
37 EXTRA_PACKAGES = {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
38 'distutils',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
39 'pygments',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
40 }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
41
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
42
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
43 def find_version(source_dir: pathlib.Path):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
44 version_py = source_dir / 'mercurial' / '__version__.py'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
45
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
46 with version_py.open('r', encoding='utf-8') as fh:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
47 source = fh.read().strip()
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
48
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
49 m = re.search('version = b"(.*)"', source)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
50 return m.group(1)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
51
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
52
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
53 def normalize_version(version):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
54 """Normalize Mercurial version string so WiX accepts it.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
55
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
56 Version strings have to be numeric X.Y.Z.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
57 """
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
58
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
59 if '+' in version:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
60 version, extra = version.split('+', 1)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
61 else:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
62 extra = None
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
63
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
64 # 4.9rc0
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
65 if version[:-1].endswith('rc'):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
66 version = version[:-3]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
67
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
68 versions = [int(v) for v in version.split('.')]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
69 while len(versions) < 3:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
70 versions.append(0)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
71
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
72 major, minor, build = versions[:3]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
73
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
74 if extra:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
75 # <commit count>-<hash>+<date>
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
76 build = int(extra.split('-')[0])
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
77
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
78 return '.'.join('%d' % x for x in (major, minor, build))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
79
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
80
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
81 def ensure_vc90_merge_modules(build_dir):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
82 x86 = (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
83 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
84 'vc9-crt-x86-msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
85 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
86 local_name='microsoft.vcxx.crt.x86_msm.msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
87 )[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
88 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
89 'vc9-crt-x86-msm-policy',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
90 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
91 local_name='policy.x.xx.microsoft.vcxx.crt.x86_msm.msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
92 )[0],
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
93 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
94
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
95 x64 = (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
96 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
97 'vc9-crt-x64-msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
98 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
99 local_name='microsoft.vcxx.crt.x64_msm.msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
100 )[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
101 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
102 'vc9-crt-x64-msm-policy',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
103 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
104 local_name='policy.x.xx.microsoft.vcxx.crt.x64_msm.msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
105 )[0],
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
106 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
107 return {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
108 'x86': x86,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
109 'x64': x64,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
110 }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
111
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
112
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
113 def run_candle(wix, cwd, wxs, source_dir, defines=None):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
114 args = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
115 str(wix / 'candle.exe'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
116 '-nologo',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
117 str(wxs),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
118 '-dSourceDir=%s' % source_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
119 ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
120
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
121 if defines:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
122 args.extend('-d%s=%s' % define for define in sorted(defines.items()))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
123
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
124 subprocess.run(args, cwd=str(cwd), check=True)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
125
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
126
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
127 def make_post_build_signing_fn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
128 name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
129 subject_name=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
130 cert_path=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
131 cert_password=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
132 timestamp_url=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
133 ):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
134 """Create a callable that will use signtool to sign hg.exe."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
135
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
136 def post_build_sign(source_dir, build_dir, dist_dir, version):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
137 description = '%s %s' % (name, version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
138
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
139 sign_with_signtool(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
140 dist_dir / 'hg.exe',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
141 description,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
142 subject_name=subject_name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
143 cert_path=cert_path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
144 cert_password=cert_password,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
145 timestamp_url=timestamp_url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
146 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
147
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
148 return post_build_sign
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
149
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
150
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
151 LIBRARIES_XML = '''
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
152 <?xml version="1.0" encoding="utf-8"?>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
153 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
154
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
155 <?include {wix_dir}/guids.wxi ?>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
156 <?include {wix_dir}/defines.wxi ?>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
157
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
158 <Fragment>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
159 <DirectoryRef Id="INSTALLDIR" FileSource="$(var.SourceDir)">
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
160 <Directory Id="libdir" Name="lib" FileSource="$(var.SourceDir)/lib">
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
161 <Component Id="libOutput" Guid="$(var.lib.guid)" Win64='$(var.IsX64)'>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
162 </Component>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
163 </Directory>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
164 </DirectoryRef>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
165 </Fragment>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
166 </Wix>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
167 '''.lstrip()
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
168
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
169
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
170 def make_libraries_xml(wix_dir: pathlib.Path, dist_dir: pathlib.Path):
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
171 """Make XML data for library components WXS."""
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
172 # We can't use ElementTree because it doesn't handle the
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
173 # <?include ?> directives.
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
174 doc = xml.dom.minidom.parseString(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
175 LIBRARIES_XML.format(wix_dir=str(wix_dir))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
176 )
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
177
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
178 component = doc.getElementsByTagName('Component')[0]
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
179
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
180 f = doc.createElement('File')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
181 f.setAttribute('Name', 'library.zip')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
182 f.setAttribute('KeyPath', 'yes')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
183 component.appendChild(f)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
184
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
185 lib_dir = dist_dir / 'lib'
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
186
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
187 for p in sorted(lib_dir.iterdir()):
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
188 if not p.name.endswith(('.dll', '.pyd')):
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
189 continue
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
190
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
191 f = doc.createElement('File')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
192 f.setAttribute('Name', p.name)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
193 component.appendChild(f)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
194
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
195 return doc.toprettyxml()
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
196
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
197
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
198 def build_installer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
199 source_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
200 python_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
201 msi_name='mercurial',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
202 version=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
203 post_build_fn=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
204 extra_packages_script=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
205 extra_wxs: typing.Optional[typing.Dict[str, str]] = None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
206 extra_features: typing.Optional[typing.List[str]] = None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
207 ):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
208 """Build a WiX MSI installer.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
209
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
210 ``source_dir`` is the path to the Mercurial source tree to use.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
211 ``arch`` is the target architecture. either ``x86`` or ``x64``.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
212 ``python_exe`` is the path to the Python executable to use/bundle.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
213 ``version`` is the Mercurial version string. If not defined,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
214 ``mercurial/__version__.py`` will be consulted.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
215 ``post_build_fn`` is a callable that will be called after building
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
216 Mercurial but before invoking WiX. It can be used to e.g. facilitate
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
217 signing. It is passed the paths to the Mercurial source, build, and
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
218 dist directories and the resolved Mercurial version.
42047
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
219 ``extra_packages_script`` is a command to be run to inject extra packages
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
220 into the py2exe binary. It should stage packages into the virtualenv and
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
221 print a null byte followed by a newline-separated list of packages that
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
222 should be included in the exe.
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
223 ``extra_wxs`` is a dict of {wxs_name: working_dir_for_wxs_build}.
42049
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
224 ``extra_features`` is a list of additional named Features to include in
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
225 the build. These must match Feature names in one of the wxs scripts.
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
226 """
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
227 arch = 'x64' if r'\x64' in os.environ.get('LIB', '') else 'x86'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
228
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
229 hg_build_dir = source_dir / 'build'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
230 dist_dir = source_dir / 'dist'
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
231 wix_dir = source_dir / 'contrib' / 'packaging' / 'wix'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
232
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
233 requirements_txt = wix_dir / 'requirements.txt'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
234
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
235 build_py2exe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
236 source_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
237 hg_build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
238 python_exe,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
239 'wix',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
240 requirements_txt,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
241 extra_packages=EXTRA_PACKAGES,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
242 extra_packages_script=extra_packages_script,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
243 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
244
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
245 version = version or normalize_version(find_version(source_dir))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
246 print('using version string: %s' % version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
247
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
248 if post_build_fn:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
249 post_build_fn(source_dir, hg_build_dir, dist_dir, version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
250
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
251 build_dir = hg_build_dir / ('wix-%s' % arch)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
252
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
253 build_dir.mkdir(exist_ok=True)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
254
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
255 wix_pkg, wix_entry = download_entry('wix', hg_build_dir)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
256 wix_path = hg_build_dir / ('wix-%s' % wix_entry['version'])
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
257
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
258 if not wix_path.exists():
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
259 extract_zip_to_directory(wix_pkg, wix_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
260
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
261 ensure_vc90_merge_modules(hg_build_dir)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
262
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
263 source_build_rel = pathlib.Path(os.path.relpath(source_dir, build_dir))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
264
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
265 defines = {'Platform': arch}
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
266
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
267 for wxs, rel_path in SUPPORT_WXS:
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
268 wxs = wix_dir / wxs
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
269 wxs_source_dir = source_dir / rel_path
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
270 run_candle(wix_path, build_dir, wxs, wxs_source_dir, defines=defines)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
271
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
272 for source, rel_path in sorted((extra_wxs or {}).items()):
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
273 run_candle(wix_path, build_dir, source, rel_path, defines=defines)
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
274
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
275 # candle.exe doesn't like when we have an open handle on the file.
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
276 # So use TemporaryDirectory() instead of NamedTemporaryFile().
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
277 with tempfile.TemporaryDirectory() as td:
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
278 td = pathlib.Path(td)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
279
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
280 tf = td / 'library.wxs'
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
281 with tf.open('w') as fh:
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
282 fh.write(make_libraries_xml(wix_dir, dist_dir))
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
283
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
284 run_candle(wix_path, build_dir, tf, dist_dir, defines=defines)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
285
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
286 source = wix_dir / 'mercurial.wxs'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
287 defines['Version'] = version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
288 defines['Comments'] = 'Installs Mercurial version %s' % version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
289 defines['VCRedistSrcDir'] = str(hg_build_dir)
42049
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
290 if extra_features:
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
291 assert all(';' not in f for f in extra_features)
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
292 defines['MercurialExtraFeatures'] = ';'.join(extra_features)
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
293
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
294 run_candle(wix_path, build_dir, source, source_build_rel, defines=defines)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
295
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
296 msi_path = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
297 source_dir / 'dist' / ('%s-%s-%s.msi' % (msi_name, version, arch))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
298 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
299
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
300 args = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
301 str(wix_path / 'light.exe'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
302 '-nologo',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
303 '-ext',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
304 'WixUIExtension',
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
305 '-sw1076',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
306 '-spdb',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
307 '-o',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
308 str(msi_path),
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
309 ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
310
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
311 for source, rel_path in SUPPORT_WXS:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
312 assert source.endswith('.wxs')
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
313 args.append(str(build_dir / ('%s.wixobj' % source[:-4])))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
314
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
315 for source, rel_path in sorted((extra_wxs or {}).items()):
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
316 assert source.endswith('.wxs')
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
317 source = os.path.basename(source)
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
318 args.append(str(build_dir / ('%s.wixobj' % source[:-4])))
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
319
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
320 args.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
321 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
322 str(build_dir / 'library.wixobj'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
323 str(build_dir / 'mercurial.wixobj'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
324 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
325 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
326
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
327 subprocess.run(args, cwd=str(source_dir), check=True)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
328
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
329 print('%s created' % msi_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
330
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
331 return {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
332 'msi_path': msi_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
333 }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
334
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
335
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
336 def build_signed_installer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
337 source_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
338 python_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
339 name: str,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
340 version=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
341 subject_name=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
342 cert_path=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
343 cert_password=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
344 timestamp_url=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
345 extra_packages_script=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
346 extra_wxs=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
347 extra_features=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
348 ):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
349 """Build an installer with signed executables."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
350
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
351 post_build_fn = make_post_build_signing_fn(
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
352 name,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
353 subject_name=subject_name,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
354 cert_path=cert_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
355 cert_password=cert_password,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
356 timestamp_url=timestamp_url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
357 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
358
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
359 info = build_installer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
360 source_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
361 python_exe=python_exe,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
362 msi_name=name.lower(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
363 version=version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
364 post_build_fn=post_build_fn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
365 extra_packages_script=extra_packages_script,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
366 extra_wxs=extra_wxs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
367 extra_features=extra_features,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
368 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
369
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
370 description = '%s %s' % (name, version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
371
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
372 sign_with_signtool(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
373 info['msi_path'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
374 description,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
375 subject_name=subject_name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
376 cert_path=cert_path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
377 cert_password=cert_password,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
378 timestamp_url=timestamp_url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
379 )