add module dist-tuple which assists with port creation from github, gitlab,

and sourcehut sources. To use it, include MODULES+=dist-tuple. There are 2 ways
to make use of it:

DIST_TUPLE=github account project tagname_or_commithash

This extracts the archive into ${WRKDIR}.

DIST_TUPLE_MV=github account project tagname_or_commithash targetdir

It does the same, but also moves the extracted directory to targetdir. This is
useful when the port build system expects the files in that location for the
build.

Tested with many ports.

ok espie@ sthen@
This commit is contained in:
thfr
2023-09-02 17:30:14 +00:00
parent fd2c96dd56
commit f73b9327e2
2 changed files with 124 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
# known MASTER_SITES.x
MASTER_SITES.github ?= https://github.com/
MASTER_SITES.gitlab ?= https://gitlab.com/
MASTER_SITES.srht ?= https://git.sr.ht/
# EXTRACT_SUFX.x for each site
EXTRACT_SUFX.github ?= .tar.gz
EXTRACT_SUFX.gitlab ?= .tar.gz
EXTRACT_SUFX.srht ?= .tar.gz
# templates for the DISTFILES.x; the following user strings are recognized and substituted:
# - <account>
# - <project>
# - <id>
#
# (<_subdir> is for internal use based on recognition of tag format of <id>.)
TEMPLATE_DISTFILES.github ?= \
<account>-<project>-{<account>/<project>/archive/<_subdir>}<id>${EXTRACT_SUFX.github}
TEMPLATE_DISTFILES.gitlab ?= \
<account>-<project>-{<account>/<project>/-/archive/<id>/}<id>${EXTRACT_SUFX.gitlab}
TEMPLATE_DISTFILES.srht ?= \
<account>-<project>-{~<account>/<project>/archive/}<id>${EXTRACT_SUFX.srht}
# templates for HOMEPAGE; same substitutions as for DISTFILES.x
PROTO_HOMEPAGE.github ?= https://github.com/<account>/<project>
PROTO_HOMEPAGE.gitlab ?= https://gitlab.com/<account>/<project>
PROTO_HOMEPAGE.srht ?= https://git.sr.ht/~<account>/<project>
+93
View File
@@ -0,0 +1,93 @@
# DIST_TUPLE: basic form, 4 elements, doesn't move files after extraction
# Syntax:
# DIST_TUPLE += template account project id(commit/tag) # license
#
# Examples:
# DIST_TUPLE += github vim vim v9.0.1677 # VIM License / donation-ware
# DIST_TUPLE += gitlab Mr_Goldberg goldberg_emulator \
# 475342f0d8b2bd7eb0d93bd7cfdd61e3ae7cda24 # LGPLv3
DIST_TUPLE ?=
# DIST_TUPLE_MV: 5 elements, move files to targetdir after extraction
# Syntax:
# DIST_TUPLE_MV += template account project id(commit/tag) targetdir # license
#
# Example:
# DIST_TUPLE_MV += github FNA-XNA FNA.NetStub ebff244074bb3c28aeeb8cf7b383b5a029d7e28d \
# ../FNA.NetStub # Ms-PL
#
# Caveats:
# If DISTNAME isn't set and a tag is used for id, project-tag will be
# set as DISTNAME.
DIST_TUPLE_MV ?=
# needed to work with traditional MASTER_SITES + DISTNAME
.if defined(DISTNAME) && defined(MASTER_SITES)
DISTFILES ?= ${DISTNAME}${EXTRACT_SUFX}
.endif
.include "${PORTSDIR}/infrastructure/db/dist-tuple.pattern"
# DIST_TUPLE
.if !empty(DIST_TUPLE)
. for _template _account _project _id in ${DIST_TUPLE}
# check if _template is valid
. if empty(MASTER_SITES.${_template})
ERRORS += "Fatal: invalid choice for distexpand: ${_template}"
. endif
# detect GitHub tagname format
. if "${_template}" == "github"
_subdir =
_test_tagname = ${_id}
. if ${_test_tagname} == "HASH" || ${_test_tagname:C/^[0-9a-f]{40}$/HASH/} != "HASH"
# set DISTNAME if not done by the port and add refs/tags/ subdir
DISTNAME ?= ${_project}-${_id:S/^v//}
_subdir = refs/tags/
. endif
. endif
# set the variables for bsd.port.mk
DISTFILES.${_template} += ${TEMPLATE_DISTFILES.${_template}:S/<account>/${_account}/g:S/<project>/${_project}/g:S/<id>/${_id}/g:S/<_subdir>/${_subdir}/g}
. if !empty(TEMPLATE_HOMEPAGE.${_template})
HOMEPAGE ?= ${TEMPLATE_HOMEPAGE.${_template}:S/%account/${_account}/g:S/%project/${_project}/g}
. endif
. endfor
.endif
# DIST_TUPLE_MV (extended template with target directory)
.if !empty(DIST_TUPLE_MV)
. for _template _account _project _id _targetdir in ${DIST_TUPLE_MV}
# check if _template is valid
. if empty(MASTER_SITES.${_template})
ERRORS += "Fatal: invalid choice for distexpand: ${_template}"
. endif
# detect GitHub tagname format
. if "${_template}" == "github"
_subdir =
_test_tagname = ${_id}
. if ${_test_tagname} == "HASH" || ${_test_tagname:C/^[0-9a-f]{40}$/HASH/} != "HASH"
# set DISTNAME if not done by the port and add refs/tags/ subdir
DISTNAME ?= ${_project}-${_id:S/^v//}
_subdir = refs/tags/
. endif
. endif
# set the variables for bsd.port.mk
DISTFILES.${_template} += ${TEMPLATE_DISTFILES.${_template}:S/<account>/${_account}/g:S/<project>/${_project}/g:S/<id>/${_id}/g:S/<_subdir>/${_subdir}/g}
. if !empty(TEMPLATE_HOMEPAGE.${_template})
HOMEPAGE ?= ${TEMPLATE_HOMEPAGE.${_template}:S/%account/${_account}/g:S/%project/${_project}/g}
. endif
# add to post-extract target
MODDIST-TUPLE_post-extract += \
[[ -d ${WRKSRC}/${_targetdir} ]] && rmdir ${WRKSRC}/${_targetdir} \
|| mkdir -p `dirname ${WRKSRC}/${_targetdir}` ; \
mv ${WRKDIR}/${_project}-${_id:S/refs\/tags\///:S/^v//} ${WRKSRC}/${_targetdir} ;
. endfor
.endif