Mercurial > public > mercurial-scm > hg
diff rust/hgcli/pyoxidizer.bzl @ 44763:94f4f2ec7dee stable
packaging: support building Inno installer with PyOxidizer
We want to start distributing Mercurial on Python 3 on
Windows. PyOxidizer will be our vehicle for achieving that.
This commit implements basic support for producing Inno
installers using PyOxidizer.
While it is an eventual goal of PyOxidizer to produce
installers, those features aren't yet implemented. So our
strategy for producing Mercurial installers is similar to
what we've been doing with py2exe: invoke a build system to
produce files then stage those files into a directory so they
can be turned into an installer.
We had to make significant alterations to the pyoxidizer.bzl
config file to get it to produce the files that we desire for
a Windows install. This meant differentiating the build targets
so we can target Windows specifically.
We've added a new module to hgpackaging to deal with interacting
with PyOxidizer. It is similar to pyexe: we invoke a build process
then copy files to a staging directory. Ideally these extra
files would be defined in pyoxidizer.bzl. But I don't think it
is worth doing at this time, as PyOxidizer's config files are
lacking some features to make this turnkey.
The rest of the change is introducing a variant of the
Inno installer code that invokes PyOxidizer instead of
py2exe.
Comparing the Python 2.7 based Inno installers with this
one, the following changes were observed:
* No lib/*.{pyd, dll} files
* No Microsoft.VC90.CRT.manifest
* No msvc{m,p,r}90.dll files
* python27.dll replaced with python37.dll
* Add vcruntime140.dll file
The disappearance of the .pyd and .dll files is acceptable, as
PyOxidizer has embedded these in hg.exe and loads them from
memory.
The disappearance of the *90* files is acceptable because those
provide the Visual C++ 9 runtime, as required by Python 2.7.
Similarly, the appearance of vcruntime140.dll is a requirement
of Python 3.7.
Differential Revision: https://phab.mercurial-scm.org/D8473
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 23 Apr 2020 18:06:02 -0700 |
parents | bc847878f4c0 |
children | 118f067f6bd1 |
line wrap: on
line diff
--- a/rust/hgcli/pyoxidizer.bzl Sun Apr 19 15:35:21 2020 -0700 +++ b/rust/hgcli/pyoxidizer.bzl Thu Apr 23 18:06:02 2020 -0700 @@ -1,13 +1,24 @@ ROOT = CWD + "/../.." -def make_exe(): - dist = default_python_distribution() +# Code to run in Python interpreter. +RUN_CODE = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()" + + +set_build_path(ROOT + "/build/pyoxidizer") + - code = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()" +def make_distribution(): + return default_python_distribution() + +def make_distribution_windows(): + return default_python_distribution(flavor="standalone_dynamic") + + +def make_exe(dist): config = PythonInterpreterConfig( raw_allocator = "system", - run_eval = code, + run_eval = RUN_CODE, # We want to let the user load extensions from the file system filesystem_importer = True, # We need this to make resourceutil happy, since it looks for sys.frozen. @@ -24,30 +35,65 @@ extension_module_filter = "all", ) - exe.add_python_resources(dist.pip_install([ROOT])) + # Add Mercurial to resources. + for resource in dist.pip_install(["--verbose", ROOT]): + # This is a bit wonky and worth explaining. + # + # Various parts of Mercurial don't yet support loading package + # resources via the ResourceReader interface. Or, not having + # file-based resources would be too inconvenient for users. + # + # So, for package resources, we package them both in the + # filesystem as well as in memory. If both are defined, + # PyOxidizer will prefer the in-memory location. So even + # if the filesystem file isn't packaged in the location + # specified here, we should never encounter an errors as the + # resource will always be available in memory. + if type(resource) == "PythonPackageResource": + exe.add_filesystem_relative_python_resource(".", resource) + exe.add_in_memory_python_resource(resource) + else: + exe.add_python_resource(resource) + + # On Windows, we install extra packages for convenience. + if "windows" in BUILD_TARGET_TRIPLE: + exe.add_python_resources( + dist.pip_install(["-r", ROOT + "/contrib/packaging/requirements_win32.txt"]) + ) return exe -def make_install(exe): + +def make_manifest(dist, exe): m = FileManifest() - - # `hg` goes in root directory. m.add_python_resource(".", exe) - templates = glob( - include = [ROOT + "/mercurial/templates/**/*"], - strip_prefix = ROOT + "/mercurial/", - ) - m.add_manifest(templates) + return m - return m def make_embedded_resources(exe): return exe.to_embedded_resources() -register_target("exe", make_exe) -register_target("app", make_install, depends = ["exe"], default = True) -register_target("embedded", make_embedded_resources, depends = ["exe"], default_build_script = True) + +register_target("distribution_posix", make_distribution) +register_target("distribution_windows", make_distribution_windows) + +register_target("exe_posix", make_exe, depends = ["distribution_posix"]) +register_target("exe_windows", make_exe, depends = ["distribution_windows"]) + +register_target( + "app_posix", + make_manifest, + depends = ["distribution_posix", "exe_posix"], + default = "windows" not in BUILD_TARGET_TRIPLE, +) +register_target( + "app_windows", + make_manifest, + depends = ["distribution_windows", "exe_windows"], + default = "windows" in BUILD_TARGET_TRIPLE, +) + resolve_targets() # END OF COMMON USER-ADJUSTED SETTINGS. @@ -55,5 +101,4 @@ # Everything below this is typically managed by PyOxidizer and doesn't need # to be updated by people. -PYOXIDIZER_VERSION = "0.7.0-pre" -PYOXIDIZER_COMMIT = "c772a1379c3026314eda1c8ea244b86c0658951d" +PYOXIDIZER_VERSION = "0.7.0"