[PATCH 6 of 6] packaging: build the shell extension with python3

1 view
Skip to first unread message

Matt Harbison

unread,
May 2, 2022, 7:04:48 PMMay 2
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1651526219 14400
# Mon May 02 17:16:59 2022 -0400
# Node ID 74a16b9081c6294177d862e65952d1beedcbc11f
# Parent 4558a46f5216cb06632190c22e17e9bc89b38722
# EXP-Topic windows-py3-packaging
packaging: build the shell extension with python3

This is a reproduction of the process used by the winbuild repo's setup.py to
build the shell extension. Multiprocessor building is enabled to speed the
process along.

The thg version is run through the normalization function that was borrowed from
the Mercurial build scripts, because the `windowsversion` function in the
winbuild repo was having fits about the string returned from Mercurial. This
points out that we haven't modernized the content of `__version__.py` to format
the extra part like "hg216.d8b5fd0ab640". We can do that later.

This also differs from the winbuild script in that it doesn't bother reading
the version of Mercurial to be packaged. I'm not really sure what the point
was- it only used the periodic value, only in `-dev` or `-stable` builds, and
only showed up in the description string passed to the signing tool. Since
Mercurial's `__version__.py` is in bytes, the thg file reading utility (which
expects str) won't work, so don't bother.

diff --git a/contrib/packaging/thgpackaging/wix.py b/contrib/packaging/thgpackaging/wix.py
--- a/contrib/packaging/thgpackaging/wix.py
+++ b/contrib/packaging/thgpackaging/wix.py
@@ -26,6 +26,7 @@
)
from .util import (
extract_zip_to_directory,
+ get_vc_environment,
normalize_windows_version,
process_install_rules,
python_exe_info,
@@ -305,6 +306,11 @@
extra_includes=EXTRA_INCLUDES,
)

+ # TODO: this is what winbuild uses, but Mercurial uses a predicatable uuid.
+ productid = str(uuid.uuid4()).upper()
+
+ build_shellext(source_dirs, sorted({'x86', arch}), productid, signing_info)
+
build_dir = thg_build_dir / ('wix-%s' % arch)
staging_dir = build_dir / 'stage'

@@ -344,6 +350,83 @@
)


+def build_shellext(
+ source_dirs: SourceDirs,
+ archs: typing.Iterable[str],
+ productid: str,
+ signing_info: typing.Optional[typing.Dict[str, str]] = None,
+):
+ """Build the shell extension for the given architectures."""
+
+ thgversion = read_version_py(source_dirs.thg)
+
+ # TODO: sync the version generation in setup.py with hg's setup.py to
+ # generate modern style version strings to eliminate this slicing off of
+ # the extra info. This cleans up something like 6.1.1+33-e6a340244a11.
+ # Since both the rc value (if present) commit count (if not) go into the
+ # 4th component, we don't care about that because the 4th component isn't
+ # used here.
+ thgversion = thgversion.split('+', 1)[0]
+
+ # This may have 3 or 4 components
+ nv = normalize_windows_version(thgversion).split('.')
+
+ shellext_dir = source_dirs.shellext
+
+ # Clear files added by previous installer runs
+ subprocess.run(
+ ["hg.exe", "--config", "extensions.purge=", "purge", "--all"],
+ cwd=str(shellext_dir),
+ check=True,
+ )
+
+ def compile(arch):
+ print("*************** Compiling %s shellext ***************" % arch)
+
+ customenv = {
+ 'DEBUG': '1',
+ 'THG_PLATFORM': arch,
+ 'THG_EXTRA_CPPFLAGS': '/DTHG_PRODUCT_ID=%s' % productid,
+ 'THG_EXTRA_RCFLAGS':
+ '/dTHG_VERSION_FIRST=%s '
+ '/dTHG_VERSION_SECOND=%s '
+ '/dTHG_VERSION_THIRD=%s '
+ '/dTHG_PRODUCT_ID="%s"' % (nv[0], nv[1], nv[2], productid),
+ 'CL': '/MP' # Enable multiprocessor builds
+ }
+
+ env = get_vc_environment(arch == "x64")
+ env.update(customenv)
+
+ subprocess.run(
+ ["nmake.exe", "/nologo", "/f", "Makefile.nmake", "clean"],
+ shell=True,
+ cwd=str(shellext_dir / 'src'),
+ env=env,
+ check=True,
+ )
+ subprocess.run(
+ ["nmake.exe", "/nologo", "/f", "Makefile.nmake"],
+ shell=True,
+ cwd=str(shellext_dir / 'src'),
+ env=env,
+ check=True,
+ )
+
+ if signing_info:
+ sign_with_signtool(
+ shellext_dir / "src" / ("ThgShell%s.dll" % arch),
+ "TortoiseHg %s %s shell extension" % (arch, thgversion),
+ subject_name=signing_info["subject_name"],
+ cert_path=signing_info["cert_path"],
+ cert_password=signing_info["cert_password"],
+ timestamp_url=signing_info["timestamp_url"],
+ )
+
+ for arch in archs:
+ compile(arch)
+
+
def run_wix_packaging(
source_dir: pathlib.Path,
build_dir: pathlib.Path,
Reply all
Reply to author
Forward
0 new messages