git: eef4d4a98ab1 - main - Uses/display.mk: Overhaul the module

From: Gleb Popov <arrowd_at_FreeBSD.org>
Date: Mon, 20 Oct 2025 13:29:32 UTC
The branch main has been updated by arrowd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=eef4d4a98ab1975ba60425ca847851d4cbb762f7

commit eef4d4a98ab1975ba60425ca847851d4cbb762f7
Author:     Gleb Popov <arrowd@FreeBSD.org>
AuthorDate: 2025-10-15 16:25:33 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2025-10-20 13:27:48 +0000

    Uses/display.mk: Overhaul the module
    
    - Stop determining the free display port number. The whole block is under the
      `!defined(DISPLAY)` condition and at the time `Xvfb` starts the `:0` port
      is guaranteed to be available.
    - Allow multiple values in the USES args.
    - Set *_ENV and *_DEPENDS more granularly.
    
    Approved by: bapt
    Differential Revision: https://reviews.freebsd.org/D53122
    Fixes: 453ec167a9f355e674cd35406725e0437cef722b
---
 Mk/Uses/display.mk | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/Mk/Uses/display.mk b/Mk/Uses/display.mk
index e46fb10d1bba..b5471b95a8ce 100644
--- a/Mk/Uses/display.mk
+++ b/Mk/Uses/display.mk
@@ -1,6 +1,6 @@
 # Feature:	display
 # Usage:	USES=display or USES=display:ARGS
-# Valid ARGS:	install (default, implicit), any target
+# Valid ARGS:	install (default, implicit), configure, build
 # 
 # Except the target where the DISPLAY is needed
 #
@@ -14,24 +14,39 @@ display_ARGS=	install
 .  endif
 
 .  if !defined(DISPLAY)
-BUILD_DEPENDS+=	Xvfb:x11-servers/xorg-server@xvfb \
+
+.    if ${display_ARGS:Mconfigure}
+DISPLAY_DEPENDS=	BUILD_DEPENDS
+CONFIGURE_ENV+=		DISPLAY=":${XVFBPORT}"
+.    elif ${display_ARGS:Mbuild}
+DISPLAY_DEPENDS=	BUILD_DEPENDS
+MAKE_ENV+=		DISPLAY=":${XVFBPORT}"
+.    elif ${display_ARGS:Mtest}
+DISPLAY_DEPENDS=	TEST_DEPENDS
+TEST_ENV+=		DISPLAY=":${XVFBPORT}"
+.else
+IGNORE=			USES=display: invalid arguments: ${display_ARGS}
+.endif
+
+${DISPLAY_DEPENDS}+= \
+	Xvfb:x11-servers/xorg-server@xvfb \
 	${LOCALBASE}/share/fonts/misc/8x13O.pcf.gz:x11-fonts/xorg-fonts-miscbitmaps \
 	${LOCALBASE}/share/fonts/misc/fonts.alias:x11-fonts/font-alias \
 	${LOCALBASE}/share/X11/xkb/rules/base:x11/xkeyboard-config \
 	xkbcomp:x11/xkbcomp
 
-XVFBPORT!=	port=0; while test -S /tmp/.X11-unix/X$${port} ; do port=$$(( port + 1 )) ; done ; ${ECHO_CMD} $$port
-PREV_XVFBPORT!=	${ECHO_CMD} $$(( ${XVFBPORT} - 1))
-XVFBPIDFILE=	/tmp/.xvfb-${XVFBPORT}.pid
-PREV_XVFBPIDFILE=	/tmp/.xvfb-${PREV_XVFBPORT}.pid
-MAKE_ENV+=	DISPLAY=":${XVFBPORT}"
+XVFBPORT?=	0
+XVFBPIDFILE=	/tmp/.xvfb-${XVFBPORT}-display-mk.pid
 
-_USES_${display_ARGS}+=	290:start-display 860:stop-display
+.    for t in ${display_ARGS}
+_USES_${t}+=	290:start-display 860:stop-display
+.    endfor
 start-display:
+	pkill -15 -F ${XVFBPIDFILE} || ${TRUE}
 	daemon -p ${XVFBPIDFILE} Xvfb :${XVFBPORT}
 
 stop-display:
-	pkill -15 -F ${PREV_XVFBPIDFILE}
+	pkill -15 -F ${XVFBPIDFILE}
 
 .  endif
 .endif