[PATCH] v2: factor out check_hgpath

2 views
Skip to first unread message

Antonio Muci

unread,
Mar 24, 2025, 9:00:21 AMMar 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 6fec45b3b44e22ae5a8897463b72a8b05d7bb11d
# 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: $(1)"; false; }
+ @[ -d "$(1)" ] || { echo "HGPATH must be a directory: $(1)"; 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:'
@@ -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)"

Yuya Nishihara

unread,
Mar 24, 2025, 9:18:07 AMMar 24
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
Maybe we don't have to parameterize $(HGPATH)? It doesn't make sense to
substitute $(HGPATH) to $(1) whereas the name HGPATH is inlined.

i.e.

define check_hgpath
@[ -n "$(HGPATH)" ] ...
endef

tests:
$(check_hgpath)

WDYT?

Antonio Muci

unread,
Mar 24, 2025, 9:49:06 AMMar 24
to thg...@googlegroups.com, Yuya Nishihara

Makes sense, v3 arriving soon.

Please note that the GNU-specific syntax is "define XXX", so the opportunity to check with a third TortoiseHG developer using MacOS stands.

I was able to confirm with Gleb Popov (contributor to TortoiseHg and maintainer of the FreeBSD port) that using "define XXX" would be OK for a FreeBSD developer.

However, I have no contact with a TortoiseHg developer using MacOS (I only noticed MacOS when you indirectly pointed me to the existence of the "app" target).

Antonio.

Matt Harbison

unread,
Mar 24, 2025, 10:56:28 AMMar 24
to TortoiseHg Developers
I've got a mac.  What do you need me to try?  (I don't think pytype runs on mac.)

Antonio Muci

unread,
Mar 24, 2025, 11:44:57 AMMar 24
to thg...@googlegroups.com

On the "makefile: factor out common code in the "function" check_hgpath()" revision, on your Mac, try to run "make tests".

It shoud fail with:

    HGPATH not specified. Please run again with 'make tests HGPATH=/path/to/hg'. For example, you could point to a checkout of the mercurial source code
    make: *** [Makefile:40: tests] Error 1


If instead it fails with a syntax error, then the Makefile uses a syntax which is not compatible with MacOS's make.

If removing repeated code is important, we'd have to find a workaround. Otherwise feel free to drop the commit that introduces "define check_hgpath".

In every case, please consider pulling "makefile: apply consistently the checks on HGPATH to the "app" target, too".

Antonio

--
You received this message because you are subscribed to the Google Groups "TortoiseHg Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thg-dev+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/thg-dev/66a5c7bc-b9ad-43a3-bc52-a738828215d2n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages