##// END OF EJS Templates
packaging: don't use temporary directory...
Gregory Szorc -
r42079:5e923355 default
parent child Browse files
Show More
@@ -1,171 +1,167
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 import tempfile
15 14
16 15 from .downloads import (
17 16 download_entry,
18 17 )
19 18 from .util import (
20 19 extract_tar_to_directory,
21 20 extract_zip_to_directory,
22 21 find_vc_runtime_files,
23 22 )
24 23
25 24
26 25 PRINT_PYTHON_INFO = '''
27 26 import platform, sys; print("%s:%d" % (platform.architecture()[0], sys.version_info[0]))
28 27 '''.strip()
29 28
30 29
31 30 def build(source_dir: pathlib.Path, build_dir: pathlib.Path,
32 31 python_exe: pathlib.Path, iscc_exe: pathlib.Path,
33 32 version=None):
34 33 """Build the Inno installer.
35 34
36 35 Build files will be placed in ``build_dir``.
37 36
38 37 py2exe's setup.py doesn't use setuptools. It doesn't have modern logic
39 38 for finding the Python 2.7 toolchain. So, we require the environment
40 39 to already be configured with an active toolchain.
41 40 """
42 41 if not iscc_exe.exists():
43 42 raise Exception('%s does not exist' % iscc_exe)
44 43
45 44 if 'VCINSTALLDIR' not in os.environ:
46 45 raise Exception('not running from a Visual C++ build environment; '
47 46 'execute the "Visual C++ <version> Command Prompt" '
48 47 'application shortcut or a vcsvarsall.bat file')
49 48
50 49 # Identity x86/x64 and validate the environment matches the Python
51 50 # architecture.
52 51 vc_x64 = r'\x64' in os.environ['LIB']
53 52
54 53 res = subprocess.run(
55 54 [str(python_exe), '-c', PRINT_PYTHON_INFO],
56 55 capture_output=True, check=True)
57 56
58 57 py_arch, py_version = res.stdout.decode('utf-8').split(':')
59 58 py_version = int(py_version)
60 59
61 60 if vc_x64:
62 61 if py_arch != '64bit':
63 62 raise Exception('architecture mismatch: Visual C++ environment '
64 63 'is configured for 64-bit but Python is 32-bit')
65 64 else:
66 65 if py_arch != '32bit':
67 66 raise Exception('architecture mismatch: Visual C++ environment '
68 67 'is configured for 32-bit but Python is 64-bit')
69 68
70 69 if py_version != 2:
71 70 raise Exception('Only Python 2 is currently supported')
72 71
73 72 build_dir.mkdir(exist_ok=True)
74 73
75 74 gettext_pkg, gettext_entry = download_entry('gettext', build_dir)
76 75 gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0]
77 76 virtualenv_pkg, virtualenv_entry = download_entry('virtualenv', build_dir)
78 77 py2exe_pkg, py2exe_entry = download_entry('py2exe', build_dir)
79 78
80 79 venv_path = build_dir / ('venv-inno-%s' % ('x64' if vc_x64 else 'x86'))
81 80
82 81 gettext_root = build_dir / (
83 82 'gettext-win-%s' % gettext_entry['version'])
84 83
85 84 if not gettext_root.exists():
86 85 extract_zip_to_directory(gettext_pkg, gettext_root)
87 86 extract_zip_to_directory(gettext_dep_pkg, gettext_root)
88 87
89 88 # This assumes Python 2. We don't need virtualenv on Python 3.
90 89 virtualenv_src_path = build_dir / (
91 90 'virtualenv-%s' % virtualenv_entry['version'])
92 91 virtualenv_py = virtualenv_src_path / 'virtualenv.py'
93 92
94 93 if not virtualenv_src_path.exists():
95 94 extract_tar_to_directory(virtualenv_pkg, build_dir)
96 95
97 96 py2exe_source_path = build_dir / ('py2exe-%s' % py2exe_entry['version'])
98 97
99 98 if not py2exe_source_path.exists():
100 99 extract_zip_to_directory(py2exe_pkg, build_dir)
101 100
102 with tempfile.TemporaryDirectory() as td:
103 td = pathlib.Path(td)
104
105 101 if not venv_path.exists():
106 102 print('creating virtualenv with dependencies')
107 103 subprocess.run(
108 104 [str(python_exe), str(virtualenv_py), str(venv_path)],
109 105 check=True)
110 106
111 107 venv_python = venv_path / 'Scripts' / 'python.exe'
112 108 venv_pip = venv_path / 'Scripts' / 'pip.exe'
113 109
114 110 requirements_txt = (source_dir / 'contrib' / 'packaging' /
115 111 'inno' / 'requirements.txt')
116 112 subprocess.run([str(venv_pip), 'install', '-r', str(requirements_txt)],
117 113 check=True)
118 114
119 115 # Force distutils to use VC++ settings from environment, which was
120 116 # validated above.
121 117 env = dict(os.environ)
122 118 env['DISTUTILS_USE_SDK'] = '1'
123 119 env['MSSdk'] = '1'
124 120
125 121 py2exe_py_path = venv_path / 'Lib' / 'site-packages' / 'py2exe'
126 122 if not py2exe_py_path.exists():
127 123 print('building py2exe')
128 124 subprocess.run([str(venv_python), 'setup.py', 'install'],
129 125 cwd=py2exe_source_path,
130 126 env=env,
131 127 check=True)
132 128
133 129 # Register location of msgfmt and other binaries.
134 130 env['PATH'] = '%s%s%s' % (
135 131 env['PATH'], os.pathsep, str(gettext_root / 'bin'))
136 132
137 133 print('building Mercurial')
138 134 subprocess.run(
139 135 [str(venv_python), 'setup.py',
140 136 'py2exe', '-b', '3' if vc_x64 else '2',
141 137 'build_doc', '--html'],
142 138 cwd=str(source_dir),
143 139 env=env,
144 140 check=True)
145 141
146 142 # hg.exe depends on VC9 runtime DLLs. Copy those into place.
147 143 for f in find_vc_runtime_files(vc_x64):
148 144 if f.name.endswith('.manifest'):
149 145 basename = 'Microsoft.VC90.CRT.manifest'
150 146 else:
151 147 basename = f.name
152 148
153 149 dest_path = source_dir / 'dist' / basename
154 150
155 151 print('copying %s to %s' % (f, dest_path))
156 152 shutil.copyfile(f, dest_path)
157 153
158 154 print('creating installer')
159 155
160 156 args = [str(iscc_exe)]
161 157
162 158 if vc_x64:
163 159 args.append('/dARCH=x64')
164 160
165 161 if version:
166 162 args.append('/dVERSION=%s' % version)
167 163
168 164 args.append('/Odist')
169 165 args.append('contrib/packaging/inno/mercurial.iss')
170 166
171 167 subprocess.run(args, cwd=str(source_dir), check=True)
General Comments 0
You need to be logged in to leave comments. Login now