author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Mon, 15 May 2023 08:55:34 +0200 | |
changeset 50468 | fd5507619d16 |
parent 48848 | 17d5e25b8e78 |
permissions | -rw-r--r-- |
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 |
|
47644
be37bb8d0c7c
packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents:
47210
diff
changeset
|
10 |
import json |
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 |
43623
94eac340d212
packaging: stage files and dynamically generate WiX installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43522
diff
changeset
|
13 |
import shutil |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
14 |
import typing |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41924
diff
changeset
|
15 |
|
47210
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
16 |
from .pyoxidizer import ( |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
17 |
build_docs_html, |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
18 |
run_pyoxidizer, |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
19 |
) |
44767
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
20 |
|
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
21 |
|
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
22 |
def build_installer_pyoxidizer( |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
23 |
source_dir: pathlib.Path, |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
24 |
target_triple: str, |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
25 |
msi_name='mercurial', |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
26 |
version=None, |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
27 |
extra_wxs: typing.Optional[typing.Dict[str, str]] = None, |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
28 |
extra_features: typing.Optional[typing.List[str]] = None, |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
29 |
signing_info: typing.Optional[typing.Dict[str, str]] = None, |
47644
be37bb8d0c7c
packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents:
47210
diff
changeset
|
30 |
extra_pyoxidizer_vars=None, |
44767
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
31 |
): |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
32 |
"""Build a WiX MSI installer using PyOxidizer.""" |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
33 |
hg_build_dir = source_dir / "build" |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
34 |
build_dir = hg_build_dir / ("wix-%s" % target_triple) |
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
35 |
|
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
36 |
build_dir.mkdir(parents=True, exist_ok=True) |
47210
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
37 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
38 |
# Need to ensure docs HTML is built because this isn't done as part of |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
39 |
# `pip install Mercurial`. |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
40 |
build_docs_html(source_dir) |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
41 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
42 |
build_vars = {} |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
43 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
44 |
if msi_name: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
45 |
build_vars["MSI_NAME"] = msi_name |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
46 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
47 |
if version: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
48 |
build_vars["VERSION"] = version |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
49 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
50 |
if extra_features: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
51 |
build_vars["EXTRA_MSI_FEATURES"] = ";".join(extra_features) |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
52 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
53 |
if signing_info: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
54 |
if signing_info["cert_path"]: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
55 |
build_vars["SIGNING_PFX_PATH"] = signing_info["cert_path"] |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
56 |
if signing_info["cert_password"]: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
57 |
build_vars["SIGNING_PFX_PASSWORD"] = signing_info["cert_password"] |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
58 |
if signing_info["subject_name"]: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
59 |
build_vars["SIGNING_SUBJECT_NAME"] = signing_info["subject_name"] |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
60 |
if signing_info["timestamp_url"]: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
61 |
build_vars["TIME_STAMP_SERVER_URL"] = signing_info["timestamp_url"] |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
62 |
|
47644
be37bb8d0c7c
packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents:
47210
diff
changeset
|
63 |
if extra_pyoxidizer_vars: |
be37bb8d0c7c
packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents:
47210
diff
changeset
|
64 |
build_vars.update(json.loads(extra_pyoxidizer_vars)) |
be37bb8d0c7c
packaging: add command line flag to add extra vars to pyoxidizer
Augie Fackler <augie@google.com>
parents:
47210
diff
changeset
|
65 |
|
47210
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
66 |
if extra_wxs: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
67 |
raise Exception( |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
68 |
"support for extra .wxs files has been temporarily dropped" |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
69 |
) |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
70 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
71 |
out_dir = run_pyoxidizer( |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
72 |
source_dir, |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
73 |
build_dir, |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
74 |
target_triple, |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
75 |
build_vars=build_vars, |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
76 |
target="msi", |
47208
df1767fa822d
packaging: rename run_pyoxidizer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
46364
diff
changeset
|
77 |
) |
44767
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
78 |
|
47210
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
79 |
msi_dir = out_dir / "msi" |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
80 |
msi_files = [f for f in os.listdir(msi_dir) if f.endswith(".msi")] |
44767
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
81 |
|
47210
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
82 |
if len(msi_files) != 1: |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
83 |
raise Exception("expected exactly 1 .msi file; got %d" % len(msi_files)) |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
84 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
85 |
msi_filename = msi_files[0] |
44767
234882d17814
packaging: support building WiX installers with PyOxidizer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44766
diff
changeset
|
86 |
|
47210
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
87 |
msi_path = msi_dir / msi_filename |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
88 |
dist_path = source_dir / "dist" / msi_filename |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
89 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
90 |
dist_path.parent.mkdir(parents=True, exist_ok=True) |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
91 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
92 |
shutil.copyfile(msi_path, dist_path) |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
93 |
|
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
94 |
return { |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
95 |
"msi_path": dist_path, |
73f1a10320d1
packaging: use PyOxidizer for producing WiX MSI installer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
47208
diff
changeset
|
96 |
} |