##// END OF EJS Templates
packaging: bundle the default mercurial.ini template with Inno also...
Matt Harbison -
r44709:a8786727 stable
parent child Browse files
Show More
@@ -1,165 +1,173 b''
1 1 # inno.py - Inno Setup functionality.
2 2 #
3 3 # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 # no-check-code because Python 3 native.
9 9
10 10 import os
11 11 import pathlib
12 12 import shutil
13 13 import subprocess
14 14
15 15 import jinja2
16 16
17 17 from .py2exe import (
18 18 build_py2exe,
19 19 stage_install,
20 20 )
21 21 from .util import (
22 22 find_vc_runtime_files,
23 23 normalize_windows_version,
24 process_install_rules,
24 25 read_version_py,
25 26 )
26 27
27 28 EXTRA_PACKAGES = {
28 29 'dulwich',
29 30 'keyring',
30 31 'pygments',
31 32 'win32ctypes',
32 33 }
33 34
35 EXTRA_INSTALL_RULES = [
36 ('contrib/win32/mercurial.ini', 'defaultrc/mercurial.rc'),
37 ]
38
34 39 PACKAGE_FILES_METADATA = {
35 40 'ReadMe.html': 'Flags: isreadme',
36 41 }
37 42
38 43
39 44 def build(
40 45 source_dir: pathlib.Path,
41 46 build_dir: pathlib.Path,
42 47 python_exe: pathlib.Path,
43 48 iscc_exe: pathlib.Path,
44 49 version=None,
45 50 ):
46 51 """Build the Inno installer.
47 52
48 53 Build files will be placed in ``build_dir``.
49 54
50 55 py2exe's setup.py doesn't use setuptools. It doesn't have modern logic
51 56 for finding the Python 2.7 toolchain. So, we require the environment
52 57 to already be configured with an active toolchain.
53 58 """
54 59 if not iscc_exe.exists():
55 60 raise Exception('%s does not exist' % iscc_exe)
56 61
57 62 vc_x64 = r'\x64' in os.environ.get('LIB', '')
58 63 arch = 'x64' if vc_x64 else 'x86'
59 64 inno_source_dir = source_dir / 'contrib' / 'packaging' / 'inno'
60 65 inno_build_dir = build_dir / ('inno-%s' % arch)
61 66 staging_dir = inno_build_dir / 'stage'
62 67
63 68 requirements_txt = (
64 69 source_dir / 'contrib' / 'packaging' / 'inno' / 'requirements.txt'
65 70 )
66 71
67 72 inno_build_dir.mkdir(parents=True, exist_ok=True)
68 73
69 74 build_py2exe(
70 75 source_dir,
71 76 build_dir,
72 77 python_exe,
73 78 'inno',
74 79 requirements_txt,
75 80 extra_packages=EXTRA_PACKAGES,
76 81 )
77 82
78 83 # Purge the staging directory for every build so packaging is
79 84 # pristine.
80 85 if staging_dir.exists():
81 86 print('purging %s' % staging_dir)
82 87 shutil.rmtree(staging_dir)
83 88
84 89 # Now assemble all the packaged files into the staging directory.
85 90 stage_install(source_dir, staging_dir)
86 91
92 # We also install some extra files.
93 process_install_rules(EXTRA_INSTALL_RULES, source_dir, staging_dir)
94
87 95 # hg.exe depends on VC9 runtime DLLs. Copy those into place.
88 96 for f in find_vc_runtime_files(vc_x64):
89 97 if f.name.endswith('.manifest'):
90 98 basename = 'Microsoft.VC90.CRT.manifest'
91 99 else:
92 100 basename = f.name
93 101
94 102 dest_path = staging_dir / basename
95 103
96 104 print('copying %s to %s' % (f, dest_path))
97 105 shutil.copyfile(f, dest_path)
98 106
99 107 # The final package layout is simply a mirror of the staging directory.
100 108 package_files = []
101 109 for root, dirs, files in os.walk(staging_dir):
102 110 dirs.sort()
103 111
104 112 root = pathlib.Path(root)
105 113
106 114 for f in sorted(files):
107 115 full = root / f
108 116 rel = full.relative_to(staging_dir)
109 117 if str(rel.parent) == '.':
110 118 dest_dir = '{app}'
111 119 else:
112 120 dest_dir = '{app}\\%s' % rel.parent
113 121
114 122 package_files.append(
115 123 {
116 124 'source': rel,
117 125 'dest_dir': dest_dir,
118 126 'metadata': PACKAGE_FILES_METADATA.get(str(rel), None),
119 127 }
120 128 )
121 129
122 130 print('creating installer')
123 131
124 132 # Install Inno files by rendering a template.
125 133 jinja_env = jinja2.Environment(
126 134 loader=jinja2.FileSystemLoader(str(inno_source_dir)),
127 135 # Need to change these to prevent conflict with Inno Setup.
128 136 comment_start_string='{##',
129 137 comment_end_string='##}',
130 138 )
131 139
132 140 try:
133 141 template = jinja_env.get_template('mercurial.iss')
134 142 except jinja2.TemplateSyntaxError as e:
135 143 raise Exception(
136 144 'template syntax error at %s:%d: %s'
137 145 % (e.name, e.lineno, e.message,)
138 146 )
139 147
140 148 content = template.render(package_files=package_files)
141 149
142 150 with (inno_build_dir / 'mercurial.iss').open('w', encoding='utf-8') as fh:
143 151 fh.write(content)
144 152
145 153 # Copy additional files used by Inno.
146 154 for p in ('mercurial.ico', 'postinstall.txt'):
147 155 shutil.copyfile(
148 156 source_dir / 'contrib' / 'win32' / p, inno_build_dir / p
149 157 )
150 158
151 159 args = [str(iscc_exe)]
152 160
153 161 if vc_x64:
154 162 args.append('/dARCH=x64')
155 163
156 164 if not version:
157 165 version = read_version_py(source_dir)
158 166
159 167 args.append('/dVERSION=%s' % version)
160 168 args.append('/dQUAD_VERSION=%s' % normalize_windows_version(version))
161 169
162 170 args.append('/Odist')
163 171 args.append(str(inno_build_dir / 'mercurial.iss'))
164 172
165 173 subprocess.run(args, cwd=str(source_dir), check=True)
General Comments 0
You need to be logged in to leave comments. Login now