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 |
|
|
106 | 102 |
|
|
107 | 103 |
|
|
108 | 104 |
|
|
109 | 105 |
|
|
110 | 106 | |
|
111 | 107 |
|
|
112 | 108 |
|
|
113 | 109 | |
|
114 | 110 |
|
|
115 | 111 |
|
|
116 | 112 |
|
|
117 | 113 |
|
|
118 | 114 | |
|
119 | 115 |
|
|
120 | 116 |
|
|
121 | 117 |
|
|
122 | 118 |
|
|
123 | 119 |
|
|
124 | 120 | |
|
125 | 121 |
|
|
126 | 122 |
|
|
127 | 123 |
|
|
128 | 124 |
|
|
129 | 125 |
|
|
130 | 126 |
|
|
131 | 127 |
|
|
132 | 128 | |
|
133 | 129 |
|
|
134 | 130 |
|
|
135 | 131 |
|
|
136 | 132 | |
|
137 | 133 |
|
|
138 | 134 |
|
|
139 | 135 |
|
|
140 | 136 |
|
|
141 | 137 |
|
|
142 | 138 |
|
|
143 | 139 |
|
|
144 | 140 |
|
|
145 | 141 | |
|
146 | 142 |
|
|
147 | 143 |
|
|
148 | 144 |
|
|
149 | 145 |
|
|
150 | 146 |
|
|
151 | 147 |
|
|
152 | 148 | |
|
153 | 149 |
|
|
154 | 150 | |
|
155 | 151 |
|
|
156 | 152 |
|
|
157 | 153 | |
|
158 | 154 |
|
|
159 | 155 | |
|
160 | 156 |
|
|
161 | 157 | |
|
162 | 158 |
|
|
163 | 159 |
|
|
164 | 160 | |
|
165 | 161 |
|
|
166 | 162 |
|
|
167 | 163 | |
|
168 | 164 |
|
|
169 | 165 |
|
|
170 | 166 | |
|
171 | 167 |
|
General Comments 0
You need to be logged in to leave comments.
Login now