##// END OF EJS Templates
packaging: use PyOxidizer for producing WiX MSI installer...
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

File last commit:

r46554:89a2afe3 default
r47981:73f1a103 default
Show More
cli.py
187 lines | 5.1 KiB | text/x-python | PythonLexer
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 # cli.py - Command line interface for automation
#
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
# no-check-code because Python 3 native.
import argparse
import os
import pathlib
from . import (
inno,
wix,
)
HERE = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))
SOURCE_DIR = HERE.parent.parent.parent
Gregory Szorc
packaging: support building Inno installer with PyOxidizer...
r45270 def build_inno(pyoxidizer_target=None, python=None, iscc=None, version=None):
if not pyoxidizer_target and not python:
raise Exception("--python required unless building with PyOxidizer")
if python and not os.path.isabs(python):
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 raise Exception("--python arg must be an absolute path")
if iscc:
iscc = pathlib.Path(iscc)
else:
iscc = (
pathlib.Path(os.environ["ProgramFiles(x86)"])
/ "Inno Setup 5"
/ "ISCC.exe"
)
build_dir = SOURCE_DIR / "build"
Gregory Szorc
packaging: support building Inno installer with PyOxidizer...
r45270 if pyoxidizer_target:
inno.build_with_pyoxidizer(
SOURCE_DIR, build_dir, pyoxidizer_target, iscc, version=version
)
else:
inno.build_with_py2exe(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 SOURCE_DIR,
build_dir,
pathlib.Path(python),
iscc,
version=version,
Gregory Szorc
packaging: support building Inno installer with PyOxidizer...
r45270 )
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913
def build_wix(
name=None,
Gregory Szorc
packaging: support building WiX installers with PyOxidizer...
r45274 pyoxidizer_target=None,
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 python=None,
version=None,
sign_sn=None,
sign_cert=None,
sign_password=None,
sign_timestamp_url=None,
extra_packages_script=None,
extra_wxs=None,
extra_features=None,
):
Gregory Szorc
packaging: support building WiX installers with PyOxidizer...
r45274 if not pyoxidizer_target and not python:
raise Exception("--python required unless building with PyOxidizer")
if python and not os.path.isabs(python):
raise Exception("--python arg must be an absolute path")
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 kwargs = {
"source_dir": SOURCE_DIR,
"version": version,
}
Gregory Szorc
packaging: support building WiX installers with PyOxidizer...
r45274 if pyoxidizer_target:
fn = wix.build_installer_pyoxidizer
kwargs["target_triple"] = pyoxidizer_target
else:
fn = wix.build_installer_py2exe
kwargs["python_exe"] = pathlib.Path(python)
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913
if extra_packages_script:
Gregory Szorc
packaging: support building WiX installers with PyOxidizer...
r45274 if pyoxidizer_target:
raise Exception(
"pyoxidizer does not support --extra-packages-script"
)
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 kwargs["extra_packages_script"] = extra_packages_script
if extra_wxs:
kwargs["extra_wxs"] = dict(
thing.split("=") for thing in extra_wxs.split(",")
)
if extra_features:
kwargs["extra_features"] = extra_features.split(",")
if sign_sn or sign_cert:
Gregory Szorc
packaging: integrate signing into run_wix_packaging()...
r45272 kwargs["signing_info"] = {
"name": name,
"subject_name": sign_sn,
"cert_path": sign_cert,
"cert_password": sign_password,
"timestamp_url": sign_timestamp_url,
}
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913
Gregory Szorc
packaging: support building WiX installers with PyOxidizer...
r45274 fn(**kwargs)
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913
def get_parser():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
sp = subparsers.add_parser("inno", help="Build Inno Setup installer")
Gregory Szorc
packaging: support building Inno installer with PyOxidizer...
r45270 sp.add_argument(
"--pyoxidizer-target",
choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"},
help="Build with PyOxidizer targeting this host triple",
)
sp.add_argument("--python", help="path to python.exe to use")
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 sp.add_argument("--iscc", help="path to iscc.exe to use")
sp.add_argument(
"--version",
help="Mercurial version string to use "
"(detected from __version__.py if not defined",
)
sp.set_defaults(func=build_inno)
sp = subparsers.add_parser(
"wix", help="Build Windows installer with WiX Toolset"
)
sp.add_argument("--name", help="Application name", default="Mercurial")
sp.add_argument(
Gregory Szorc
packaging: support building WiX installers with PyOxidizer...
r45274 "--pyoxidizer-target",
choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"},
help="Build with PyOxidizer targeting this host triple",
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 )
Gregory Szorc
packaging: support building WiX installers with PyOxidizer...
r45274 sp.add_argument("--python", help="Path to Python executable to use")
Gregory Szorc
packaging: consolidate CLI functionality into packaging.py...
r43913 sp.add_argument(
"--sign-sn",
help="Subject name (or fragment thereof) of certificate "
"to use for signing",
)
sp.add_argument(
"--sign-cert", help="Path to certificate to use for signing"
)
sp.add_argument("--sign-password", help="Password for signing certificate")
sp.add_argument(
"--sign-timestamp-url",
help="URL of timestamp server to use for signing",
)
sp.add_argument("--version", help="Version string to use")
sp.add_argument(
"--extra-packages-script",
help=(
"Script to execute to include extra packages in " "py2exe binary."
),
)
sp.add_argument(
"--extra-wxs", help="CSV of path_to_wxs_file=working_dir_for_wxs_file"
)
sp.add_argument(
"--extra-features",
help=(
"CSV of extra feature names to include "
"in the installer from the extra wxs files"
),
)
sp.set_defaults(func=build_wix)
return parser
def main():
parser = get_parser()
args = parser.parse_args()
if not hasattr(args, "func"):
parser.print_help()
return
kwargs = dict(vars(args))
del kwargs["func"]
args.func(**kwargs)