contrib/packaging/debian/rules
author Kyle Lippincott <spectral@google.com>
Thu, 04 Feb 2021 17:34:20 -0800
changeset 46668 90481550467c
parent 45024 36178b5c9aeb
child 46844 2fd5e0054dd9
permissions -rwxr-xr-x
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
#!/usr/bin/make -f
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
# Uncomment this to turn on verbose mode.
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
# export DH_VERBOSE=1
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
45024
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
     5
# By default we build a .deb where the native components are built with the
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
     6
# current "default" version of py3 on the build machine. If you wish to build a
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
     7
# .deb that has native components built for multiple versions of py3:
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
     8
#
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
     9
#   1. install python3.x and python3.x-dev for each version you want
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    10
#   2. set DEB_HG_MULTI_VERSION=1 or DEB_HG_PYTHON_VERSIONS in your environment
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    11
#      (if both are set, DEB_HG_PYTHON_VERSIONS has precedence)
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    12
#
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    13
# If you choose `DEB_HG_MULTI_VERSION=1`, it will build for every "supported"
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    14
# version of py3 that's installed on the build machine. This may not be equal to
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    15
# the actual versions that are installed, see the comment above where we set
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    16
# DEB_HG_PYTHON_VERSIONS below. If you choose to set `DEB_HG_PYTHON_VERSIONS`
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    17
# yourself, set it to a space-separated string of python version numbers, like:
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    18
#   DEB_HG_PYTHON_VERSIONS="3.7 3.8" make deb
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    19
DEB_HG_MULTI_VERSION?=0
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    20
46668
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    21
# Set to 1 to make /usr/bin/hg a symlink to chg, and move hg to
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    22
# /usr/lib/mercurial/hg.
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    23
DEB_HG_CHG_BY_DEFAULT?=0
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    24
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
CPUS=$(shell cat /proc/cpuinfo | grep -E ^processor | wc -l)
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
45024
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    27
# By default, only build for the version of python3 that the system considers
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    28
# the 'default' (which should be the one invoked by just running 'python3'
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    29
# without a minor version). If DEB_HG_PYTHON_VERSIONS is set, this is ignored.
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    30
ifeq ($(DEB_HG_MULTI_VERSION), 1)
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    31
	# If we're building for multiple versions, use all of the "supported" versions
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    32
	# on the build machine. Note: the mechanism in use here (`py3versions`) is the
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    33
	# recommended one, but it relies on a file written by the python3-minimal
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    34
	# package, and this file is not dynamic and does not account for manual
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    35
	# installations, just the ones that would be installed by `python3-all`. This
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    36
	# includes the `-i` flag, which claims it's to list all "installed" versions,
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    37
	# but it doesn't. This was quite confusing, hence this tale of woe. :)
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    38
	DEB_HG_PYTHON_VERSIONS?=$(shell py3versions -vs)
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    39
else
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    40
	# If we're building for only one version, identify the "default" version on
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    41
	# the build machine and use that when building; this is just so that we don't
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    42
	# have to duplicate the rules below for multi-version vs. single-version. The
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    43
	# shebang line will still be /usr/bin/python3 (no minor version).
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    44
	DEB_HG_PYTHON_VERSIONS?=$(shell py3versions -vd)
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    45
endif
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    46
46668
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    47
ifeq ($(DEB_HG_CHG_BY_DEFAULT), 1)
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    48
	# Important: the "real" hg must have a 'basename' of 'hg'. Otherwise, hg
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    49
	# behaves differently when setting $HG and breaks aliases that use that.
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    50
	export HGPATH=/usr/lib/mercurial/hg
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    51
endif
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    52
43310
7574ccd87200 packaging: upgrade Debian packaging to build with Python 3
Denis Laxalde <denis@laxalde.org>
parents: 38051
diff changeset
    53
export HGPYTHON3=1
7574ccd87200 packaging: upgrade Debian packaging to build with Python 3
Denis Laxalde <denis@laxalde.org>
parents: 38051
diff changeset
    54
export PYTHON=python3
7574ccd87200 packaging: upgrade Debian packaging to build with Python 3
Denis Laxalde <denis@laxalde.org>
parents: 38051
diff changeset
    55
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    56
%:
43310
7574ccd87200 packaging: upgrade Debian packaging to build with Python 3
Denis Laxalde <denis@laxalde.org>
parents: 38051
diff changeset
    57
	dh $@ --with python3
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    58
45024
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    59
# Note: testing can be disabled using the standard `DEB_BUILD_OPTIONS=nocheck`
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    60
override_dh_auto_test:
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    61
	http_proxy='' dh_auto_test -- TESTFLAGS="-j$(CPUS)"
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    62
43310
7574ccd87200 packaging: upgrade Debian packaging to build with Python 3
Denis Laxalde <denis@laxalde.org>
parents: 38051
diff changeset
    63
override_dh_python3:
43313
a882c088dc2e packaging: use /usr/bin/python3 shebang for scripts in Debian
Denis Laxalde <denis@laxalde.org>
parents: 43310
diff changeset
    64
	dh_python3 --shebang=/usr/bin/python3
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
diff changeset
    65
43318
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    66
override_dh_auto_clean:
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    67
	$(MAKE) cleanbutpackages
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    68
	$(MAKE) -C contrib/chg clean
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    69
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    70
override_dh_auto_build:
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    71
	$(MAKE) all
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    72
	$(MAKE) -C contrib/chg all
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    73
45024
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    74
# Build the native extensions for a specfic python3 version (which must be
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    75
# installed on the build machine).
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    76
install-python%:
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    77
	python$* setup.py install --root "$(CURDIR)"/debian/mercurial --install-layout=deb
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    78
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    79
# Build the final package. This rule has a dependencies section that causes the
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    80
# native extensions to be compiled for every version of python3 listed in
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    81
# DEB_HG_PYTHON_VERSIONS.
36178b5c9aeb debian: support building a single deb for multiple py3 versions
Kyle Lippincott <spectral@google.com>
parents: 43320
diff changeset
    82
override_dh_auto_install: $(DEB_HG_PYTHON_VERSIONS:%=install-python%)
34407
0133ca39c688 deb: build and install chg
Kyle Lippincott <spectral@google.com>
parents: 34406
diff changeset
    83
	# chg
0133ca39c688 deb: build and install chg
Kyle Lippincott <spectral@google.com>
parents: 34406
diff changeset
    84
	make -C contrib/chg \
34625
f1c2552c2de7 build: "make deb" failed when the base path contained spaces
muxator <a.mux@inwind.it>
parents: 34407
diff changeset
    85
		DESTDIR="$(CURDIR)"/debian/mercurial \
34407
0133ca39c688 deb: build and install chg
Kyle Lippincott <spectral@google.com>
parents: 34406
diff changeset
    86
		PREFIX=/usr \
43318
cdf6db1f4faf packaging: distinguish clean and build steps from install in Debian
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43313
diff changeset
    87
		install
43320
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    88
	make install-doc PREFIX="$(CURDIR)"/debian/mercurial/usr
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    89
	cp contrib/hg-ssh "$(CURDIR)"/debian/mercurial/usr/bin
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    90
	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/mercurial
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    91
	cp contrib/hgk "$(CURDIR)"/debian/mercurial/usr/share/mercurial
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    92
	mkdir -p "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    93
	cp contrib/packaging/debian/*.rc "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
34407
0133ca39c688 deb: build and install chg
Kyle Lippincott <spectral@google.com>
parents: 34406
diff changeset
    94
	# completions
43320
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    95
	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    96
	cp contrib/bash_completion "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions/hg
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    97
	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions
7b638d25b8e4 packaging: ship only a single binary Debian package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43319
diff changeset
    98
	cp contrib/zsh_completion "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
46668
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
    99
	if [[ "$(DEB_HG_CHG_BY_DEFAULT)" -eq 1 ]]; then \
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
   100
		mkdir -p "$(CURDIR)"/debian/mercurial/usr/lib/mercurial; \
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
   101
		mv "$(CURDIR)"/debian/mercurial/usr/bin/hg "$(CURDIR)"/debian/mercurial/usr/lib/mercurial/hg; \
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
   102
		ln -s chg "$(CURDIR)"/debian/mercurial/usr/bin/hg; \
90481550467c debian: support a "chg-first" installation mechanism (hg is actually chg)
Kyle Lippincott <spectral@google.com>
parents: 45024
diff changeset
   103
	fi