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