Show More
@@ -1,295 +1,303 b'' | |||
|
1 | 1 | # The following variables can be passed in as parameters: |
|
2 | 2 | # |
|
3 | 3 | # VERSION |
|
4 | 4 | # Version string of program being produced. |
|
5 | 5 | # |
|
6 | 6 | # MSI_NAME |
|
7 | 7 | # Root name of MSI installer. |
|
8 | 8 | # |
|
9 | 9 | # EXTRA_MSI_FEATURES |
|
10 | 10 | # ; delimited string of extra features to advertise in the built MSA. |
|
11 | 11 | # |
|
12 | 12 | # SIGNING_PFX_PATH |
|
13 | 13 | # Path to code signing certificate to use. |
|
14 | 14 | # |
|
15 | 15 | # SIGNING_PFX_PASSWORD |
|
16 | 16 | # Password to code signing PFX file defined by SIGNING_PFX_PATH. |
|
17 | 17 | # |
|
18 | 18 | # SIGNING_SUBJECT_NAME |
|
19 | 19 | # String fragment in code signing certificate subject name used to find |
|
20 | 20 | # code signing certificate in Windows certificate store. |
|
21 | 21 | # |
|
22 | 22 | # TIME_STAMP_SERVER_URL |
|
23 | 23 | # URL of time-stamp token authority (RFC 3161) servers to stamp code signatures. |
|
24 | 24 | |
|
25 | 25 | ROOT = CWD + "/../.." |
|
26 | 26 | |
|
27 | 27 | VERSION = VARS.get("VERSION", "5.8") |
|
28 | 28 | MSI_NAME = VARS.get("MSI_NAME", "mercurial") |
|
29 | 29 | EXTRA_MSI_FEATURES = VARS.get("EXTRA_MSI_FEATURES") |
|
30 | 30 | SIGNING_PFX_PATH = VARS.get("SIGNING_PFX_PATH") |
|
31 | 31 | SIGNING_PFX_PASSWORD = VARS.get("SIGNING_PFX_PASSWORD", "") |
|
32 | 32 | SIGNING_SUBJECT_NAME = VARS.get("SIGNING_SUBJECT_NAME") |
|
33 | 33 | TIME_STAMP_SERVER_URL = VARS.get("TIME_STAMP_SERVER_URL", "http://timestamp.digicert.com") |
|
34 | 34 | |
|
35 | 35 | IS_WINDOWS = "windows" in BUILD_TARGET_TRIPLE |
|
36 | 36 | |
|
37 | 37 | # Code to run in Python interpreter. |
|
38 | 38 | RUN_CODE = """ |
|
39 | import os | |
|
40 | import sys | |
|
41 | extra_path = os.environ.get('PYTHONPATH') | |
|
42 | if extra_path is not None: | |
|
43 | # extensions and hooks expect a working python environment | |
|
44 | # We do not prepend the values because the Mercurial library wants to be in | |
|
45 | # the front of the sys.path to avoid picking up other installations. | |
|
46 | sys.path.extend(extra_path.split(os.pathsep)) | |
|
39 | 47 | import hgdemandimport; |
|
40 | 48 | hgdemandimport.enable(); |
|
41 | 49 | from mercurial import dispatch; |
|
42 | 50 | dispatch.run(); |
|
43 | 51 | """ |
|
44 | 52 | |
|
45 | 53 | set_build_path(ROOT + "/build/pyoxidizer") |
|
46 | 54 | |
|
47 | 55 | def make_distribution(): |
|
48 | 56 | return default_python_distribution(python_version = "3.9") |
|
49 | 57 | |
|
50 | 58 | def resource_callback(policy, resource): |
|
51 | 59 | if not IS_WINDOWS: |
|
52 | 60 | resource.add_location = "in-memory" |
|
53 | 61 | return |
|
54 | 62 | |
|
55 | 63 | # We use a custom resource routing policy to influence where things are loaded |
|
56 | 64 | # from. |
|
57 | 65 | # |
|
58 | 66 | # For Python modules and resources, we load from memory if they are in |
|
59 | 67 | # the standard library and from the filesystem if not. This is because |
|
60 | 68 | # parts of Mercurial and some 3rd party packages aren't yet compatible |
|
61 | 69 | # with memory loading. |
|
62 | 70 | # |
|
63 | 71 | # For Python extension modules, we load from the filesystem because |
|
64 | 72 | # this yields greatest compatibility. |
|
65 | 73 | if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"): |
|
66 | 74 | if resource.is_stdlib: |
|
67 | 75 | resource.add_location = "in-memory" |
|
68 | 76 | else: |
|
69 | 77 | resource.add_location = "filesystem-relative:lib" |
|
70 | 78 | |
|
71 | 79 | elif type(resource) == "PythonExtensionModule": |
|
72 | 80 | resource.add_location = "filesystem-relative:lib" |
|
73 | 81 | |
|
74 | 82 | def make_exe(dist): |
|
75 | 83 | """Builds a Rust-wrapped Mercurial binary.""" |
|
76 | 84 | packaging_policy = dist.make_python_packaging_policy() |
|
77 | 85 | |
|
78 | 86 | # Extension may depend on any Python functionality. Include all |
|
79 | 87 | # extensions. |
|
80 | 88 | packaging_policy.extension_module_filter = "all" |
|
81 | 89 | packaging_policy.resources_location = "in-memory" |
|
82 | 90 | if IS_WINDOWS: |
|
83 | 91 | packaging_policy.resources_location_fallback = "filesystem-relative:lib" |
|
84 | 92 | packaging_policy.register_resource_callback(resource_callback) |
|
85 | 93 | |
|
86 | 94 | config = dist.make_python_interpreter_config() |
|
87 | 95 | config.allocator_backend = "default" |
|
88 | 96 | config.run_command = RUN_CODE |
|
89 | 97 | |
|
90 | 98 | # We want to let the user load extensions from the file system |
|
91 | 99 | config.filesystem_importer = True |
|
92 | 100 | |
|
93 | 101 | # We need this to make resourceutil happy, since it looks for sys.frozen. |
|
94 | 102 | config.sys_frozen = True |
|
95 | 103 | config.legacy_windows_stdio = True |
|
96 | 104 | |
|
97 | 105 | exe = dist.to_python_executable( |
|
98 | 106 | name = "hg", |
|
99 | 107 | packaging_policy = packaging_policy, |
|
100 | 108 | config = config, |
|
101 | 109 | ) |
|
102 | 110 | |
|
103 | 111 | # Add Mercurial to resources. |
|
104 | 112 | exe.add_python_resources(exe.pip_install(["--verbose", ROOT])) |
|
105 | 113 | |
|
106 | 114 | # On Windows, we install extra packages for convenience. |
|
107 | 115 | if IS_WINDOWS: |
|
108 | 116 | exe.add_python_resources( |
|
109 | 117 | exe.pip_install(["-r", ROOT + "/contrib/packaging/requirements-windows-py3.txt"]), |
|
110 | 118 | ) |
|
111 | 119 | extra_packages = VARS.get("extra_py_packages", "") |
|
112 | 120 | if extra_packages: |
|
113 | 121 | for extra in extra_packages.split(","): |
|
114 | 122 | extra_src, pkgs = extra.split("=") |
|
115 | 123 | pkgs = pkgs.split(":") |
|
116 | 124 | exe.add_python_resources(exe.read_package_root(extra_src, pkgs)) |
|
117 | 125 | |
|
118 | 126 | return exe |
|
119 | 127 | |
|
120 | 128 | def make_manifest(dist, exe): |
|
121 | 129 | m = FileManifest() |
|
122 | 130 | m.add_python_resource(".", exe) |
|
123 | 131 | |
|
124 | 132 | return m |
|
125 | 133 | |
|
126 | 134 | |
|
127 | 135 | # This adjusts the InstallManifest produced from exe generation to provide |
|
128 | 136 | # additional files found in a Windows install layout. |
|
129 | 137 | def make_windows_install_layout(manifest): |
|
130 | 138 | # Copy various files to new install locations. This can go away once |
|
131 | 139 | # we're using the importlib resource reader. |
|
132 | 140 | RECURSIVE_COPIES = { |
|
133 | 141 | "lib/mercurial/locale/": "locale/", |
|
134 | 142 | "lib/mercurial/templates/": "templates/", |
|
135 | 143 | } |
|
136 | 144 | for (search, replace) in RECURSIVE_COPIES.items(): |
|
137 | 145 | for path in manifest.paths(): |
|
138 | 146 | if path.startswith(search): |
|
139 | 147 | new_path = path.replace(search, replace) |
|
140 | 148 | print("copy %s to %s" % (path, new_path)) |
|
141 | 149 | file = manifest.get_file(path) |
|
142 | 150 | manifest.add_file(file, path = new_path) |
|
143 | 151 | |
|
144 | 152 | # Similar to above, but with filename pattern matching. |
|
145 | 153 | # lib/mercurial/helptext/**/*.txt -> helptext/ |
|
146 | 154 | # lib/mercurial/defaultrc/*.rc -> defaultrc/ |
|
147 | 155 | for path in manifest.paths(): |
|
148 | 156 | if path.startswith("lib/mercurial/helptext/") and path.endswith(".txt"): |
|
149 | 157 | new_path = path[len("lib/mercurial/"):] |
|
150 | 158 | elif path.startswith("lib/mercurial/defaultrc/") and path.endswith(".rc"): |
|
151 | 159 | new_path = path[len("lib/mercurial/"):] |
|
152 | 160 | else: |
|
153 | 161 | continue |
|
154 | 162 | |
|
155 | 163 | print("copying %s to %s" % (path, new_path)) |
|
156 | 164 | manifest.add_file(manifest.get_file(path), path = new_path) |
|
157 | 165 | |
|
158 | 166 | extra_install_files = VARS.get("extra_install_files", "") |
|
159 | 167 | if extra_install_files: |
|
160 | 168 | for extra in extra_install_files.split(","): |
|
161 | 169 | print("adding extra files from %s" % extra) |
|
162 | 170 | # TODO: I expected a ** glob to work, but it didn't. |
|
163 | 171 | # |
|
164 | 172 | # TODO: I know this has forward-slash paths. As far as I can tell, |
|
165 | 173 | # backslashes don't ever match glob() expansions in |
|
166 | 174 | # tugger-starlark, even on Windows. |
|
167 | 175 | manifest.add_manifest(glob(include=[extra + "/*/*"], strip_prefix=extra+"/")) |
|
168 | 176 | |
|
169 | 177 | # We also install a handful of additional files. |
|
170 | 178 | EXTRA_CONTRIB_FILES = [ |
|
171 | 179 | "bash_completion", |
|
172 | 180 | "hgweb.fcgi", |
|
173 | 181 | "hgweb.wsgi", |
|
174 | 182 | "logo-droplets.svg", |
|
175 | 183 | "mercurial.el", |
|
176 | 184 | "mq.el", |
|
177 | 185 | "tcsh_completion", |
|
178 | 186 | "tcsh_completion_build.sh", |
|
179 | 187 | "xml.rnc", |
|
180 | 188 | "zsh_completion", |
|
181 | 189 | ] |
|
182 | 190 | |
|
183 | 191 | for f in EXTRA_CONTRIB_FILES: |
|
184 | 192 | manifest.add_file(FileContent(path = ROOT + "/contrib/" + f), directory = "contrib") |
|
185 | 193 | |
|
186 | 194 | # Individual files with full source to destination path mapping. |
|
187 | 195 | EXTRA_FILES = { |
|
188 | 196 | "contrib/hgk": "contrib/hgk.tcl", |
|
189 | 197 | "contrib/win32/postinstall.txt": "ReleaseNotes.txt", |
|
190 | 198 | "contrib/win32/ReadMe.html": "ReadMe.html", |
|
191 | 199 | "doc/style.css": "doc/style.css", |
|
192 | 200 | "COPYING": "Copying.txt", |
|
193 | 201 | } |
|
194 | 202 | |
|
195 | 203 | for source, dest in EXTRA_FILES.items(): |
|
196 | 204 | print("adding extra file %s" % dest) |
|
197 | 205 | manifest.add_file(FileContent(path = ROOT + "/" + source), path = dest) |
|
198 | 206 | |
|
199 | 207 | # And finally some wildcard matches. |
|
200 | 208 | manifest.add_manifest(glob( |
|
201 | 209 | include = [ROOT + "/contrib/vim/*"], |
|
202 | 210 | strip_prefix = ROOT + "/" |
|
203 | 211 | )) |
|
204 | 212 | manifest.add_manifest(glob( |
|
205 | 213 | include = [ROOT + "/doc/*.html"], |
|
206 | 214 | strip_prefix = ROOT + "/" |
|
207 | 215 | )) |
|
208 | 216 | |
|
209 | 217 | # But we don't ship hg-ssh on Windows, so exclude its documentation. |
|
210 | 218 | manifest.remove("doc/hg-ssh.8.html") |
|
211 | 219 | |
|
212 | 220 | return manifest |
|
213 | 221 | |
|
214 | 222 | |
|
215 | 223 | def make_msi(manifest): |
|
216 | 224 | manifest = make_windows_install_layout(manifest) |
|
217 | 225 | |
|
218 | 226 | if "x86_64" in BUILD_TARGET_TRIPLE: |
|
219 | 227 | platform = "x64" |
|
220 | 228 | else: |
|
221 | 229 | platform = "x86" |
|
222 | 230 | |
|
223 | 231 | manifest.add_file( |
|
224 | 232 | FileContent(path = ROOT + "/contrib/packaging/wix/COPYING.rtf"), |
|
225 | 233 | path = "COPYING.rtf", |
|
226 | 234 | ) |
|
227 | 235 | manifest.remove("Copying.txt") |
|
228 | 236 | manifest.add_file( |
|
229 | 237 | FileContent(path = ROOT + "/contrib/win32/mercurial.ini"), |
|
230 | 238 | path = "defaultrc/mercurial.rc", |
|
231 | 239 | ) |
|
232 | 240 | manifest.add_file( |
|
233 | 241 | FileContent(filename = "editor.rc", content = "[ui]\neditor = notepad\n"), |
|
234 | 242 | path = "defaultrc/editor.rc", |
|
235 | 243 | ) |
|
236 | 244 | |
|
237 | 245 | wix = WiXInstaller("hg", "%s-%s.msi" % (MSI_NAME, VERSION)) |
|
238 | 246 | |
|
239 | 247 | # Materialize files in the manifest to the install layout. |
|
240 | 248 | wix.add_install_files(manifest) |
|
241 | 249 | |
|
242 | 250 | # From mercurial.wxs. |
|
243 | 251 | wix.install_files_root_directory_id = "INSTALLDIR" |
|
244 | 252 | |
|
245 | 253 | # Pull in our custom .wxs files. |
|
246 | 254 | defines = { |
|
247 | 255 | "PyOxidizer": "1", |
|
248 | 256 | "Platform": platform, |
|
249 | 257 | "Version": VERSION, |
|
250 | 258 | "Comments": "Installs Mercurial version %s" % VERSION, |
|
251 | 259 | "PythonVersion": "3", |
|
252 | 260 | "MercurialHasLib": "1", |
|
253 | 261 | } |
|
254 | 262 | |
|
255 | 263 | if EXTRA_MSI_FEATURES: |
|
256 | 264 | defines["MercurialExtraFeatures"] = EXTRA_MSI_FEATURES |
|
257 | 265 | |
|
258 | 266 | wix.add_wxs_file( |
|
259 | 267 | ROOT + "/contrib/packaging/wix/mercurial.wxs", |
|
260 | 268 | preprocessor_parameters=defines, |
|
261 | 269 | ) |
|
262 | 270 | |
|
263 | 271 | # Our .wxs references to other files. Pull those into the build environment. |
|
264 | 272 | for f in ("defines.wxi", "guids.wxi", "COPYING.rtf"): |
|
265 | 273 | wix.add_build_file(f, ROOT + "/contrib/packaging/wix/" + f) |
|
266 | 274 | |
|
267 | 275 | wix.add_build_file("mercurial.ico", ROOT + "/contrib/win32/mercurial.ico") |
|
268 | 276 | |
|
269 | 277 | return wix |
|
270 | 278 | |
|
271 | 279 | |
|
272 | 280 | def register_code_signers(): |
|
273 | 281 | if not IS_WINDOWS: |
|
274 | 282 | return |
|
275 | 283 | |
|
276 | 284 | if SIGNING_PFX_PATH: |
|
277 | 285 | signer = code_signer_from_pfx_file(SIGNING_PFX_PATH, SIGNING_PFX_PASSWORD) |
|
278 | 286 | elif SIGNING_SUBJECT_NAME: |
|
279 | 287 | signer = code_signer_from_windows_store_subject(SIGNING_SUBJECT_NAME) |
|
280 | 288 | else: |
|
281 | 289 | signer = None |
|
282 | 290 | |
|
283 | 291 | if signer: |
|
284 | 292 | signer.set_time_stamp_server(TIME_STAMP_SERVER_URL) |
|
285 | 293 | signer.activate() |
|
286 | 294 | |
|
287 | 295 | |
|
288 | 296 | register_code_signers() |
|
289 | 297 | |
|
290 | 298 | register_target("distribution", make_distribution) |
|
291 | 299 | register_target("exe", make_exe, depends = ["distribution"]) |
|
292 | 300 | register_target("app", make_manifest, depends = ["distribution", "exe"], default = True) |
|
293 | 301 | register_target("msi", make_msi, depends = ["app"]) |
|
294 | 302 | |
|
295 | 303 | resolve_targets() |
General Comments 0
You need to be logged in to leave comments.
Login now