annotate contrib/packaging/hgpackaging/wix.py @ 43697:dc4e74d0ef96

py3: send bytes from Rust-created warning patterns Python code expects bytes in both Python 2 and Python 3, so we should send bytes. Differential Revision: https://phab.mercurial-scm.org/D7454
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 18 Nov 2019 17:37:59 +0100
parents 94eac340d212
children e4344e463c0c
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
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
10 import collections
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
11 import os
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
12 import pathlib
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
13 import re
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
14 import shutil
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
15 import subprocess
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
16 import typing
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
17 import uuid
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
18 import xml.dom.minidom
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
19
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
20 from .downloads import download_entry
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
21 from .py2exe import (
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
22 build_py2exe,
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
23 stage_install,
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
24 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
25 from .util import (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
26 extract_zip_to_directory,
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
27 process_install_rules,
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
28 sign_with_signtool,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
29 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
30
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
31
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
32 EXTRA_PACKAGES = {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
33 'distutils',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
34 'pygments',
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
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
38 EXTRA_INSTALL_RULES = [
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
39 ('contrib/packaging/wix/COPYING.rtf', 'COPYING.rtf'),
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
40 ('contrib/win32/mercurial.ini', 'hgrc.d/mercurial.rc'),
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
41 ]
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
42
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
43 STAGING_REMOVE_FILES = [
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
44 # We use the RTF variant.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
45 'copying.txt',
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
46 ]
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
47
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
48 SHORTCUTS = {
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
49 # hg.1.html'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
50 'hg.file.5d3e441c_28d9_5542_afd0_cdd4234f12d5': {
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
51 'Name': 'Mercurial Command Reference',
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
52 },
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
53 # hgignore.5.html
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
54 'hg.file.5757d8e0_f207_5e10_a2ec_3ba0a062f431': {
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
55 'Name': 'Mercurial Ignore Files',
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
56 },
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
57 # hgrc.5.html
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
58 'hg.file.92e605fd_1d1a_5dc6_9fc0_5d2998eb8f5e': {
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
59 'Name': 'Mercurial Configuration Files',
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
60 },
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
61 }
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
62
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
63
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
64 def find_version(source_dir: pathlib.Path):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
65 version_py = source_dir / 'mercurial' / '__version__.py'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
66
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
67 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
68 source = fh.read().strip()
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
69
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
70 m = re.search('version = b"(.*)"', source)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
71 return m.group(1)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
72
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 def normalize_version(version):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
75 """Normalize Mercurial version string so WiX accepts it.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
76
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
77 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
78 """
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 if '+' in version:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
81 version, extra = version.split('+', 1)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
82 else:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
83 extra = None
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
84
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
85 # 4.9rc0
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
86 if version[:-1].endswith('rc'):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
87 version = version[:-3]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
88
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
89 versions = [int(v) for v in version.split('.')]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
90 while len(versions) < 3:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
91 versions.append(0)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
92
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
93 major, minor, build = versions[:3]
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 if extra:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
96 # <commit count>-<hash>+<date>
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
97 build = int(extra.split('-')[0])
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
98
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
99 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
100
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
101
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
102 def ensure_vc90_merge_modules(build_dir):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
103 x86 = (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
104 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
105 'vc9-crt-x86-msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
106 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
107 local_name='microsoft.vcxx.crt.x86_msm.msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
108 )[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
109 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
110 'vc9-crt-x86-msm-policy',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
111 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
112 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
113 )[0],
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
114 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
115
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
116 x64 = (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
117 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
118 'vc9-crt-x64-msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
119 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
120 local_name='microsoft.vcxx.crt.x64_msm.msm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
121 )[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
122 download_entry(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
123 'vc9-crt-x64-msm-policy',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
124 build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
125 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
126 )[0],
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
127 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
128 return {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
129 'x86': x86,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
130 'x64': x64,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
131 }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
132
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
133
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
134 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
135 args = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
136 str(wix / 'candle.exe'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
137 '-nologo',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
138 str(wxs),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
139 '-dSourceDir=%s' % source_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
140 ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
141
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
142 if defines:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
143 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
144
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
145 subprocess.run(args, cwd=str(cwd), check=True)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
146
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
147
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
148 def make_post_build_signing_fn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
149 name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
150 subject_name=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
151 cert_path=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
152 cert_password=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
153 timestamp_url=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
154 ):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
155 """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
156
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
157 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
158 description = '%s %s' % (name, version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
159
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
160 sign_with_signtool(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
161 dist_dir / 'hg.exe',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
162 description,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
163 subject_name=subject_name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
164 cert_path=cert_path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
165 cert_password=cert_password,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
166 timestamp_url=timestamp_url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
167 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
168
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
169 return post_build_sign
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
170
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
171
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
172 def make_files_xml(staging_dir: pathlib.Path, is_x64) -> str:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
173 """Create XML string listing every file to be installed."""
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
174
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
175 # We derive GUIDs from a deterministic file path identifier.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
176 # We shoehorn the name into something that looks like a URL because
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
177 # the UUID namespaces are supposed to work that way (even though
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
178 # the input data probably is never validated).
41957
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 doc = xml.dom.minidom.parseString(
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
181 '<?xml version="1.0" encoding="utf-8"?>'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
182 '<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
183 '</Wix>'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
184 )
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
185
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
186 # Assemble the install layout by directory. This makes it easier to
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
187 # emit XML, since each directory has separate entities.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
188 manifest = collections.defaultdict(dict)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
189
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
190 for root, dirs, files in os.walk(staging_dir):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
191 dirs.sort()
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
192
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
193 root = pathlib.Path(root)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
194 rel_dir = root.relative_to(staging_dir)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
195
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
196 for i in range(len(rel_dir.parts)):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
197 parent = '/'.join(rel_dir.parts[0 : i + 1])
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
198 manifest.setdefault(parent, {})
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
199
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
200 for f in sorted(files):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
201 full = root / f
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
202 manifest[str(rel_dir).replace('\\', '/')][full.name] = full
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
203
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
204 component_groups = collections.defaultdict(list)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
205
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
206 # Now emit a <Fragment> for each directory.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
207 # Each directory is composed of a <DirectoryRef> pointing to its parent
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
208 # and defines child <Directory>'s and a <Component> with all the files.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
209 for dir_name, entries in sorted(manifest.items()):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
210 # The directory id is derived from the path. But the root directory
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
211 # is special.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
212 if dir_name == '.':
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
213 parent_directory_id = 'INSTALLDIR'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
214 else:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
215 parent_directory_id = 'hg.dir.%s' % dir_name.replace('/', '.')
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
216
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
217 fragment = doc.createElement('Fragment')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
218 directory_ref = doc.createElement('DirectoryRef')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
219 directory_ref.setAttribute('Id', parent_directory_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
220
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
221 # Add <Directory> entries for immediate children directories.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
222 for possible_child in sorted(manifest.keys()):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
223 if (
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
224 dir_name == '.'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
225 and '/' not in possible_child
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
226 and possible_child != '.'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
227 ):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
228 child_directory_id = 'hg.dir.%s' % possible_child
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
229 name = possible_child
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
230 else:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
231 if not possible_child.startswith('%s/' % dir_name):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
232 continue
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
233 name = possible_child[len(dir_name) + 1 :]
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
234 if '/' in name:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
235 continue
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
236
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
237 child_directory_id = 'hg.dir.%s' % possible_child.replace(
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
238 '/', '.'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
239 )
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
240
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
241 directory = doc.createElement('Directory')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
242 directory.setAttribute('Id', child_directory_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
243 directory.setAttribute('Name', name)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
244 directory_ref.appendChild(directory)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
245
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
246 # Add <Component>s for files in this directory.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
247 for rel, source_path in sorted(entries.items()):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
248 if dir_name == '.':
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
249 full_rel = rel
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
250 else:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
251 full_rel = '%s/%s' % (dir_name, rel)
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
252
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
253 component_unique_id = (
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
254 'https://www.mercurial-scm.org/wix-installer/0/component/%s'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
255 % full_rel
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
256 )
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
257 component_guid = uuid.uuid5(uuid.NAMESPACE_URL, component_unique_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
258 component_id = 'hg.component.%s' % str(component_guid).replace(
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
259 '-', '_'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
260 )
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
261
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
262 component = doc.createElement('Component')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
263
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
264 component.setAttribute('Id', component_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
265 component.setAttribute('Guid', str(component_guid).upper())
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
266 component.setAttribute('Win64', 'yes' if is_x64 else 'no')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
267
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
268 # Assign this component to a top-level group.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
269 if dir_name == '.':
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
270 component_groups['ROOT'].append(component_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
271 elif '/' in dir_name:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
272 component_groups[dir_name[0 : dir_name.index('/')]].append(
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
273 component_id
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
274 )
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
275 else:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
276 component_groups[dir_name].append(component_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
277
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
278 unique_id = (
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
279 'https://www.mercurial-scm.org/wix-installer/0/%s' % full_rel
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
280 )
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
281 file_guid = uuid.uuid5(uuid.NAMESPACE_URL, unique_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
282
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
283 # IDs have length limits. So use GUID to derive them.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
284 file_guid_normalized = str(file_guid).replace('-', '_')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
285 file_id = 'hg.file.%s' % file_guid_normalized
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
286
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
287 file_element = doc.createElement('File')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
288 file_element.setAttribute('Id', file_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
289 file_element.setAttribute('Source', str(source_path))
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
290 file_element.setAttribute('KeyPath', 'yes')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
291 file_element.setAttribute('ReadOnly', 'yes')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
292
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
293 component.appendChild(file_element)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
294 directory_ref.appendChild(component)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
295
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
296 fragment.appendChild(directory_ref)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
297 doc.documentElement.appendChild(fragment)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
298
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
299 for group, component_ids in sorted(component_groups.items()):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
300 fragment = doc.createElement('Fragment')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
301 component_group = doc.createElement('ComponentGroup')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
302 component_group.setAttribute('Id', 'hg.group.%s' % group)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
303
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
304 for component_id in component_ids:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
305 component_ref = doc.createElement('ComponentRef')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
306 component_ref.setAttribute('Id', component_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
307 component_group.appendChild(component_ref)
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
308
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
309 fragment.appendChild(component_group)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
310 doc.documentElement.appendChild(fragment)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
311
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
312 # Add <Shortcut> to files that have it defined.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
313 for file_id, metadata in sorted(SHORTCUTS.items()):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
314 els = doc.getElementsByTagName('File')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
315 els = [el for el in els if el.getAttribute('Id') == file_id]
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
316
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
317 if not els:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
318 raise Exception('could not find File[Id=%s]' % file_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
319
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
320 for el in els:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
321 shortcut = doc.createElement('Shortcut')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
322 shortcut.setAttribute('Id', 'hg.shortcut.%s' % file_id)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
323 shortcut.setAttribute('Directory', 'ProgramMenuDir')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
324 shortcut.setAttribute('Icon', 'hgIcon.ico')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
325 shortcut.setAttribute('IconIndex', '0')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
326 shortcut.setAttribute('Advertise', 'yes')
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
327 for k, v in sorted(metadata.items()):
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
328 shortcut.setAttribute(k, v)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
329
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
330 el.appendChild(shortcut)
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
331
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
332 return doc.toprettyxml()
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
333
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
334
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
335 def build_installer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
336 source_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
337 python_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
338 msi_name='mercurial',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
339 version=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
340 post_build_fn=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
341 extra_packages_script=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
342 extra_wxs: typing.Optional[typing.Dict[str, str]] = None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
343 extra_features: typing.Optional[typing.List[str]] = None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
344 ):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
345 """Build a WiX MSI installer.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
346
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
347 ``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
348 ``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
349 ``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
350 ``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
351 ``mercurial/__version__.py`` will be consulted.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
352 ``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
353 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
354 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
355 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
356 ``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
357 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
358 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
359 should be included in the exe.
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
360 ``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
361 ``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
362 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
363 """
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
364 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
365
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
366 hg_build_dir = source_dir / 'build'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
367 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
368 wix_dir = source_dir / 'contrib' / 'packaging' / 'wix'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
369
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
370 requirements_txt = wix_dir / 'requirements.txt'
41952
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 build_py2exe(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
373 source_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
374 hg_build_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
375 python_exe,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
376 'wix',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
377 requirements_txt,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
378 extra_packages=EXTRA_PACKAGES,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
379 extra_packages_script=extra_packages_script,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
380 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
381
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
382 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
383 print('using version string: %s' % version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
384
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
385 if post_build_fn:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
386 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
387
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
388 build_dir = hg_build_dir / ('wix-%s' % arch)
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
389 staging_dir = build_dir / 'stage'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
390
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
391 build_dir.mkdir(exist_ok=True)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
392
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
393 # Purge the staging directory for every build so packaging is pristine.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
394 if staging_dir.exists():
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
395 print('purging %s' % staging_dir)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
396 shutil.rmtree(staging_dir)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
397
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
398 stage_install(source_dir, staging_dir, lower_case=True)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
399
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
400 # We also install some extra files.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
401 process_install_rules(EXTRA_INSTALL_RULES, source_dir, staging_dir)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
402
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
403 # And remove some files we don't want.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
404 for f in STAGING_REMOVE_FILES:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
405 p = staging_dir / f
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
406 if p.exists():
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
407 print('removing %s' % p)
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
408 p.unlink()
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
409
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
410 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
411 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
412
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
413 if not wix_path.exists():
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
414 extract_zip_to_directory(wix_pkg, wix_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
415
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
416 ensure_vc90_merge_modules(hg_build_dir)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
417
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
418 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
419
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
420 defines = {'Platform': arch}
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
421
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
422 # Derive a .wxs file with the staged files.
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
423 manifest_wxs = build_dir / 'stage.wxs'
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
424 with manifest_wxs.open('w', encoding='utf-8') as fh:
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
425 fh.write(make_files_xml(staging_dir, is_x64=arch == 'x64'))
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
426
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
427 run_candle(wix_path, build_dir, manifest_wxs, staging_dir, defines=defines)
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
428
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
429 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
430 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
431
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
432 source = wix_dir / 'mercurial.wxs'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
433 defines['Version'] = version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
434 defines['Comments'] = 'Installs Mercurial version %s' % version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
435 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
436 if extra_features:
1711f5813a63 wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents: 42048
diff changeset
437 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
438 defines['MercurialExtraFeatures'] = ';'.join(extra_features)
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
439
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
440 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
441
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
442 msi_path = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
443 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
444 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
445
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
446 args = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
447 str(wix_path / 'light.exe'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
448 '-nologo',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
449 '-ext',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
450 'WixUIExtension',
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
451 '-sw1076',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
452 '-spdb',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
453 '-o',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
454 str(msi_path),
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
455 ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
456
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
457 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
458 assert source.endswith('.wxs')
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
459 source = os.path.basename(source)
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
460 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
461
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
462 args.extend(
43623
94eac340d212 packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43522
diff changeset
463 [str(build_dir / 'stage.wixobj'), str(build_dir / 'mercurial.wixobj'),]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
464 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
465
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
466 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
467
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
468 print('%s created' % msi_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
469
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
470 return {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
471 'msi_path': msi_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
472 }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
473
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
474
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
475 def build_signed_installer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
476 source_dir: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
477 python_exe: pathlib.Path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
478 name: str,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
479 version=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
480 subject_name=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
481 cert_path=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
482 cert_password=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
483 timestamp_url=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
484 extra_packages_script=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
485 extra_wxs=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
486 extra_features=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
487 ):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
488 """Build an installer with signed executables."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
489
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
490 post_build_fn = make_post_build_signing_fn(
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
491 name,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
492 subject_name=subject_name,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
493 cert_path=cert_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
494 cert_password=cert_password,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
495 timestamp_url=timestamp_url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
496 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
497
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
498 info = build_installer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
499 source_dir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
500 python_exe=python_exe,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
501 msi_name=name.lower(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
502 version=version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
503 post_build_fn=post_build_fn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
504 extra_packages_script=extra_packages_script,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
505 extra_wxs=extra_wxs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
506 extra_features=extra_features,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
507 )
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
508
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
509 description = '%s %s' % (name, version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
510
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
511 sign_with_signtool(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
512 info['msi_path'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
513 description,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
514 subject_name=subject_name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
515 cert_path=cert_path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
516 cert_password=cert_password,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
517 timestamp_url=timestamp_url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42049
diff changeset
518 )