Mercurial > hg
annotate contrib/packaging/hgpackaging/wix.py @ 44223:481caa4a2244 stable
packaging: bundle dulwich, keyring, and pywin32-ctypes with WiX too
TortoiseHg installs these, which is possibly where they originated (though I
would have thought it more likely to be in the WiX installer, given its
heritage). When I was working on the TortoiseHg app for Mac (which uses the
similar `py2app`), it wasn't possible to use the keyring extension (even
externally) without bundling this keyring package into the app. Assuming the
same principle applies here, these would enable some common extensions. One of
the things that the TortoiseHg packager on macOS does now is it adds the user's
local `site-packages` directory to `sys.path`. That would allow the user to
install these critical modules in cases like this. But that can probably wait
for py3 packaging.
The only difference in the installed packages that I see now is WiX also bundles
distutils for some reason. I suppose that's not harming anything, so I'm not
touching it.
The only orphans in the install directories when comparing WiX and Inno now is
the Copying.txt vs COPYING.rtf, the two uninstaller files for Inno, and a
`Mercurial.url` file in Inno. I have no idea what that is, and it has *.ini
syntax with a single field pointing to the Mercurial homepage.
Differential Revision: https://phab.mercurial-scm.org/D8062
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 01 Feb 2020 00:58:34 -0500 |
parents | a70108a3d7cc |
children | e2589b9e4562 |
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, |
44220
a70108a3d7cc
packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents:
44173
diff
changeset
|
27 normalize_windows_version, |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
28 process_install_rules, |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
29 sign_with_signtool, |
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 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
33 EXTRA_PACKAGES = { |
44223
481caa4a2244
packaging: bundle dulwich, keyring, and pywin32-ctypes with WiX too
Matt Harbison <matt_harbison@yahoo.com>
parents:
44220
diff
changeset
|
34 'dulwich', |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
35 'distutils', |
44223
481caa4a2244
packaging: bundle dulwich, keyring, and pywin32-ctypes with WiX too
Matt Harbison <matt_harbison@yahoo.com>
parents:
44220
diff
changeset
|
36 'keyring', |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
37 'pygments', |
44223
481caa4a2244
packaging: bundle dulwich, keyring, and pywin32-ctypes with WiX too
Matt Harbison <matt_harbison@yahoo.com>
parents:
44220
diff
changeset
|
38 'win32ctypes', |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
39 } |
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 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
42 EXTRA_INSTALL_RULES = [ |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
43 ('contrib/packaging/wix/COPYING.rtf', 'COPYING.rtf'), |
44153
e4344e463c0c
packaging: rename hgrc.d to defaultrc for Windows config files next to the exe
Matt Harbison <matt_harbison@yahoo.com>
parents:
43623
diff
changeset
|
44 ('contrib/win32/mercurial.ini', 'defaultrc/mercurial.rc'), |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
45 ] |
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 STAGING_REMOVE_FILES = [ |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
48 # We use the RTF variant. |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
49 'copying.txt', |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
50 ] |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
51 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
52 SHORTCUTS = { |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
53 # hg.1.html' |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
54 '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
|
55 'Name': 'Mercurial Command Reference', |
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 # hgignore.5.html |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
58 '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
|
59 'Name': 'Mercurial Ignore 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 # hgrc.5.html |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
62 '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
|
63 'Name': 'Mercurial Configuration Files', |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
64 }, |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
65 } |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
66 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
67 |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
68 def find_version(source_dir: pathlib.Path): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
69 version_py = source_dir / 'mercurial' / '__version__.py' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
70 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
71 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
|
72 source = fh.read().strip() |
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 m = re.search('version = b"(.*)"', source) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
75 return m.group(1) |
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 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
78 def ensure_vc90_merge_modules(build_dir): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
79 x86 = ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
80 download_entry( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
81 'vc9-crt-x86-msm', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
82 build_dir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
83 local_name='microsoft.vcxx.crt.x86_msm.msm', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
84 )[0], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
85 download_entry( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
86 'vc9-crt-x86-msm-policy', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
87 build_dir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
88 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
|
89 )[0], |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
90 ) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
91 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
92 x64 = ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
93 download_entry( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
94 'vc9-crt-x64-msm', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
95 build_dir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
96 local_name='microsoft.vcxx.crt.x64_msm.msm', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
97 )[0], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
98 download_entry( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
99 'vc9-crt-x64-msm-policy', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
100 build_dir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
101 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
|
102 )[0], |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
103 ) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
104 return { |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
105 'x86': x86, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
106 'x64': x64, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
107 } |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
108 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
109 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
110 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
|
111 args = [ |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
112 str(wix / 'candle.exe'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
113 '-nologo', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
114 str(wxs), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
115 '-dSourceDir=%s' % source_dir, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
116 ] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
117 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
118 if defines: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
119 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
|
120 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
121 subprocess.run(args, cwd=str(cwd), check=True) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
122 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
123 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
124 def make_post_build_signing_fn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
125 name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
126 subject_name=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
127 cert_path=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
128 cert_password=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
129 timestamp_url=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
130 ): |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
131 """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
|
132 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
133 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
|
134 description = '%s %s' % (name, version) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
135 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
136 sign_with_signtool( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
137 dist_dir / 'hg.exe', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
138 description, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
139 subject_name=subject_name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
140 cert_path=cert_path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
141 cert_password=cert_password, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
142 timestamp_url=timestamp_url, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
143 ) |
41952
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 return post_build_sign |
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 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
148 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
|
149 """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
|
150 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
151 # 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
|
152 # 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
|
153 # 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
|
154 # 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
|
155 |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41956
diff
changeset
|
156 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
|
157 '<?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
|
158 '<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
|
159 '</Wix>' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
160 ) |
41957
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41956
diff
changeset
|
161 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
162 # 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
|
163 # 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
|
164 manifest = collections.defaultdict(dict) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
165 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
166 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
|
167 dirs.sort() |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
168 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
169 root = pathlib.Path(root) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
170 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
|
171 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
172 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
|
173 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
|
174 manifest.setdefault(parent, {}) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
175 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
176 for f in sorted(files): |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
177 full = root / f |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
178 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
|
179 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
180 component_groups = collections.defaultdict(list) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
181 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
182 # 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
|
183 # 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
|
184 # 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
|
185 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
|
186 # 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
|
187 # is special. |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
188 if dir_name == '.': |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
189 parent_directory_id = 'INSTALLDIR' |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
190 else: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
191 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
|
192 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
193 fragment = doc.createElement('Fragment') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
194 directory_ref = doc.createElement('DirectoryRef') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
195 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
|
196 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
197 # 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
|
198 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
|
199 if ( |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
200 dir_name == '.' |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
201 and '/' not in possible_child |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
202 and possible_child != '.' |
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 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
|
205 name = possible_child |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
206 else: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
207 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
|
208 continue |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
209 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
|
210 if '/' in name: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
211 continue |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
212 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
213 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
|
214 '/', '.' |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
215 ) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
216 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
217 directory = doc.createElement('Directory') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
218 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
|
219 directory.setAttribute('Name', name) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
220 directory_ref.appendChild(directory) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
221 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
222 # 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
|
223 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
|
224 if dir_name == '.': |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
225 full_rel = rel |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
226 else: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
227 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
|
228 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
229 component_unique_id = ( |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
230 '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
|
231 % full_rel |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
232 ) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
233 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
|
234 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
|
235 '-', '_' |
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 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
238 component = doc.createElement('Component') |
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 component.setAttribute('Id', component_id) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
241 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
|
242 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
|
243 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
244 # 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
|
245 if dir_name == '.': |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
246 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
|
247 elif '/' in dir_name: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
248 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
|
249 component_id |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
250 ) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
251 else: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
252 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
|
253 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
254 unique_id = ( |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
255 '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
|
256 ) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
257 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
|
258 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
259 # 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
|
260 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
|
261 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
|
262 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
263 file_element = doc.createElement('File') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
264 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
|
265 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
|
266 file_element.setAttribute('KeyPath', 'yes') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
267 file_element.setAttribute('ReadOnly', 'yes') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
268 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
269 component.appendChild(file_element) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
270 directory_ref.appendChild(component) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
271 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
272 fragment.appendChild(directory_ref) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
273 doc.documentElement.appendChild(fragment) |
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 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
|
276 fragment = doc.createElement('Fragment') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
277 component_group = doc.createElement('ComponentGroup') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
278 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
|
279 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
280 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
|
281 component_ref = doc.createElement('ComponentRef') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
282 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
|
283 component_group.appendChild(component_ref) |
41957
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41956
diff
changeset
|
284 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
285 fragment.appendChild(component_group) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
286 doc.documentElement.appendChild(fragment) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
287 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
288 # 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
|
289 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
|
290 els = doc.getElementsByTagName('File') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
291 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
|
292 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
293 if not els: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
294 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
|
295 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
296 for el in els: |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
297 shortcut = doc.createElement('Shortcut') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
298 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
|
299 shortcut.setAttribute('Directory', 'ProgramMenuDir') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
300 shortcut.setAttribute('Icon', 'hgIcon.ico') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
301 shortcut.setAttribute('IconIndex', '0') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
302 shortcut.setAttribute('Advertise', 'yes') |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
303 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
|
304 shortcut.setAttribute(k, v) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
305 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
306 el.appendChild(shortcut) |
41957
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41956
diff
changeset
|
307 |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41956
diff
changeset
|
308 return doc.toprettyxml() |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41956
diff
changeset
|
309 |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41956
diff
changeset
|
310 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
311 def build_installer( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
312 source_dir: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
313 python_exe: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
314 msi_name='mercurial', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
315 version=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
316 post_build_fn=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
317 extra_packages_script=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
318 extra_wxs: typing.Optional[typing.Dict[str, str]] = None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
319 extra_features: typing.Optional[typing.List[str]] = None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
320 ): |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
321 """Build a WiX MSI installer. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
322 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
323 ``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
|
324 ``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
|
325 ``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
|
326 ``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
|
327 ``mercurial/__version__.py`` will be consulted. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
328 ``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
|
329 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
|
330 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
|
331 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
|
332 ``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
|
333 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
|
334 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
|
335 should be included in the exe. |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
336 ``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
|
337 ``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
|
338 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
|
339 """ |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
340 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
|
341 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
342 hg_build_dir = source_dir / 'build' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
343 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
|
344 wix_dir = source_dir / 'contrib' / 'packaging' / 'wix' |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
345 |
41956
39f65c506899
wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41952
diff
changeset
|
346 requirements_txt = wix_dir / 'requirements.txt' |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
347 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
348 build_py2exe( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
349 source_dir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
350 hg_build_dir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
351 python_exe, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
352 'wix', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
353 requirements_txt, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
354 extra_packages=EXTRA_PACKAGES, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
355 extra_packages_script=extra_packages_script, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
356 ) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
357 |
44172
2251b6cde170
wix: always normalize version string
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44171
diff
changeset
|
358 orig_version = version or find_version(source_dir) |
44220
a70108a3d7cc
packaging: move the version normalization function to the util module
Matt Harbison <matt_harbison@yahoo.com>
parents:
44173
diff
changeset
|
359 version = normalize_windows_version(orig_version) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
360 print('using version string: %s' % version) |
44172
2251b6cde170
wix: always normalize version string
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44171
diff
changeset
|
361 if version != orig_version: |
2251b6cde170
wix: always normalize version string
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44171
diff
changeset
|
362 print('(normalized from: %s)' % orig_version) |
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 if post_build_fn: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
365 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
|
366 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
367 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
|
368 staging_dir = build_dir / 'stage' |
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 build_dir.mkdir(exist_ok=True) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
371 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
372 # 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
|
373 if staging_dir.exists(): |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
374 print('purging %s' % staging_dir) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
375 shutil.rmtree(staging_dir) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
376 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
377 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
|
378 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
379 # 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
|
380 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
|
381 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
382 # 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
|
383 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
|
384 p = staging_dir / f |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
385 if p.exists(): |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
386 print('removing %s' % p) |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
387 p.unlink() |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
388 |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
389 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
|
390 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
|
391 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
392 if not wix_path.exists(): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
393 extract_zip_to_directory(wix_pkg, wix_path) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
394 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
395 ensure_vc90_merge_modules(hg_build_dir) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
396 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
397 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
|
398 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
399 defines = {'Platform': arch} |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
400 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
401 # 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
|
402 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
|
403 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
|
404 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
|
405 |
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
406 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
|
407 |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
408 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
|
409 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
|
410 |
41956
39f65c506899
wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41952
diff
changeset
|
411 source = wix_dir / 'mercurial.wxs' |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
412 defines['Version'] = version |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
413 defines['Comments'] = 'Installs Mercurial version %s' % version |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
414 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
|
415 if extra_features: |
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
416 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
|
417 defines['MercurialExtraFeatures'] = ';'.join(extra_features) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
418 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
419 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
|
420 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
421 msi_path = ( |
44173
62111bc5ff87
wix: use original version string for MSI filename
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44172
diff
changeset
|
422 source_dir / 'dist' / ('%s-%s-%s.msi' % (msi_name, orig_version, arch)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
423 ) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
424 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
425 args = [ |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
426 str(wix_path / 'light.exe'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
427 '-nologo', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
428 '-ext', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
429 'WixUIExtension', |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
430 '-sw1076', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
431 '-spdb', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
432 '-o', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
433 str(msi_path), |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
434 ] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
435 |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
436 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
|
437 assert source.endswith('.wxs') |
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
438 source = os.path.basename(source) |
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
439 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
|
440 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
441 args.extend( |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
442 [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
|
443 ) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
444 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
445 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
|
446 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
447 print('%s created' % msi_path) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
448 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
449 return { |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
450 'msi_path': msi_path, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
451 } |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
452 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
453 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
454 def build_signed_installer( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
455 source_dir: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
456 python_exe: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
457 name: str, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
458 version=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
459 subject_name=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
460 cert_path=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
461 cert_password=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
462 timestamp_url=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
463 extra_packages_script=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
464 extra_wxs=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
465 extra_features=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
466 ): |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
467 """Build an installer with signed executables.""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
468 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
469 post_build_fn = make_post_build_signing_fn( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
470 name, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
471 subject_name=subject_name, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
472 cert_path=cert_path, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
473 cert_password=cert_password, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
474 timestamp_url=timestamp_url, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
475 ) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
476 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
477 info = build_installer( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
478 source_dir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
479 python_exe=python_exe, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
480 msi_name=name.lower(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
481 version=version, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
482 post_build_fn=post_build_fn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
483 extra_packages_script=extra_packages_script, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
484 extra_wxs=extra_wxs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
485 extra_features=extra_features, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
486 ) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
487 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
488 description = '%s %s' % (name, version) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
489 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
490 sign_with_signtool( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
491 info['msi_path'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
492 description, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
493 subject_name=subject_name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
494 cert_path=cert_path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
495 cert_password=cert_password, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
496 timestamp_url=timestamp_url, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42049
diff
changeset
|
497 ) |