debian: support a "chg-first" installation mechanism (hg is actually chg)
This mechanism builds chg such that it looks for `hg` to be available at
/usr/lib/mercurial/hg instead of in the $PATH as `hg`, and makes the `hg` in
/usr/bin be a symlink to `chg`.
It's important to note that the hg binary must continue to be named `hg`. If we
wanted to instead place it at /usr/bin/pyhg or something similar, we would need
to modify Mercurial to allow that basename. Failure to do so would break
Mercurial's shell aliases that use `hg`, `chg`, or `$HG`.
I don't know if we should ever have a setup like this be the default setup, but
I'm willing to get more information on our experience with it for making such a
determination. Actually making it the default might be rather involved, as we
don't maintain the official debian packaging rules.
Differential Revision: https://phab.mercurial-scm.org/D10020
--- a/contrib/packaging/debian/rules Thu Mar 04 00:31:18 2021 +0100
+++ b/contrib/packaging/debian/rules Thu Feb 04 17:34:20 2021 -0800
@@ -18,6 +18,10 @@
# DEB_HG_PYTHON_VERSIONS="3.7 3.8" make deb
DEB_HG_MULTI_VERSION?=0
+# Set to 1 to make /usr/bin/hg a symlink to chg, and move hg to
+# /usr/lib/mercurial/hg.
+DEB_HG_CHG_BY_DEFAULT?=0
+
CPUS=$(shell cat /proc/cpuinfo | grep -E ^processor | wc -l)
# By default, only build for the version of python3 that the system considers
@@ -40,6 +44,12 @@
DEB_HG_PYTHON_VERSIONS?=$(shell py3versions -vd)
endif
+ifeq ($(DEB_HG_CHG_BY_DEFAULT), 1)
+ # Important: the "real" hg must have a 'basename' of 'hg'. Otherwise, hg
+ # behaves differently when setting $HG and breaks aliases that use that.
+ export HGPATH=/usr/lib/mercurial/hg
+endif
+
export HGPYTHON3=1
export PYTHON=python3
@@ -86,3 +96,8 @@
cp contrib/bash_completion "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions/hg
mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions
cp contrib/zsh_completion "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
+ if [[ "$(DEB_HG_CHG_BY_DEFAULT)" -eq 1 ]]; then \
+ mkdir -p "$(CURDIR)"/debian/mercurial/usr/lib/mercurial; \
+ mv "$(CURDIR)"/debian/mercurial/usr/bin/hg "$(CURDIR)"/debian/mercurial/usr/lib/mercurial/hg; \
+ ln -s chg "$(CURDIR)"/debian/mercurial/usr/bin/hg; \
+ fi