| 1 |
# wix.py - WiX installer functionality |
| 2 |
# |
| 3 |
# Copyright 2019 Gregory Szorc <[email protected]> |
| 4 |
# |
| 5 |
# This software may be used and distributed according to the terms of the |
| 6 |
# GNU General Public License version 2 or any later version. |
| 7 |
|
| 8 |
# no-check-code because Python 3 native. |
| 9 |
|
| 10 |
import json |
| 11 |
import os |
| 12 |
import pathlib |
| 13 |
import shutil |
| 14 |
import typing |
| 15 |
|
| 16 |
from .pyoxidizer import ( |
| 17 |
build_docs_html, |
| 18 |
run_pyoxidizer, |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
def build_installer_pyoxidizer( |
| 23 |
source_dir: pathlib.Path, |
| 24 |
target_triple: str, |
| 25 |
msi_name='mercurial', |
| 26 |
version=None, |
| 27 |
extra_wxs: typing.Optional[dict[str, str]] = None, |
| 28 |
extra_features: typing.Optional[list[str]] = None, |
| 29 |
signing_info: typing.Optional[dict[str, str]] = None, |
| 30 |
extra_pyoxidizer_vars=None, |
| 31 |
): |
| 32 |
"""Build a WiX MSI installer using PyOxidizer.""" |
| 33 |
hg_build_dir = source_dir / "build" |
| 34 |
build_dir = hg_build_dir / ("wix-%s" % target_triple) |
| 35 |
|
| 36 |
build_dir.mkdir(parents=True, exist_ok=True) |
| 37 |
|
| 38 |
# Need to ensure docs HTML is built because this isn't done as part of |
| 39 |
# `pip install Mercurial`. |
| 40 |
build_docs_html(source_dir) |
| 41 |
|
| 42 |
build_vars = {} |
| 43 |
|
| 44 |
if msi_name: |
| 45 |
build_vars["MSI_NAME"] = msi_name |
| 46 |
|
| 47 |
if version: |
| 48 |
build_vars["VERSION"] = version |
| 49 |
|
| 50 |
if extra_features: |
| 51 |
build_vars["EXTRA_MSI_FEATURES"] = ";".join(extra_features) |
| 52 |
|
| 53 |
if signing_info: |
| 54 |
if signing_info["cert_path"]: |
| 55 |
build_vars["SIGNING_PFX_PATH"] = signing_info["cert_path"] |
| 56 |
if signing_info["cert_password"]: |
| 57 |
build_vars["SIGNING_PFX_PASSWORD"] = signing_info["cert_password"] |
| 58 |
if signing_info["subject_name"]: |
| 59 |
build_vars["SIGNING_SUBJECT_NAME"] = signing_info["subject_name"] |
| 60 |
if signing_info["timestamp_url"]: |
| 61 |
build_vars["TIME_STAMP_SERVER_URL"] = signing_info["timestamp_url"] |
| 62 |
|
| 63 |
if extra_pyoxidizer_vars: |
| 64 |
build_vars.update(json.loads(extra_pyoxidizer_vars)) |
| 65 |
|
| 66 |
if extra_wxs: |
| 67 |
raise Exception( |
| 68 |
"support for extra .wxs files has been temporarily dropped" |
| 69 |
) |
| 70 |
|
| 71 |
out_dir = run_pyoxidizer( |
| 72 |
source_dir, |
| 73 |
build_dir, |
| 74 |
target_triple, |
| 75 |
build_vars=build_vars, |
| 76 |
target="msi", |
| 77 |
) |
| 78 |
|
| 79 |
msi_dir = out_dir / "msi" |
| 80 |
msi_files = [f for f in os.listdir(msi_dir) if f.endswith(".msi")] |
| 81 |
|
| 82 |
if len(msi_files) != 1: |
| 83 |
raise Exception("expected exactly 1 .msi file; got %d" % len(msi_files)) |
| 84 |
|
| 85 |
msi_filename = msi_files[0] |
| 86 |
|
| 87 |
msi_path = msi_dir / msi_filename |
| 88 |
dist_path = source_dir / "dist" / msi_filename |
| 89 |
|
| 90 |
dist_path.parent.mkdir(parents=True, exist_ok=True) |
| 91 |
|
| 92 |
shutil.copyfile(msi_path, dist_path) |
| 93 |
|
| 94 |
return { |
| 95 |
"msi_path": dist_path, |
| 96 |
} |