annotate contrib/packaging/hgpackaging/wix.py @ 42048:978b03d5f66e

wix: add support for additional wxs files As with my previous change for an --extra-prebuiild-script, I'm assuming this is predominantly useful in an enterprise environment and am only adding this to wix and not also to inno install scripts. Differential Revision: https://phab.mercurial-scm.org/D6179
author Augie Fackler <raf@durin42.com>
date Mon, 01 Apr 2019 16:21:47 -0400
parents 715d3220ac4f
children 1711f5813a63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
1 # wix.py - WiX installer functionality
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
2 #
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
3 # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
4 #
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
5 # This software may be used and distributed according to the terms of the
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
6 # GNU General Public License version 2 or any later version.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
7
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
8 # no-check-code because Python 3 native.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
9
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
10 import os
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
11 import pathlib
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
12 import re
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
13 import subprocess
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
14 import tempfile
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
15 import typing
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
16 import xml.dom.minidom
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
17
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
18 from .downloads import (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
19 download_entry,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
20 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
21 from .py2exe import (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
22 build_py2exe,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
23 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
24 from .util import (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
25 extract_zip_to_directory,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
26 sign_with_signtool,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
27 )
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
28
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 SUPPORT_WXS = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
31 ('contrib.wxs', r'contrib'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
32 ('dist.wxs', r'dist'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
33 ('doc.wxs', r'doc'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
34 ('help.wxs', r'mercurial\help'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
35 ('i18n.wxs', r'i18n'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
36 ('locale.wxs', r'mercurial\locale'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
37 ('templates.wxs', r'mercurial\templates'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
38 ]
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 EXTRA_PACKAGES = {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
42 'distutils',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
43 'pygments',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
44 }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
45
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
46
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
47 def find_version(source_dir: pathlib.Path):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
48 version_py = source_dir / 'mercurial' / '__version__.py'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
49
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
50 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
51 source = fh.read().strip()
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
52
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
53 m = re.search('version = b"(.*)"', source)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
54 return m.group(1)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
55
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
56
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
57 def normalize_version(version):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
58 """Normalize Mercurial version string so WiX accepts it.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
59
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
60 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
61 """
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
62
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
63 if '+' in version:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
64 version, extra = version.split('+', 1)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
65 else:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
66 extra = None
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
67
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
68 # 4.9rc0
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
69 if version[:-1].endswith('rc'):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
70 version = version[:-3]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
71
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
72 versions = [int(v) for v in version.split('.')]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
73 while len(versions) < 3:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
74 versions.append(0)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
75
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
76 major, minor, build = versions[:3]
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 if extra:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
79 # <commit count>-<hash>+<date>
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
80 build = int(extra.split('-')[0])
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
81
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
82 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
83
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 def ensure_vc90_merge_modules(build_dir):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
86 x86 = (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
87 download_entry('vc9-crt-x86-msm', build_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
88 local_name='microsoft.vcxx.crt.x86_msm.msm')[0],
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
89 download_entry('vc9-crt-x86-msm-policy', build_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
90 local_name='policy.x.xx.microsoft.vcxx.crt.x86_msm.msm')[0]
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
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
93 x64 = (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
94 download_entry('vc9-crt-x64-msm', build_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
95 local_name='microsoft.vcxx.crt.x64_msm.msm')[0],
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
96 download_entry('vc9-crt-x64-msm-policy', build_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
97 local_name='policy.x.xx.microsoft.vcxx.crt.x64_msm.msm')[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 {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
100 'x86': x86,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
101 'x64': x64,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
102 }
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
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
105 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
106 args = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
107 str(wix / 'candle.exe'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
108 '-nologo',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
109 str(wxs),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
110 '-dSourceDir=%s' % source_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
111 ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
112
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
113 if defines:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
114 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
115
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
116 subprocess.run(args, cwd=str(cwd), check=True)
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
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
119 def make_post_build_signing_fn(name, subject_name=None, cert_path=None,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
120 cert_password=None, timestamp_url=None):
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
121 """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
122
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
123 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
124 description = '%s %s' % (name, version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
125
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
126 sign_with_signtool(dist_dir / 'hg.exe', description,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
127 subject_name=subject_name, cert_path=cert_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
128 cert_password=cert_password,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
129 timestamp_url=timestamp_url)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
130
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
131 return post_build_sign
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
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
134 LIBRARIES_XML = '''
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
135 <?xml version="1.0" encoding="utf-8"?>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
136 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
137
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
138 <?include {wix_dir}/guids.wxi ?>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
139 <?include {wix_dir}/defines.wxi ?>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
140
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
141 <Fragment>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
142 <DirectoryRef Id="INSTALLDIR" FileSource="$(var.SourceDir)">
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
143 <Directory Id="libdir" Name="lib" FileSource="$(var.SourceDir)/lib">
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
144 <Component Id="libOutput" Guid="$(var.lib.guid)" Win64='$(var.IsX64)'>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
145 </Component>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
146 </Directory>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
147 </DirectoryRef>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
148 </Fragment>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
149 </Wix>
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
150 '''.lstrip()
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
151
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
152
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
153 def make_libraries_xml(wix_dir: pathlib.Path, dist_dir: pathlib.Path):
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
154 """Make XML data for library components WXS."""
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
155 # We can't use ElementTree because it doesn't handle the
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
156 # <?include ?> directives.
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
157 doc = xml.dom.minidom.parseString(
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
158 LIBRARIES_XML.format(wix_dir=str(wix_dir)))
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
159
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
160 component = doc.getElementsByTagName('Component')[0]
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
161
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
162 f = doc.createElement('File')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
163 f.setAttribute('Name', 'library.zip')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
164 f.setAttribute('KeyPath', 'yes')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
165 component.appendChild(f)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
166
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
167 lib_dir = dist_dir / 'lib'
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
168
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
169 for p in sorted(lib_dir.iterdir()):
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
170 if not p.name.endswith(('.dll', '.pyd')):
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
171 continue
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
172
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
173 f = doc.createElement('File')
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
174 f.setAttribute('Name', p.name)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
175 component.appendChild(f)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
176
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
177 return doc.toprettyxml()
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
178
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
179
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
180 def build_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
42047
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
181 msi_name='mercurial', version=None, post_build_fn=None,
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
182 extra_packages_script: typing.Optional[str]=None,
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
183 extra_wxs:typing.Optional[typing.Dict[str,str]]=None):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
184 """Build a WiX MSI installer.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
185
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
186 ``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
187 ``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
188 ``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
189 ``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
190 ``mercurial/__version__.py`` will be consulted.
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
191 ``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
192 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
193 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
194 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
195 ``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
196 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
197 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
198 should be included in the exe.
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
199 ``extra_wxs`` is a dict of {wxs_name: working_dir_for_wxs_build}.
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
200 """
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
201 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
202
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
203 hg_build_dir = source_dir / 'build'
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
204 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
205 wix_dir = source_dir / 'contrib' / 'packaging' / 'wix'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
206
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
207 requirements_txt = wix_dir / 'requirements.txt'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
208
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
209 build_py2exe(source_dir, hg_build_dir,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
210 python_exe, 'wix', requirements_txt,
42047
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
211 extra_packages=EXTRA_PACKAGES,
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
212 extra_packages_script=extra_packages_script)
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
213
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
214 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
215 print('using version string: %s' % version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
216
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
217 if post_build_fn:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
218 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
219
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
220 build_dir = hg_build_dir / ('wix-%s' % arch)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
221
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
222 build_dir.mkdir(exist_ok=True)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
223
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
224 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
225 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
226
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
227 if not wix_path.exists():
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
228 extract_zip_to_directory(wix_pkg, wix_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
229
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
230 ensure_vc90_merge_modules(hg_build_dir)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
231
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
232 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
233
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
234 defines = {'Platform': arch}
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
235
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
236 for wxs, rel_path in SUPPORT_WXS:
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
237 wxs = wix_dir / wxs
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
238 wxs_source_dir = source_dir / rel_path
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
239 run_candle(wix_path, build_dir, wxs, wxs_source_dir, defines=defines)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
240
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
241 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
242 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
243
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
244 # candle.exe doesn't like when we have an open handle on the file.
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
245 # So use TemporaryDirectory() instead of NamedTemporaryFile().
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
246 with tempfile.TemporaryDirectory() as td:
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
247 td = pathlib.Path(td)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
248
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
249 tf = td / 'library.wxs'
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
250 with tf.open('w') as fh:
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
251 fh.write(make_libraries_xml(wix_dir, dist_dir))
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
252
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
253 run_candle(wix_path, build_dir, tf, dist_dir, defines=defines)
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
254
41956
39f65c506899 wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41952
diff changeset
255 source = wix_dir / 'mercurial.wxs'
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
256 defines['Version'] = version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
257 defines['Comments'] = 'Installs Mercurial version %s' % version
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
258 defines['VCRedistSrcDir'] = str(hg_build_dir)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
259
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
260 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
261
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
262 msi_path = source_dir / 'dist' / (
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
263 '%s-%s-%s.msi' % (msi_name, version, arch))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
264
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
265 args = [
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
266 str(wix_path / 'light.exe'),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
267 '-nologo',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
268 '-ext', 'WixUIExtension',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
269 '-sw1076',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
270 '-spdb',
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
271 '-o', str(msi_path),
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
272 ]
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
273
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
274 for source, rel_path in SUPPORT_WXS:
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
275 assert source.endswith('.wxs')
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
276 args.append(str(build_dir / ('%s.wixobj' % source[:-4])))
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
277
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
278 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
279 assert source.endswith('.wxs')
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
280 source = os.path.basename(source)
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
281 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
282
41957
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
283 args.extend([
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
284 str(build_dir / 'library.wixobj'),
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
285 str(build_dir / 'mercurial.wixobj'),
131d0b7c3940 wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41956
diff changeset
286 ])
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
287
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
288 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
289
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
290 print('%s created' % msi_path)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
291
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
292 return {
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
293 'msi_path': msi_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
294 }
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
295
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
296
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
297 def build_signed_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
298 name: str, version=None, subject_name=None,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
299 cert_path=None, cert_password=None,
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
300 timestamp_url=None, extra_packages_script=None,
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
301 extra_wxs=None):
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
302 """Build an installer with signed executables."""
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
303
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
304 post_build_fn = make_post_build_signing_fn(
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
305 name,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
306 subject_name=subject_name,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
307 cert_path=cert_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
308 cert_password=cert_password,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
309 timestamp_url=timestamp_url)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
310
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
311 info = build_installer(source_dir, python_exe=python_exe,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
312 msi_name=name.lower(), version=version,
42047
715d3220ac4f wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents: 41957
diff changeset
313 post_build_fn=post_build_fn,
42048
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
314 extra_packages_script=extra_packages_script,
978b03d5f66e wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents: 42047
diff changeset
315 extra_wxs=extra_wxs)
41952
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
316
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
317 description = '%s %s' % (name, version)
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
318
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
319 sign_with_signtool(info['msi_path'], description,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
320 subject_name=subject_name, cert_path=cert_path,
b83de9150c1c packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41924
diff changeset
321 cert_password=cert_password, timestamp_url=timestamp_url)