[PATCH 2 of 6] packaging: stage the dependent repos when building the Windows installer

1 view
Skip to first unread message

Matt Harbison

unread,
May 2, 2022, 7:04:46 PMMay 2
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1650410512 14400
# Tue Apr 19 19:21:52 2022 -0400
# Node ID 83a3e09fce3708e3a6b128733d947bb75f8288aa
# Parent f0bd1f9455a29caa95f8458ac424e16c3382131e
# EXP-Topic windows-py3-packaging
packaging: stage the dependent repos when building the Windows installer

I really didn't want to replicate some of the current hierarchy of repos used to
build the installer, but there are various binary artifacts needed to build the
installer in various repos, and some of the `*.wxs` files have relative paths
that assume the directory structure. I don't want to change those until after
py2 support is dropped. With the recently added code to generate the `*.wxs`
files, some or most of these may go away anyway. But the build process is
complicated, and I'm sick of working on this enough that I'm settling for a
subset of the current build process for now.

None of the extensions other than hg-evolve that are currently bundled into the
py2 installer are cloned here. The keyring extension and other python
dependencies will be installed into the venv and bundled that way. The other
extensions aren't available on PyPI and haven't been ported to py3, so let's
simplify things and see if anyone complains.

One change here is to get rid of the clone of local clones, which I found
confusing. Instead, Mercurial is cloned right to `winbuild/build/hg` (so
there's only one copy), and the current thg code will be archived into place
when the installer is built (to pick up any local changes). Maybe Mercurial
should be cloned to the root of the dependencies directory and shared into
place to support other platforms, but that can be sorted out later.

The other important change here is that the staging is a separate step from the
(future) build command. The `winbuild` script had a tendency to update to
different branches, based on the target named on the command line, and a lot of
times that was a hassle. The current macOS scripts assume the repos are updated
as appropriate when run, and that has been more reliable.

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -55,5 +55,6 @@
contrib/packaging/macos/toolchain/toolchain-qt4
contrib/packaging/macos/toolchain/toolchain-qt5
contrib/packaging/macos/releases
+dependencies
re:venv-py\d\.\d
.pytest_cache
diff --git a/contrib/packaging/thgpackaging/cli.py b/contrib/packaging/thgpackaging/cli.py
--- a/contrib/packaging/thgpackaging/cli.py
+++ b/contrib/packaging/thgpackaging/cli.py
@@ -12,6 +12,7 @@
import os
import pathlib
import shutil
+import subprocess
import sys

from . import (
@@ -23,6 +24,7 @@

HERE = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))
SOURCE_DIR = HERE.parent.parent.parent
+SOURCE_DIRS = thgutil.SourceDirs(SOURCE_DIR)


def build_venv(python='', hg='', qt=None, output='', force=False, clean=False):
@@ -122,6 +124,70 @@
fn(**kwargs)


+def stage_dependencies(
+ hg_version=None,
+ evolve_version=None,
+ shellext_version=None,
+ clean=False,
+):
+ """Stage the other required repositories locally."""
+
+ if clean:
+ SOURCE_DIRS.clean()
+
+ repos = [
+ (
+ "WinBuild",
+ "https://foss.heptapod.net/mercurial/tortoisehg/thg-winbuild",
+ SOURCE_DIRS.winbuild,
+ "default",
+ ),
+ (
+ "Mercurial",
+ "https://www.mercurial-scm.org/repo/hg",
+ SOURCE_DIRS.hg,
+ hg_version,
+ ),
+ (
+ "Evolve",
+ "https://www.mercurial-scm.org/repo/evolve",
+ SOURCE_DIRS.evolve,
+ evolve_version,
+ ),
+ (
+ "ShellExt",
+ "https://foss.heptapod.net/mercurial/tortoisehg/thg-shellext",
+ SOURCE_DIRS.shellext,
+ shellext_version,
+ )
+ ]
+
+ for name, url, repo_dir, version in repos:
+ if repo_dir.exists():
+ print("Pulling %s" % name)
+ subprocess.run(
+ ["hg", "pull"],
+ cwd=str(repo_dir),
+ check=True,
+ )
+ else:
+ print("Cloning %s" % name)
+ subprocess.run(
+ ["hg", "clone", "--noupdate", url, str(repo_dir)],
+ check=True,
+ )
+
+ if version:
+ print("Updating %s to %s" % (name, version))
+ subprocess.run(
+ ["hg", "update", version],
+ cwd=str(repo_dir),
+ check=True,
+ )
+
+ print()
+
+
def get_parser():
parser = argparse.ArgumentParser()

@@ -193,6 +259,34 @@

sp.set_defaults(func=build_wix)

+ sp = subparsers.add_parser(
+ "stage", help="Stage the projects bundled into the installer"
+ )
+ sp.add_argument(
+ "--hg-version",
+ help=("The version of Mercurial to bundle. (default: 'stable')"),
+ default="stable",
+ )
+ sp.add_argument(
+ "--evolve-version",
+ help=("The version of evolve to bundle. (default: 'stable')"),
+ default="stable",
+ )
+ sp.add_argument(
+ "--shellext-version",
+ help=(
+ "The version of the shell extension to bundle. (default: 'default')"
+ ),
+ default="default",
+ )
+ sp.add_argument(
+ "--clean",
+ help="Reclone the dependencies",
+ action="store_true",
+ )
+
+ sp.set_defaults(func=stage_dependencies)
+
return parser


diff --git a/contrib/packaging/thgpackaging/util.py b/contrib/packaging/thgpackaging/util.py
--- a/contrib/packaging/thgpackaging/util.py
+++ b/contrib/packaging/thgpackaging/util.py
@@ -22,6 +22,23 @@
import zipfile


+class SourceDirs:
+ def __init__(self, source_dir: pathlib.Path):
+ self._dependencies = source_dir / "dependencies"
+
+ self.original = source_dir
+ self.evolve = self._dependencies / "evolve"
+ self.winbuild = self._dependencies / "winbuild"
+ self.hg = self.winbuild / "build" / "hg"
+ self.shellext = self.winbuild / "build" / "shellext"
+ self.thg = self.winbuild / "build" / "thg"
+
+ def clean(self):
+ if self._dependencies.exists():
+ print("Deleting dependencies")
+ shutil.rmtree(self._dependencies)
+
+
def extract_tar_to_directory(source: pathlib.Path, dest: pathlib.Path):
with tarfile.open(source, 'r') as tf:
tf.extractall(dest)
Reply all
Reply to author
Forward
0 new messages