author | Augie Fackler <augie@google.com> |
Wed, 29 May 2019 10:00:30 -0400 | |
changeset 42410 | c2deb2512823 |
parent 42049 | 1711f5813a63 |
child 43076 | 2372284d9457 |
permissions | -rw-r--r-- |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
1 |
# wix.py - WiX installer functionality |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
2 |
# |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
3 |
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
4 |
# |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
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:
41929
diff
changeset
|
7 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
8 |
# no-check-code because Python 3 native. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
9 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
10 |
import os |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
11 |
import pathlib |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
12 |
import re |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
13 |
import subprocess |
41962
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
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 |
41962
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
16 |
import xml.dom.minidom |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
17 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
18 |
from .downloads import ( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
19 |
download_entry, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
20 |
) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
21 |
from .py2exe import ( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
22 |
build_py2exe, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
23 |
) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
24 |
from .util import ( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
25 |
extract_zip_to_directory, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
26 |
sign_with_signtool, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
27 |
) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
28 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
29 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
30 |
SUPPORT_WXS = [ |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
31 |
('contrib.wxs', r'contrib'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
32 |
('dist.wxs', r'dist'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
33 |
('doc.wxs', r'doc'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
34 |
('help.wxs', r'mercurial\help'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
35 |
('i18n.wxs', r'i18n'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
36 |
('locale.wxs', r'mercurial\locale'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
37 |
('templates.wxs', r'mercurial\templates'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
38 |
] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
39 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
40 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
41 |
EXTRA_PACKAGES = { |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
42 |
'distutils', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
43 |
'pygments', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
44 |
} |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
45 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
46 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
47 |
def find_version(source_dir: pathlib.Path): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
48 |
version_py = source_dir / 'mercurial' / '__version__.py' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
49 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
51 |
source = fh.read().strip() |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
52 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
53 |
m = re.search('version = b"(.*)"', source) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
54 |
return m.group(1) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
55 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
56 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
57 |
def normalize_version(version): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
58 |
"""Normalize Mercurial version string so WiX accepts it. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
59 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
61 |
""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
62 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
63 |
if '+' in version: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
64 |
version, extra = version.split('+', 1) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
65 |
else: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
66 |
extra = None |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
67 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
68 |
# 4.9rc0 |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
69 |
if version[:-1].endswith('rc'): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
70 |
version = version[:-3] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
71 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
72 |
versions = [int(v) for v in version.split('.')] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
73 |
while len(versions) < 3: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
74 |
versions.append(0) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
75 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
76 |
major, minor, build = versions[:3] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
77 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
78 |
if extra: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
79 |
# <commit count>-<hash>+<date> |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
80 |
build = int(extra.split('-')[0]) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
81 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
83 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
84 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
85 |
def ensure_vc90_merge_modules(build_dir): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
86 |
x86 = ( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
87 |
download_entry('vc9-crt-x86-msm', build_dir, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
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:
41929
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:
41929
diff
changeset
|
91 |
) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
92 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
93 |
x64 = ( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
94 |
download_entry('vc9-crt-x64-msm', build_dir, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
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:
41929
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:
41929
diff
changeset
|
98 |
) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
99 |
return { |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
100 |
'x86': x86, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
101 |
'x64': x64, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
102 |
} |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
103 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
104 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
106 |
args = [ |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
107 |
str(wix / 'candle.exe'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
108 |
'-nologo', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
109 |
str(wxs), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
110 |
'-dSourceDir=%s' % source_dir, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
111 |
] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
112 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
113 |
if defines: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
115 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
116 |
subprocess.run(args, cwd=str(cwd), check=True) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
117 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
118 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
120 |
cert_password=None, timestamp_url=None): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
122 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41929
diff
changeset
|
124 |
description = '%s %s' % (name, version) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
125 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
126 |
sign_with_signtool(dist_dir / 'hg.exe', description, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
127 |
subject_name=subject_name, cert_path=cert_path, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
128 |
cert_password=cert_password, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
129 |
timestamp_url=timestamp_url) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
130 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
131 |
return post_build_sign |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
132 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
133 |
|
41962
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
134 |
LIBRARIES_XML = ''' |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
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:
41961
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:
41961
diff
changeset
|
137 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
138 |
<?include {wix_dir}/guids.wxi ?> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
139 |
<?include {wix_dir}/defines.wxi ?> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
140 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
141 |
<Fragment> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
142 |
<DirectoryRef Id="INSTALLDIR" FileSource="$(var.SourceDir)"> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
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:
41961
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:
41961
diff
changeset
|
145 |
</Component> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
146 |
</Directory> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
147 |
</DirectoryRef> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
148 |
</Fragment> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
149 |
</Wix> |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
150 |
'''.lstrip() |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
151 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
152 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
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:
41961
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:
41961
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:
41961
diff
changeset
|
156 |
# <?include ?> directives. |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
157 |
doc = xml.dom.minidom.parseString( |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
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:
41961
diff
changeset
|
159 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
160 |
component = doc.getElementsByTagName('Component')[0] |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
161 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
162 |
f = doc.createElement('File') |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
163 |
f.setAttribute('Name', 'library.zip') |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
164 |
f.setAttribute('KeyPath', 'yes') |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
165 |
component.appendChild(f) |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
166 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
167 |
lib_dir = dist_dir / 'lib' |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
168 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
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:
41961
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:
41961
diff
changeset
|
171 |
continue |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
172 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
173 |
f = doc.createElement('File') |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
174 |
f.setAttribute('Name', p.name) |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
175 |
component.appendChild(f) |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
176 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
177 |
return doc.toprettyxml() |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
178 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
179 |
|
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
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:
41962
diff
changeset
|
181 |
msi_name='mercurial', version=None, post_build_fn=None, |
42049
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
182 |
extra_packages_script=None, |
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
183 |
extra_wxs:typing.Optional[typing.Dict[str,str]]=None, |
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
184 |
extra_features:typing.Optional[typing.List[str]]=None): |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
185 |
"""Build a WiX MSI installer. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
186 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
187 |
``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:
41929
diff
changeset
|
188 |
``arch`` is the target architecture. either ``x86`` or ``x64``. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
189 |
``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:
41929
diff
changeset
|
190 |
``version`` is the Mercurial version string. If not defined, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
191 |
``mercurial/__version__.py`` will be consulted. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
192 |
``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:
41929
diff
changeset
|
193 |
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:
41929
diff
changeset
|
194 |
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:
41929
diff
changeset
|
195 |
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:
41962
diff
changeset
|
196 |
``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:
41962
diff
changeset
|
197 |
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:
41962
diff
changeset
|
198 |
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:
41962
diff
changeset
|
199 |
should be included in the exe. |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
200 |
``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
|
201 |
``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
|
202 |
the build. These must match Feature names in one of the wxs scripts. |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
203 |
""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
204 |
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:
41929
diff
changeset
|
205 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
206 |
hg_build_dir = source_dir / 'build' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
207 |
dist_dir = source_dir / 'dist' |
41961
39f65c506899
wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41957
diff
changeset
|
208 |
wix_dir = source_dir / 'contrib' / 'packaging' / 'wix' |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
209 |
|
41961
39f65c506899
wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41957
diff
changeset
|
210 |
requirements_txt = wix_dir / 'requirements.txt' |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
211 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
212 |
build_py2exe(source_dir, hg_build_dir, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
213 |
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:
41962
diff
changeset
|
214 |
extra_packages=EXTRA_PACKAGES, |
715d3220ac4f
wix: add a hook for a prebuild script to inject extra libraries
Augie Fackler <augie@google.com>
parents:
41962
diff
changeset
|
215 |
extra_packages_script=extra_packages_script) |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
216 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
217 |
version = version or normalize_version(find_version(source_dir)) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
218 |
print('using version string: %s' % version) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
219 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
220 |
if post_build_fn: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
221 |
post_build_fn(source_dir, hg_build_dir, dist_dir, version) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
222 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
223 |
build_dir = hg_build_dir / ('wix-%s' % arch) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
224 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
225 |
build_dir.mkdir(exist_ok=True) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
226 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
227 |
wix_pkg, wix_entry = download_entry('wix', hg_build_dir) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
228 |
wix_path = hg_build_dir / ('wix-%s' % wix_entry['version']) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
229 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
230 |
if not wix_path.exists(): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
231 |
extract_zip_to_directory(wix_pkg, wix_path) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
232 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
233 |
ensure_vc90_merge_modules(hg_build_dir) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
234 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
235 |
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:
41929
diff
changeset
|
236 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
237 |
defines = {'Platform': arch} |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
238 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
239 |
for wxs, rel_path in SUPPORT_WXS: |
41961
39f65c506899
wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41957
diff
changeset
|
240 |
wxs = wix_dir / wxs |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
241 |
wxs_source_dir = source_dir / rel_path |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
242 |
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:
41929
diff
changeset
|
243 |
|
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
|
41962
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
247 |
# 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:
41961
diff
changeset
|
248 |
# So use TemporaryDirectory() instead of NamedTemporaryFile(). |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
249 |
with tempfile.TemporaryDirectory() as td: |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
250 |
td = pathlib.Path(td) |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
251 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
252 |
tf = td / 'library.wxs' |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
253 |
with tf.open('w') as fh: |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
254 |
fh.write(make_libraries_xml(wix_dir, dist_dir)) |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
255 |
|
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
256 |
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:
41961
diff
changeset
|
257 |
|
41961
39f65c506899
wix: introduce variable to hold path to wix packaging directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41957
diff
changeset
|
258 |
source = wix_dir / 'mercurial.wxs' |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
259 |
defines['Version'] = version |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
260 |
defines['Comments'] = 'Installs Mercurial version %s' % version |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
261 |
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
|
262 |
if extra_features: |
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
263 |
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
|
264 |
defines['MercurialExtraFeatures'] = ';'.join(extra_features) |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
265 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
266 |
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:
41929
diff
changeset
|
267 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
268 |
msi_path = source_dir / 'dist' / ( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
269 |
'%s-%s-%s.msi' % (msi_name, version, arch)) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
270 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
271 |
args = [ |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
272 |
str(wix_path / 'light.exe'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
273 |
'-nologo', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
274 |
'-ext', 'WixUIExtension', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
275 |
'-sw1076', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
276 |
'-spdb', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
277 |
'-o', str(msi_path), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
278 |
] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
279 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
280 |
for source, rel_path in SUPPORT_WXS: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
281 |
assert source.endswith('.wxs') |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
282 |
args.append(str(build_dir / ('%s.wixobj' % source[:-4]))) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
283 |
|
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
284 |
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
|
285 |
assert source.endswith('.wxs') |
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
286 |
source = os.path.basename(source) |
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
287 |
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
|
288 |
|
41962
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
289 |
args.extend([ |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
290 |
str(build_dir / 'library.wixobj'), |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
291 |
str(build_dir / 'mercurial.wixobj'), |
131d0b7c3940
wix: autogenerate wxs file for library files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41961
diff
changeset
|
292 |
]) |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
293 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
294 |
subprocess.run(args, cwd=str(source_dir), check=True) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
295 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
296 |
print('%s created' % msi_path) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
297 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
298 |
return { |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
299 |
'msi_path': msi_path, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
300 |
} |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
301 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
302 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
303 |
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:
41929
diff
changeset
|
304 |
name: str, version=None, subject_name=None, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
305 |
cert_path=None, cert_password=None, |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
306 |
timestamp_url=None, extra_packages_script=None, |
42049
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
307 |
extra_wxs=None, extra_features=None): |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
308 |
"""Build an installer with signed executables.""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
309 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
310 |
post_build_fn = make_post_build_signing_fn( |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
311 |
name, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
312 |
subject_name=subject_name, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
313 |
cert_path=cert_path, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
314 |
cert_password=cert_password, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
315 |
timestamp_url=timestamp_url) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
316 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
317 |
info = build_installer(source_dir, python_exe=python_exe, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
318 |
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:
41962
diff
changeset
|
319 |
post_build_fn=post_build_fn, |
42048
978b03d5f66e
wix: add support for additional wxs files
Augie Fackler <raf@durin42.com>
parents:
42047
diff
changeset
|
320 |
extra_packages_script=extra_packages_script, |
42049
1711f5813a63
wix: add functionality to inject additional Features into installer
Augie Fackler <raf@durin42.com>
parents:
42048
diff
changeset
|
321 |
extra_wxs=extra_wxs, extra_features=extra_features) |
41957
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
322 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
323 |
description = '%s %s' % (name, version) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
324 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
325 |
sign_with_signtool(info['msi_path'], description, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
326 |
subject_name=subject_name, cert_path=cert_path, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41929
diff
changeset
|
327 |
cert_password=cert_password, timestamp_url=timestamp_url) |