On Mon, 5 Oct 2026 16:42:56 +0100
Stuart Henderson <[email protected]> wrote:

> On 2026/10/05 05:24, Thomas Frohwein wrote:
> > - devel/jj-gh: non-standard GH tagnames (jj-gh-v0.3.1); therefore
> >   justifiable to require this to set WRKDIST manually. (There may
> > be a smarter regex for *_TAG_MOD.github that can avoid this.)  
> 
> > ok?  
> 
> this is not an unusual naming format - while it's uncommon for
> DIST_TUPLE you'll find 30-40 or so if you look at ports with
> GH_TAGNAME so would be good to handle it sooner rather than later
> (setting WRKDIST=${WRKDIR}/${DISTNAME} by hand isn't something that
> easily comes to mind..)

It took a bigger rewrite and some testing to arrive at what now avoids
the previous simplification that led to the regression with jj-gh and
others with a TAGNAME like abc-v0.1.2. Diff below, and ports that need
patches to deal with the changes (for good reasons) attached.

Reminder about the rationale for update: lack of DIST_TUPLE flexibility
is leading to an increasing number of workarounds in dist-tuple.port.mk
and individual ports. Examples include custom
MODDIST-TUPLE_post-extract for codeberg so far (and videolan has been
proposed), and a significant number of DIST_TUPLE users having to set
WRKDIST to make up for the limitations.
Ideally, DIST_TUPLE will arrive at: 1) all configuration for upstream
sites is done in the variables in db/dist-tuple.pattern, and 2) no
workarounds are needed in individual ports for the pertinent variables
like DISTNAME or WRKDIST.

The main thing to know for those who want to add new sites/templates
into dist-tuple.pattern is that TEMPLATE_EXTRACT_DIR.${template}.{hash
or tag} tell dist-tuple.port.mk what directory the upstream distfile
extracts to (relative path). Here, '<mod_id>' can be used in
combination with setting ID_MOD.${template}.{hash or tag} which is the
'id' part of DIST_TUPLE (4th element of the DIST_TUPLE string) modified
by the pertinent ID_MOD.x.y. This way, the flaw of the previous version
that such modification was applied to the whole string for WRKDIST is
now avoided.

As a result, workarounds for codeberg (custom
MODDIST-TUPLE_post-extract and setting WRKDIST) are not needed anymore.

This diff also fixes the issue with having to set WKRDIST in case of
gitlab with commit hashes (raised by ian in [1]). If/when the update in
this or a future version goes in, we should weed out the then
unnecessary WRKDIST lines.

I can comment on the internals of the new dist-tuple.port.mk structure
upon request. There may be opportunities to refine a few things, like
that there is quite a bit of duplication between the # tag mode and #
hash mode sections that I couldn't find a way to improve sanely.

I ran this diff with the attached patches through a complete bulk build
and no errors attributable to this. Rationale for the diffs with some
explanation why I think they are a necessary step now below in response
to sthen's useful WRKDIST before-after comparison.

ok?

Comments on individual ports:

> diffing output from 'make show=WRKDIST' before+after patching shows
> these discrepancies:

>  ===> devel/bazel  
> -/usr/obj/ports/bazel-6.5.0/bazel-6.5.0
> +/usr/obj/ports/bazel-6.5.0/abseil-cpp-20230802.1

DIST_TUPLE logic (built on in this diff) is that a tuple with targetdir
'.' is the main one and gets to set DISTNAME and WRKDIST if not done
by the port. This leads to priority conflicts in bazel because of
combination of SITES+DISTNAME and DIST_TUPLE with '.'. DIST_TUPLE wins
because of the location where modules.port.mk is included in
bsd.port.mk. The result in bazel still builds, but the WRKDIST is wrong.

I think we need to accept that such combinations of different ways to
get distfiles sometimes need setting WRKDIST, and this is done easily
here with WRKDIST=${WRKDIR}/${DISTNAME}.

Similar for lang/nim (SITES+DISTNAME and 8(sic) DIST_TUPLE with '.').

>  ===> devel/stylua  
> -/usr/obj/ports/stylua-2.5.2/stylua-2.5.2
> +/usr/obj/ports/stylua-2.5.2/StyLua-2.5.2

This still works and isn't "wrong". This is DIST_TUPLE using what is
extracted. Issues come from DISTNAME's dual use - one is to inform
PKGNAME later, and one is to tell bsd.port.mk the WRKDIST. 

>  ===> games/love/12  
> -/usr/obj/ports/love-12.0alpha0/love-4e167072ae558e114cacec28ad5abb2ec2cdf05c
> +

Should already be a non-issue since [2].

>  ===> net/validns  
> -/usr/obj/ports/validns-0.11.0/validns-0.11.0
> +/usr/obj/ports/validns-0.11.0/validns

Does the right thing here. Port has been setting
WRKSRC=${WRKDIR}/validns which is now done by DIST_TUPLE in WRKDIST and
this workaround can go away.

>  ===> sysutils/py-tsk  
> -/usr/obj/ports/py-tsk-20260715/pytsk3-20260715
> +/usr/obj/ports/py-tsk-20260715/pytsk-20260715

Similar to bazel. This time competition between if MODPY or DIST_TUPLE
gets to set WRKDIST. DIST_TUPLE which now actually sets WRKDIST wins; if
desired we could look into changing its place in the order of
modules.port.mk, but I don't think this is needed.

[1] https://marc.info/?l=openbsd-ports&m=178992069266352&w=2
[2] https://marc.info/?l=openbsd-ports-cvs&m=179218341526029&w=2

Index: db/dist-tuple.pattern
===================================================================
RCS file: /cvs/ports/infrastructure/db/dist-tuple.pattern,v
diff -u -p -r1.13 dist-tuple.pattern
--- db/dist-tuple.pattern       16 Jan 2026 06:12:28 -0000      1.13
+++ db/dist-tuple.pattern       15 Oct 2026 14:23:19 -0000
@@ -36,6 +36,20 @@ TEMPLATE_DISTFILES.kde ?= \
 TEMPLATE_DISTFILES.srht ?= \
        
<account>-<project>-{~<account>/<project>/archive/}<id>${EXTRACT_SUFX.srht}
 
+# Template for the directory created upon extraction of the distfile.
+# This is used 1) for setting WRKDIST where needed, and 2) to use the
+# correct path for the post-extract target. 
+# Format: TEMPLATE_EXTRACT_DIR.x.y, where x is the template and y is
+# either tag or hash
+# Defaults to a (heuristically modified) version of <project>-<id>.
+# Can use <mod_id>: the <id> string, modified with ID_MOD.x.y,
+# according to make(1) rules.
+TEMPLATE_EXTRACT_DIR.codeberg.tag ?=           <project>
+TEMPLATE_EXTRACT_DIR.codeberg.hash ?=  <project>
+
+TEMPLATE_EXTRACT_DIR.github.tag ?=             <project>-<mod_id>
+ID_MOD.github.tag ?=                   :C/^(v|V)([0-9])/\2/
+
 # template for HOMEPAGE; same substitutions as for DISTFILES.x
 # Defaults to TEMPLATE_HOMEPAGE. Set TEMPLATE_HOMEPAGE.x to use different 
pattern.
 # - <site> - substituted, may correspond to SITES.x
Index: mk/bsd.port.mk
===================================================================
RCS file: /cvs/ports/infrastructure/mk/bsd.port.mk,v
diff -u -p -r1.1652 bsd.port.mk
--- mk/bsd.port.mk      19 Sep 2026 23:17:29 -0000      1.1652
+++ mk/bsd.port.mk      15 Oct 2026 14:23:19 -0000
@@ -897,8 +897,6 @@ WRKDIST ?= ${WRKDIR}/${GH_PROJECT}-${GH_
 WRKDIST ?= ${WRKDIR}/${GH_PROJECT}-${GH_COMMIT}
 .elif defined(DISTNAME)
 WRKDIST ?= ${WRKDIR}/${DISTNAME}
-.elif !empty(_DT_WRKDIST)
-WRKDIST ?= ${_DT_WRKDIST}
 .else
 WRKDIST ?= ${WRKDIR}
 .endif
Index: mk/dist-tuple.port.mk
===================================================================
RCS file: /cvs/ports/infrastructure/mk/dist-tuple.port.mk,v
diff -u -p -r1.22 dist-tuple.port.mk
--- mk/dist-tuple.port.mk       1 Apr 2026 15:14:57 -0000       1.22
+++ mk/dist-tuple.port.mk       15 Oct 2026 14:23:19 -0000
@@ -1,14 +1,14 @@
 # DIST_TUPLE: 5 elements
 # use targetdir=. if you don't want to move files after extraction
 # Syntax:
-# DIST_TUPLE +=        template account project id(commit/tag) targetdir # 
license
+# DIST_TUPLE +=        template account project id(commit/tag) targetdir
 #
 # Examples:
-# DIST_TUPLE +=        github vim vim v9.0.1677 . # VIM License / donation-ware
+# DIST_TUPLE +=        github vim vim v9.0.1677 .
 # DIST_TUPLE +=        gitlab Mr_Goldberg goldberg_emulator \
-#              475342f0d8b2bd7eb0d93bd7cfdd61e3ae7cda24 . # LGPLv3
+#              475342f0d8b2bd7eb0d93bd7cfdd61e3ae7cda24 .
 # DIST_TUPLE +=        github FNA-XNA FNA.NetStub 
ebff244074bb3c28aeeb8cf7b383b5a029d7e28d \
-#                      ../FNA.NetStub # Ms-PL
+#                      ../FNA.NetStub
 DIST_TUPLE ?=
 
 # Caveats:
@@ -18,40 +18,71 @@ DIST_TUPLE ?=
 .include "${PORTSDIR}/infrastructure/db/dist-tuple.pattern"
 
 .if !empty(DIST_TUPLE)
-.  for _template _account _project _id _targetdir in ${DIST_TUPLE}
 
-.    if empty(SITES.${_template})
+.  for __template __account __project __id __targetdir in ${DIST_TUPLE}
+
+.    for __id_type in tag hash
+# inert substitution by default; this can't be an empty element
+ID_MOD.${__template}.${__id_type} ?= :S///
+.    endfor
+
+.    for _template _account _project _id _id_mod_tag _id_mod_hash _targetdir 
in ${__template} ${__account} ${__project} ${__id} ${ID_MOD.${__template}.tag} 
${ID_MOD.${__template}.hash} ${__targetdir}
+
+.      if empty(SITES.${_template})
 ERRORS += "Fatal: invalid choice for DIST_TUPLE: ${_template}"
-.    endif
+.      endif
 
-_subdir =
-.    if "${_id}" == "HASH" || "${_id:C/^[0-9a-f]{10,40}$/HASH/}" != "HASH"
-# set DISTNAME if not done by the port and add refs/tags/ subdir
-_distname ?= 
${_project}-${_id:C/^(v|V|ver|[Rr]el|[Rr]elease)[-._]?([0-9])/\2/:S,/,-,g}
-DISTNAME ?= ${_distname}
-_subdir =      refs/tags/
-_DT_WRKDIST ?= ${WRKDIR}/${_distname}
-.    else
-_DT_WRKDIST ?= ${WRKDIR}/${_project:C,^.*/,,}-${_id}
+# create _FULL_DIST_TUPLE with derived variables
+_FULL_DIST_TUPLE += ${_template} ${_account} ${_project} ${_id} ${_targetdir}
+
+.      if "${_id}" == "HASH" || "${_id:C/^[0-9a-f]{10,40}$/HASH/}" != "HASH"
+# tag mode
+_FULL_DIST_TUPLE += tag
+_FULL_DIST_TUPLE += 
${_project}-${_id:C/^(v|V|ver|[Rr]el|[Rr]elease)[-._]?([0-9])/\2/:S,/,-,g}
+.        if !empty(TEMPLATE_EXTRACT_DIR.${_template}.tag)
+_FULL_DIST_TUPLE += ${TEMPLATE_EXTRACT_DIR.${_template}.tag}
+.        else
+_FULL_DIST_TUPLE += <defaultname>
+.        endif
+# XXX: refs/tags/ is only useful for template github
+_FULL_DIST_TUPLE += 
S,<account>,${_account},g:S,<project>,${_project},g:S,<id>,${_id},g:S,<subdir>,refs/tags/,g:S,<site>,${SITES.${_template}},g:S,<defaultname>,${_project}-${_id:C/^(v|V|ver|[Rr]el|[Rr]elease)[-._]?([0-9])/\2/:S,/,-,g},g:S,<mod_id>,${_id${_id_mod_tag}},g
+
+.      else
+# hash mode
+_FULL_DIST_TUPLE += hash
+_FULL_DIST_TUPLE += ${_project}-${_id}
+.        if !empty(TEMPLATE_EXTRACT_DIR.${_template}.hash)
+_FULL_DIST_TUPLE += ${TEMPLATE_EXTRACT_DIR.${_template}.hash}
+.        else
+_FULL_DIST_TUPLE += <defaultname>
+.        endif
+_FULL_DIST_TUPLE += 
S,<account>,${_account},g:S,<project>,${_project},g:S,<id>,${_id},g:S,<subdir>,,g:S,<site>,${SITES.${_template}},g:S,<defaultname>,${_project}-${_id},g:S,<mod_id>,${_id${_id_mod_hash}},g
+.      endif
+.    endfor
+.  endfor
+
+.  for _template _account _project _id _targetdir _mode _defaultname 
_extrdir_temp _subst in ${_FULL_DIST_TUPLE}
+
+.    if "${_mode}" == "tag" && !defined(GH_TAGNAME)
+# Yield to GH_TAGNAME; it takes precedence and is set later in bsd.port.mk 
with ?=.
+# Only set DISTNAME for tag; commit hashes are not desired for this.
+DISTNAME ?= ${_defaultname}
 .    endif
 
-.    for _subst in 
S,<account>,${_account},g:S,<project>,${_project},g:S,<id>,${_id},g:S,<subdir>,${_subdir},g:S,<site>,${SITES.${_template}},g
+.    for _extrdir in ${_extrdir_temp:${_subst}}
 
 DISTFILES.${_template} +=              
${TEMPLATE_DISTFILES.${_template}:${_subst}}
 EXTRACT_SUFX.${_template} ?=           ${TEMPLATE_EXTRACT_SUFX}
 TEMPLATE_HOMEPAGE.${_template} ?=      ${TEMPLATE_HOMEPAGE}
-HOMEPAGE ?=    ${TEMPLATE_HOMEPAGE.${_template}:${_subst}}
+HOMEPAGE ?=                            
${TEMPLATE_HOMEPAGE.${_template}:${_subst}}
 
-.      if "${_targetdir}" != "." && "${_template}" == "codeberg"
-MODDIST-TUPLE_post-extract += \
-       t=${WRKDIST}/${_targetdir}; [[ -d $$t ]] && rmdir $$t \
-       || mkdir -p `dirname $$t` ; \
-       mv ${WRKDIR}/${_project:T} $$t;
-.      elif "${_targetdir}" != "."
+.      if "${_targetdir}" == "."
+WRKDIST ?= ${WRKDIR}/${_extrdir}
+.      else
 MODDIST-TUPLE_post-extract += \
        t=${WRKDIST}/${_targetdir}; [[ -d $$t ]] && rmdir $$t \
        || mkdir -p `dirname $$t` ; \
-       mv ${WRKDIR}/${_project:T}-${_id:S/refs\/tags\///:C/^v([0-9])/\1/} $$t;
+       mv ${WRKDIR}/${_extrdir} $$t;
 .      endif
 .    endfor
 
Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/nim/Makefile,v
diff -u -p -r1.28 Makefile
--- Makefile	17 Sep 2026 17:31:35 -0000	1.28
+++ Makefile	3 Oct 2026 21:45:26 -0000
@@ -45,6 +45,8 @@ TEST_DEPENDS =		archivers/7zip,-main \
 			devel/pcre \
 			lang/node \
 			multimedia/sfml
+
+WRKDIST =		${WRKDIR}/${DISTNAME}
 
 SUBST_VARS +=		CFLAGS
 
Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/bazel/Makefile,v
diff -u -p -r1.12 Makefile
--- Makefile	22 Sep 2026 08:38:51 -0000	1.12
+++ Makefile	15 Oct 2026 07:32:59 -0000
@@ -38,6 +38,8 @@ INSTALL_STRIP =
 
 MAKE_ENV =		VERBOSE=yes
 
+WRKDIST =		${WRKDIR}/${DISTNAME}
+
 # The bundled version of abseil is from 2021 and isn't compatible with clang-16.
 # It also needs some patches we copy from devel/abseil.
 post-patch:
Index: Makefile
===================================================================
RCS file: /cvs/ports/sysutils/py-tsk/Makefile,v
diff -u -p -r1.26 Makefile
--- Makefile	28 Aug 2026 19:44:28 -0000	1.26
+++ Makefile	10 Oct 2026 10:05:04 -0000
@@ -29,6 +29,8 @@ WANTLIB += ${COMPILER_LIBCXX} m
 # C++11
 COMPILER=	base-clang ports-gcc
 
+WRKDIST =	${WRKDIR}/${DISTNAME}
+
 post-extract:
 	mv ${WRKDIR}/pytsk-${MODPY_DISTV}/tests/* ${WRKSRC}/tests/
 
Index: Makefile
===================================================================
RCS file: /cvs/ports/net/validns/Makefile,v
diff -u -p -r1.9 Makefile
--- Makefile	25 Jul 2026 16:58:20 -0000	1.9
+++ Makefile	10 Oct 2026 09:51:22 -0000
@@ -25,6 +25,4 @@ AUTORECONF =		./autogen.sh
 
 CONFIGURE_ENV =	CPPFLAGS="-I${LOCALBASE}/include" LDFLAGS="-L${LOCALBASE}/lib"
 
-WRKSRC = 	${WRKDIR}/validns
-
 .include <bsd.port.mk>

Reply via email to