diff --git a/contrib/packaging/hgpackaging/py2exe.py b/contrib/packaging/hgpackaging/py2exe.py --- a/contrib/packaging/hgpackaging/py2exe.py +++ b/contrib/packaging/hgpackaging/py2exe.py @@ -25,7 +25,8 @@ def build_py2exe(source_dir: pathlib.Pat python_exe: pathlib.Path, build_name: str, venv_requirements_txt: pathlib.Path, extra_packages=None, extra_excludes=None, - extra_dll_excludes=None): + extra_dll_excludes=None, + extra_packages_script=None): """Build Mercurial with py2exe. Build files will be placed in ``build_dir``. @@ -105,6 +106,16 @@ def build_py2exe(source_dir: pathlib.Pat env['DISTUTILS_USE_SDK'] = '1' env['MSSdk'] = '1' + if extra_packages_script: + more_packages = set(subprocess.check_output( + extra_packages_script, + cwd=build_dir).split(b'\0')[-1].strip().decode('utf-8').splitlines()) + if more_packages: + if not extra_packages: + extra_packages = more_packages + else: + extra_packages |= more_packages + if extra_packages: env['HG_PY2EXE_EXTRA_PACKAGES'] = ' '.join(sorted(extra_packages)) if extra_excludes: diff --git a/contrib/packaging/hgpackaging/wix.py b/contrib/packaging/hgpackaging/wix.py --- a/contrib/packaging/hgpackaging/wix.py +++ b/contrib/packaging/hgpackaging/wix.py @@ -177,7 +177,8 @@ def make_libraries_xml(wix_dir: pathlib. def build_installer(source_dir: pathlib.Path, python_exe: pathlib.Path, - msi_name='mercurial', version=None, post_build_fn=None): + msi_name='mercurial', version=None, post_build_fn=None, + extra_packages_script=None): """Build a WiX MSI installer. ``source_dir`` is the path to the Mercurial source tree to use. @@ -189,6 +190,10 @@ def build_installer(source_dir: pathlib. Mercurial but before invoking WiX. It can be used to e.g. facilitate signing. It is passed the paths to the Mercurial source, build, and dist directories and the resolved Mercurial version. + ``extra_packages_script`` is a command to be run to inject extra packages + into the py2exe binary. It should stage packages into the virtualenv and + print a null byte followed by a newline-separated list of packages that + should be included in the exe. """ arch = 'x64' if r'\x64' in os.environ.get('LIB', '') else 'x86' @@ -200,7 +205,8 @@ def build_installer(source_dir: pathlib. build_py2exe(source_dir, hg_build_dir, python_exe, 'wix', requirements_txt, - extra_packages=EXTRA_PACKAGES) + extra_packages=EXTRA_PACKAGES, + extra_packages_script=extra_packages_script) version = version or normalize_version(find_version(source_dir)) print('using version string: %s' % version) @@ -280,7 +286,7 @@ def build_installer(source_dir: pathlib. def build_signed_installer(source_dir: pathlib.Path, python_exe: pathlib.Path, name: str, version=None, subject_name=None, cert_path=None, cert_password=None, - timestamp_url=None): + timestamp_url=None, extra_packages_script=None): """Build an installer with signed executables.""" post_build_fn = make_post_build_signing_fn( @@ -292,7 +298,8 @@ def build_signed_installer(source_dir: p info = build_installer(source_dir, python_exe=python_exe, msi_name=name.lower(), version=version, - post_build_fn=post_build_fn) + post_build_fn=post_build_fn, + extra_packages_script=extra_packages_script) description = '%s %s' % (name, version) diff --git a/contrib/packaging/wix/build.py b/contrib/packaging/wix/build.py --- a/contrib/packaging/wix/build.py +++ b/contrib/packaging/wix/build.py @@ -34,6 +34,9 @@ if __name__ == '__main__': help='URL of timestamp server to use for signing') parser.add_argument('--version', help='Version string to use') + parser.add_argument('--extra-packages-script', + help=('Script to execute to include extra packages in ' + 'py2exe binary.')) args = parser.parse_args() @@ -54,6 +57,9 @@ if __name__ == '__main__': 'version': args.version, } + if args.extra_packages_script: + kwargs['extra_packages_script'] = args.extra_packages_script + if args.sign_sn or args.sign_cert: fn = build_signed_installer kwargs['name'] = args.name