comparison contrib/packaging/hgpackaging/wix.py @ 42047:715d3220ac4f

wix: add a hook for a prebuild script to inject extra libraries I need this to build packages for Google so we can bundle some extensions in the installed image. My assumption is that this is most interesting for the .msi images so I only wired it up there. I'm not thrilled with the interface this provides, but it was an easy way to retain debug messages on Windows while also having enough structure to know what lines are actually module names for py2exe. Still pending on my end: I need to bundle a couple of config files, and at least one data file. I'm open to advice on how to do those things, and how to do this better. Differential Revision: https://phab.mercurial-scm.org/D6164
author Augie Fackler <augie@google.com>
date Wed, 20 Mar 2019 13:18:37 -0400
parents 131d0b7c3940
children 978b03d5f66e
comparison
equal deleted inserted replaced
42046:4ee906aa7b60 42047:715d3220ac4f
175 175
176 return doc.toprettyxml() 176 return doc.toprettyxml()
177 177
178 178
179 def build_installer(source_dir: pathlib.Path, python_exe: pathlib.Path, 179 def build_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
180 msi_name='mercurial', version=None, post_build_fn=None): 180 msi_name='mercurial', version=None, post_build_fn=None,
181 extra_packages_script=None):
181 """Build a WiX MSI installer. 182 """Build a WiX MSI installer.
182 183
183 ``source_dir`` is the path to the Mercurial source tree to use. 184 ``source_dir`` is the path to the Mercurial source tree to use.
184 ``arch`` is the target architecture. either ``x86`` or ``x64``. 185 ``arch`` is the target architecture. either ``x86`` or ``x64``.
185 ``python_exe`` is the path to the Python executable to use/bundle. 186 ``python_exe`` is the path to the Python executable to use/bundle.
187 ``mercurial/__version__.py`` will be consulted. 188 ``mercurial/__version__.py`` will be consulted.
188 ``post_build_fn`` is a callable that will be called after building 189 ``post_build_fn`` is a callable that will be called after building
189 Mercurial but before invoking WiX. It can be used to e.g. facilitate 190 Mercurial but before invoking WiX. It can be used to e.g. facilitate
190 signing. It is passed the paths to the Mercurial source, build, and 191 signing. It is passed the paths to the Mercurial source, build, and
191 dist directories and the resolved Mercurial version. 192 dist directories and the resolved Mercurial version.
193 ``extra_packages_script`` is a command to be run to inject extra packages
194 into the py2exe binary. It should stage packages into the virtualenv and
195 print a null byte followed by a newline-separated list of packages that
196 should be included in the exe.
192 """ 197 """
193 arch = 'x64' if r'\x64' in os.environ.get('LIB', '') else 'x86' 198 arch = 'x64' if r'\x64' in os.environ.get('LIB', '') else 'x86'
194 199
195 hg_build_dir = source_dir / 'build' 200 hg_build_dir = source_dir / 'build'
196 dist_dir = source_dir / 'dist' 201 dist_dir = source_dir / 'dist'
198 203
199 requirements_txt = wix_dir / 'requirements.txt' 204 requirements_txt = wix_dir / 'requirements.txt'
200 205
201 build_py2exe(source_dir, hg_build_dir, 206 build_py2exe(source_dir, hg_build_dir,
202 python_exe, 'wix', requirements_txt, 207 python_exe, 'wix', requirements_txt,
203 extra_packages=EXTRA_PACKAGES) 208 extra_packages=EXTRA_PACKAGES,
209 extra_packages_script=extra_packages_script)
204 210
205 version = version or normalize_version(find_version(source_dir)) 211 version = version or normalize_version(find_version(source_dir))
206 print('using version string: %s' % version) 212 print('using version string: %s' % version)
207 213
208 if post_build_fn: 214 if post_build_fn:
278 284
279 285
280 def build_signed_installer(source_dir: pathlib.Path, python_exe: pathlib.Path, 286 def build_signed_installer(source_dir: pathlib.Path, python_exe: pathlib.Path,
281 name: str, version=None, subject_name=None, 287 name: str, version=None, subject_name=None,
282 cert_path=None, cert_password=None, 288 cert_path=None, cert_password=None,
283 timestamp_url=None): 289 timestamp_url=None, extra_packages_script=None):
284 """Build an installer with signed executables.""" 290 """Build an installer with signed executables."""
285 291
286 post_build_fn = make_post_build_signing_fn( 292 post_build_fn = make_post_build_signing_fn(
287 name, 293 name,
288 subject_name=subject_name, 294 subject_name=subject_name,
290 cert_password=cert_password, 296 cert_password=cert_password,
291 timestamp_url=timestamp_url) 297 timestamp_url=timestamp_url)
292 298
293 info = build_installer(source_dir, python_exe=python_exe, 299 info = build_installer(source_dir, python_exe=python_exe,
294 msi_name=name.lower(), version=version, 300 msi_name=name.lower(), version=version,
295 post_build_fn=post_build_fn) 301 post_build_fn=post_build_fn,
302 extra_packages_script=extra_packages_script)
296 303
297 description = '%s %s' % (name, version) 304 description = '%s %s' % (name, version)
298 305
299 sign_with_signtool(info['msi_path'], description, 306 sign_with_signtool(info['msi_path'], description,
300 subject_name=subject_name, cert_path=cert_path, 307 subject_name=subject_name, cert_path=cert_path,