[PATCH] v3: factor out check_hgpath

1 view
Skip to first unread message

Antonio Muci

unread,
Mar 24, 2025, 9:56:32 AMMar 24
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742824268 -3600
# Mon Mar 24 14:51:08 2025 +0100
# Branch stable
# Node ID 7f86ee44a14ddd9a5e36875b3e32c80b42c621c3
# Parent 22f03f8eddce89c39a6277dd41144d47b5b8e571
makefile: factor out common code in the "function" check_hgpath()

This change uses GNU Make specific syntax, as per:
https://stackoverflow.com/questions/6783243/functions-in-makefiles/74742720

I have verified with one of the FreeBSD maintainers for TortoiseHg that this
change would not impact packaging (this Makefile is for development only, and
Ports are a totally independent project), and the developers' workflow (because
it is common practice to use devel/gmake to work on upstream projects).

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,13 @@ ifneq ($(HGPATH),)
export PYTHONPATH := $(realpath $(HGPATH)):$(PYTHONPATH)
endif

+# the following syntax using "define" requires GNU Make
+define check_hgpath
+ @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified. Please run again with 'make $@ HGPATH=/path/to/hg'. For example, you could point to a checkout of the mercurial source code"; false; }
+ @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
+endef
+
.PHONY: help
help:
@echo 'Commonly used make targets:'
@@ -30,9 +37,7 @@ local:

.PHONY: tests
tests:
- @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified. Please run again with 'make $@ HGPATH=/path/to/hg'. For example, you could point to a checkout of the mercurial source code"; false; }
- @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
- @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
+ @$(call check_hgpath)
$(PYTHON) tests/run-tests.py -m 'not largefiles' --doctest-modules \
--ignore tortoisehg/hgqt/shellconf.py \
--ignore tortoisehg/util/bugtraq.py \
@@ -43,9 +48,7 @@ tests:
.PHONY: pytype
pytype: PYTHON_VERSION = 3.8
pytype:
- @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified. Please run again with 'make $@ HGPATH=/path/to/hg'. For example, you could point to a checkout of the mercurial source code"; false; }
- @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
- @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
+ @$(call check_hgpath)
$(PYTYPE) -P ".:$(HGPATH)" -V "$(PYTHON_VERSION)" -j auto \
--config pytype.cfg
@echo 'pytype crashed while generating the following type stubs:'
@@ -56,9 +59,7 @@ app: DISTDIR = dist/app
app: SETUPCFG = contrib/setup-py2app.cfg
app: export MACOSX_DEPLOYMENT_TARGET=10.7
app:
- @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified. Please run again with 'make $@ HGPATH=/path/to/hg'. For example, you could point to a checkout of the mercurial source code"; false; }
- @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
- @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
+ @$(call check_hgpath)
[ -z "$(SETUPCFG)" ] || cp "$(SETUPCFG)" setup.cfg
$(MAKE) -C "$(HGPATH)" local
FORCE_SETUPTOOLS= $(PYTHON) setup.py py2app -d "$(DISTDIR)"

Yuya Nishihara

unread,
Mar 24, 2025, 11:47:35 AMMar 24
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
Since we no longer pass positional arguments, maybe we can just expand
$(check_hgpath)?

https://www.gnu.org/software/make/manual/make.html#Canned-Recipes

Appears that the @ prefix can also be moved to caller, but I haven't
tested.
Reply all
Reply to author
Forward
0 new messages