[PATCH 3 of 3] makefile: factor out common code in the "function" check_hgpath()

1 view
Skip to first unread message

Antonio Muci

unread,
Mar 24, 2025, 10:40:40 AM (6 days ago) Mar 24
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742812110 -3600
# Mon Mar 24 11:28:30 2025 +0100
# Branch stable
# Node ID 01a869f074da5772386e1de876eddcdadca5c9ae
# Parent 8b1e1df909713e4dc318b876511badd752fbe7a4
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 requires GNU Make
+define check_hgpath
+ @[ -n "$(1)" ] || { 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 "$(1)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -d "$(1)" ] || { 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,"$(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,"$(HGPATH)")
$(PYTYPE) -P ".:$(HGPATH)" -V "$(PYTHON_VERSION)" -j auto \
--config pytype.cfg
@echo 'pytype crashed while generating the following type stubs:'

Yuya Nishihara

unread,
Mar 24, 2025, 12:17:27 PM (6 days ago) Mar 24
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
I didn't know the positional argument syntax, but if we use it, I think
all $(HGPATH) and the variable name HGPATH should be replaced
consistently.

Antonio Muci

unread,
Mar 24, 2025, 12:52:40 PM (6 days ago) Mar 24
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742812110 -3600
# Mon Mar 24 11:28:30 2025 +0100
# Branch stable
# Node ID 705ed7a61fcd05c5dd79818d96defa214fe28c91
# 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 requires GNU Make
+define check_hgpath
+ @[ -n "$(1)" ] || { 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 "$(1)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -d "$(1)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
+endef
@@ -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,"$(HGPATH)")
[ -z "$(SETUPCFG)" ] || cp "$(SETUPCFG)" setup.cfg
$(MAKE) -C "$(HGPATH)" local
FORCE_SETUPTOOLS= $(PYTHON) setup.py py2app -d "$(DISTDIR)"

Antonio Muci

unread,
Mar 24, 2025, 12:55:09 PM (6 days ago) Mar 24
to thg...@googlegroups.com
I suspect that this is used on MacOS by whoever builds the MacOS
application (is it Matt or the CI?), and I have no access to a MacOS system.

Please hold back integrating this until a signoff by you (Yuya) or Matt.


Thanks.

Antonio

Antonio Muci

unread,
Mar 24, 2025, 1:06:07 PM (6 days ago) Mar 24
to thg...@googlegroups.com, Yuya Nishihara
After two attempts, I think I got all of your advice.

I've submitted:

- a patch that introduces HGPATH check also on the "app" target. I think
that one can be integrated with no problems

- a v2 for the change that introcudes check_hgpath() in the Makefile,
because I did not get your invitation to be consistent in using $(1). I
think this v2 should be held back until we hear from someone that uses
MacOS.


Antonio
Reply all
Reply to author
Forward
0 new messages