[PATCH 1 of 3] makefile: for HGPATH, split the existence check and the "is a directory" check

5 views
Skip to first unread message

Antonio Muci

unread,
Mar 23, 2025, 10:21:48 PMMar 23
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742782235 -3600
# Mon Mar 24 03:10:35 2025 +0100
# Branch stable
# Node ID 6a65e0414f3d5c456933d46e2daea837a92931fb
# Parent 4306fdea53cf8b262f25b938a914cba81d832d11
makefile: for HGPATH, split the existence check and the "is a directory" check

Before this change, if a user mistakenly set HGPATH to point to a file (for
example, because he used <MERCURIAL_BASE>/hg/hg), he would receive the "HGPATH
not found" error, which would be confusing. Now he would receive an explicit
message that HGPATH needs to be a directory.

This commit makes apparent some code duplication. For now I propose to live with
that. There is the possibility of reducing it via a GNU-specific syntax, but it
would break compatibility with FreeBSD Make.

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,8 @@ local:
.PHONY: tests
tests:
@[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
- @[ -d "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
$(PYTHON) tests/run-tests.py -m 'not largefiles' --doctest-modules \
--ignore tortoisehg/hgqt/shellconf.py \
--ignore tortoisehg/util/bugtraq.py \
@@ -43,7 +44,8 @@ tests:
pytype: PYTHON_VERSION = 3.8
pytype:
@[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
- @[ -d "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
$(PYTYPE) -P ".:$(HGPATH)" -V "$(PYTHON_VERSION)" -j auto \
--config pytype.cfg
@echo 'pytype crashed while generating the following type stubs:'

Antonio Muci

unread,
Mar 23, 2025, 10:21:48 PMMar 23
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742777548 -3600
# Mon Mar 24 01:52:28 2025 +0100
# Branch stable
# Node ID 9129e25bf9fc25ffbe309e21425da06248682c21
# Parent 6a65e0414f3d5c456933d46e2daea837a92931fb
makefile: when HGPATH needs to be defined, but it's not, fail with an example

The commands "make tests" and "make pytype" require that the user sets HGPATH.
The Make syntax for doing it can be unintuitive for a non expert.
This change extends the error message, introducing an example for a
syntactically correct invocation, which also shows a possible actual value for
HGPATH.

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

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ local:

.PHONY: tests
tests:
- @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
+ @[ -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; }
$(PYTHON) tests/run-tests.py -m 'not largefiles' --doctest-modules \
@@ -43,7 +43,7 @@ tests:
.PHONY: pytype
pytype: PYTHON_VERSION = 3.8
pytype:
- @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
+ @[ -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; }

Antonio Muci

unread,
Mar 23, 2025, 10:21:48 PMMar 23
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742781824 -3600
# Mon Mar 24 03:03:44 2025 +0100
# Branch stable
# Node ID e4934cd7072fddad3c9fc24bc581f4268f246277
# Parent 9129e25bf9fc25ffbe309e21425da06248682c21
makefile: use GNU-specific syntax to factor common code out in the "function" check_hgpath()

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

This syntax does not work on FreeBSD's Make (verified in a VM).

I have privately contacted a FreeBSD TortoiseHg maintainer to verify if this
change can be accepted, or if it's best to avoid it.

I'll report back if he answers.

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

+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 +36,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 +47,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)")

Antonio Muci

unread,
Mar 24, 2025, 6:40:40 AMMar 24
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742777548 -3600
# Mon Mar 24 01:52:28 2025 +0100
# Branch stable
# Node ID 8b1e1df909713e4dc318b876511badd752fbe7a4
# Parent 9b9b3c16df18908fca2b7875e732794febf0aa82
makefile: when HGPATH needs to be defined, but it's not, fail with an example

The commands "make tests" and "make pytype" require that the user sets HGPATH.
The Make syntax for doing it can be unintuitive for a non expert.
This change extends the error message, introducing an example for a
syntactically correct invocation, which also shows a possible actual value for
HGPATH.

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

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ local:

.PHONY: tests
tests:
- @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
+ @[ -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; }
$(PYTHON) tests/run-tests.py -m 'not largefiles' --doctest-modules \
@@ -43,7 +43,7 @@ tests:
.PHONY: pytype
pytype: PYTHON_VERSION = 3.8
pytype:
- @[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
+ @[ -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; }

Antonio Muci

unread,
Mar 24, 2025, 6:40:40 AMMar 24
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1742782235 -3600
# Mon Mar 24 03:10:35 2025 +0100
# Branch stable
# Node ID 9b9b3c16df18908fca2b7875e732794febf0aa82
# Parent 019aed556f70ee6e4e8138353110019d433c2446
makefile: for HGPATH, split the existence check and the "is a directory" check

Before this change, if a user mistakenly set HGPATH to point to a file (for
example, because he used <MERCURIAL_BASE>/hg/hg), he would receive the "HGPATH
not found" error, which would be confusing. Now he would receive an explicit
message that HGPATH needs to be a directory.

This commit makes apparent some pre existing code duplication.

For now I propose to live with that. There is the possibility of reducing it via
a GNU-specific syntax (for example
https://stackoverflow.com/questions/6783243/functions-in-makefiles/74742720).

That will eventually be done in a dedicated patch at the end of the series.

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,8 @@ local:
.PHONY: tests
tests:
@[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
- @[ -d "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
$(PYTHON) tests/run-tests.py -m 'not largefiles' --doctest-modules \
--ignore tortoisehg/hgqt/shellconf.py \
--ignore tortoisehg/util/bugtraq.py \
@@ -43,7 +44,8 @@ tests:
pytype: PYTHON_VERSION = 3.8
pytype:
@[ -n "$(HGPATH)" ] || { echo "HGPATH not specified"; false; }
- @[ -d "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -e "$(HGPATH)" ] || { echo "HGPATH not found: $(HGPATH)"; false; }
+ @[ -d "$(HGPATH)" ] || { echo "HGPATH must be a directory: $(HGPATH)"; false; }
$(PYTYPE) -P ".:$(HGPATH)" -V "$(PYTHON_VERSION)" -j auto \

Yuya Nishihara

unread,
Mar 24, 2025, 8:17:25 AMMar 24
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
On Mon, 24 Mar 2025 11:40:37 +0100, 'Antonio Muci' via TortoiseHg
Developers wrote:
> # HG changeset patch
> # User Antonio Muci <a....@inwind.it>
> # Date 1742782235 -3600
> # Mon Mar 24 03:10:35 2025 +0100
> # Branch stable
> # Node ID 9b9b3c16df18908fca2b7875e732794febf0aa82
> # Parent 019aed556f70ee6e4e8138353110019d433c2446
> makefile: for HGPATH, split the existence check and the "is a
> directory" check

Queued the first two, thanks.
Reply all
Reply to author
Forward
0 new messages