comparison contrib/packaging/hgpackaging/pyoxidizer.py @ 47210:73f1a10320d1

packaging: use PyOxidizer for producing WiX MSI installer We recently taught our in-tree PyOxidizer configuration file to produce MSI installers with WiX using PyOxidizer's built-in support for doing so. This commit changes our WiX + PyOxidizer installer generation code to use this functionality. After this change, all the Python packaging code is doing is the following: * Building HTML documentation * Making gettext available to the build process. * Munging CLI arguments to variables for the `pyoxidizer` execution. * Invoking `pyoxidizer build`. * Copying the produced `.msi` to the `dist/` directory. Applying this stack on stable and rebuilding the 5.8 MSI installer produced the following differences from the official 5.8 installer: * .exe and .pyd files aren't byte identical (this is expected). * Various .dist-info/ directories have different names due to older versions of PyOxidizer being buggy and not properly normalizing package names. (The new behavior is correct.) * Various *.dist-info/RECORD files are different due to content divergence of files (this is expected). * The python38.dll differs due to newer PyOxidizer shipping a newer version of Python 3.8. * We now ship python3.dll because PyOxidizer now includes this file by default. * The vcruntime140.dll differs because newer PyOxidizer installs a newer version. We also now ship a vcruntime140_1.dll because newer versions of the redistributable ship 2 files now. The WiX GUIDs and IDs of installed files have likely changed as a result of PyOxidizer's different mechanism for generating those identifiers. This means that an upgrade install of the MSI will replace files instead of doing an incremental update. This is likely harmless and we've incurred this kind of breakage before. As far as I can tell, the new PyOxidizer-built MSI is functionally equivalent to the old method. Once we drop support for Python 2.7 MSI installers, we can delete the WiX code from the repository. This commit temporarily drops support for extra `.wxs` files. We raise an exception instead of silently not using them, which I think is appropriate. We should be able to add support back in by injecting state into pyoxidizer.bzl via `--var`. I just didn't want to expend cognitive load to think about the solution as part of this series. Differential Revision: https://phab.mercurial-scm.org/D10688
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 May 2021 16:11:13 -0700
parents d09b36f69180
children 1e6cb23ce6da
comparison
equal deleted inserted replaced
47209:d09b36f69180 47210:73f1a10320d1
10 import os 10 import os
11 import pathlib 11 import pathlib
12 import shutil 12 import shutil
13 import subprocess 13 import subprocess
14 import sys 14 import sys
15 import typing
15 16
16 from .downloads import download_entry 17 from .downloads import download_entry
17 from .util import ( 18 from .util import (
18 extract_zip_to_directory, 19 extract_zip_to_directory,
19 process_install_rules, 20 process_install_rules,
67 check=True, 68 check=True,
68 ) 69 )
69 70
70 71
71 def run_pyoxidizer( 72 def run_pyoxidizer(
72 source_dir: pathlib.Path, build_dir: pathlib.Path, target_triple: str, 73 source_dir: pathlib.Path,
74 build_dir: pathlib.Path,
75 target_triple: str,
76 build_vars: typing.Optional[typing.Dict[str, str]] = None,
77 target: typing.Optional[str] = None,
73 ) -> pathlib.Path: 78 ) -> pathlib.Path:
74 """Run `pyoxidizer` in an environment with access to build dependencies. 79 """Run `pyoxidizer` in an environment with access to build dependencies.
75 80
76 Returns the output directory that pyoxidizer would have used for build 81 Returns the output directory that pyoxidizer would have used for build
77 artifacts. Actual build artifacts are likely in a sub-directory with the 82 artifacts. Actual build artifacts are likely in a sub-directory with the
78 name of the pyoxidizer build target that was built. 83 name of the pyoxidizer build target that was built.
79 """ 84 """
85 build_vars = build_vars or {}
86
80 # We need to make gettext binaries available for compiling i18n files. 87 # We need to make gettext binaries available for compiling i18n files.
81 gettext_pkg, gettext_entry = download_entry('gettext', build_dir) 88 gettext_pkg, gettext_entry = download_entry('gettext', build_dir)
82 gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0] 89 gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0]
83 90
84 gettext_root = build_dir / ('gettext-win-%s' % gettext_entry['version']) 91 gettext_root = build_dir / ('gettext-win-%s' % gettext_entry['version'])
101 str(source_dir / "rust" / "hgcli"), 108 str(source_dir / "rust" / "hgcli"),
102 "--release", 109 "--release",
103 "--target-triple", 110 "--target-triple",
104 target_triple, 111 target_triple,
105 ] 112 ]
113
114 for k, v in sorted(build_vars.items()):
115 args.extend(["--var", k, v])
116
117 if target:
118 args.append(target)
106 119
107 subprocess.run(args, env=env, check=True) 120 subprocess.run(args, env=env, check=True)
108 121
109 return source_dir / "build" / "pyoxidizer" / target_triple / "release" 122 return source_dir / "build" / "pyoxidizer" / target_triple / "release"
110 123