On Thu, Sep 14, 2023 at 12:31:34PM +0200, Sebastien Marie wrote:
> Hi,
> 
> When trying to add codeberg to DIST_TUPLE stuff, I had a problem with the 
> name 
> used to extract the downloaded tarball.
> 
> codeberg.org is using the following scheme:
>   the downloaded file is at: 
> https://codeberg.org/<account>/<project>/archive/<id>.tar.gz
>   the tarball extracts at ${WRKDIR}/<project>/ (and not 
> ${WRKDIR}/<project>-<tag>/ as expected by DIST_TUPLE)
> 
> So I customized a bit dist-tuple.port.mk to be able to use a template for 
> this name.
> 
> The variable is named TEMPLATE_WRKSRC.x (using WRKSRC for the similarity with 
> a 
> port with only one distfile). But I am unsure about the name.
> 
> The following patch adds the machinery (and the doc) for using 
> TEMPLATE_WRKSRC., 
> and adds also codeberg in templates.
> 
> I tested several github ports which differents schemes, but more testing will 
> be 
> appreciate.
> 
> Thanks.
> -- 
> Sebastien Marie
> 
> diff /home/semarie/repos/openbsd/ports
> commit - d3b35887e0ba204a5916da1942dd81f98bfc2148
> path + /home/semarie/repos/openbsd/ports
> blob - b4bf842539bf825f55e78520f17b026f654419bb
> file + infrastructure/mk/dist-tuple.port.mk
> --- infrastructure/mk/dist-tuple.port.mk
> +++ infrastructure/mk/dist-tuple.port.mk
> @@ -38,9 +38,10 @@ HOMEPAGE ?=        
> ${TEMPLATE_HOMEPAGE.${_template}:S/<accoun
>  
>  .    if "${_targetdir}" != "."
>  MODDIST-TUPLE_post-extract += \
> +     
> s=${TEMPLATE_WRKSRC.${_template}:S/<account>/${_account}/g:S/<project>/${_project}/g:S/<id>/${_id:S/refs\/tags\///:S/^v//}/g:S/<subdir>/${_subdir}/g};
>  \
>       t=${WRKDIST}/${_targetdir}; [[ -d $$t ]] && rmdir $$t \
>       || mkdir -p `dirname $$t` ; \
> -     mv ${WRKDIR}/${_project}-${_id:S/refs\/tags\///:S/^v//} $$t;
> +     mv ${WRKDIR}/$$s $$t;
>  .    endif
>  
>  .  endfor
> diff /home/semarie/repos/openbsd/ports
> commit - d3b35887e0ba204a5916da1942dd81f98bfc2148
> path + /home/semarie/repos/openbsd/ports
> blob - 3b11da9f1f4ef0be05caace3865d55f51d70d92c
> file + infrastructure/db/dist-tuple.pattern
> --- infrastructure/db/dist-tuple.pattern
> +++ infrastructure/db/dist-tuple.pattern
> @@ -1,9 +1,11 @@
>  # known MASTER_SITES.x
> +MASTER_SITES.codeberg ?=     https://codeberg.org/
>  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.codeberg ?=     .tar.gz
>  EXTRACT_SUFX.github ?=       .tar.gz
>  EXTRACT_SUFX.gitlab ?=       .tar.gz
>  EXTRACT_SUFX.srht ?= .tar.gz
> @@ -13,6 +15,9 @@ EXTRACT_SUFX.srht ?=        .tar.gz
>  # - <project>
>  # - <id>
>  # - <subdir> - used automatically if <id> is in tag format
> +TEMPLATE_DISTFILES.codeberg ?= \
> +     
> <account>-<project>-{<account>/<project>/archive/}<id>${EXTRACT_SUFX.codeberg}
> +
>  TEMPLATE_DISTFILES.github ?= \
>       
> <account>-<project>-{<account>/<project>/archive/<subdir>}<id>${EXTRACT_SUFX.github}
>  
> @@ -23,6 +28,13 @@ TEMPLATE_DISTFILES.srht ?= \
>       
> <account>-<project>-{~<account>/<project>/archive/}<id>${EXTRACT_SUFX.srht}
>  
>  # templates for HOMEPAGE; same substitutions as for DISTFILES.x
> +TEMPLATE_HOMEPAGE.codeberg ?=        https://codeberg.org/<account>/<project>
>  TEMPLATE_HOMEPAGE.github ?=  https://github.com/<account>/<project>
>  TEMPLATE_HOMEPAGE.gitlab ?=  https://gitlab.com/<account>/<project>
>  TEMPLATE_HOMEPAGE.srht ?=    https://git.sr.ht/~<account>/<project>
> +
> +# templates for extraction; same substitutions as for DISTFILES.x
> +TEMPLATE_WRKSRC.codeberg ?=  <project>
> +TEMPLATE_WRKSRC.github ?=    <project>-<id>
> +TEMPLATE_WRKSRC.gitlab ?=    <project>-<id>
> +TEMPLATE_WRKSRC.srht ?=              <project>-<id>
> diff /home/semarie/repos/openbsd/src
> commit - 5f7ea7bc25406ceab417284d038129723f0423a2
> path + /home/semarie/repos/openbsd/src
> blob - 099febdff4c5d7dba8b8aff137831c91abb57364
> file + share/man/man5/bsd.port.mk.5
> --- share/man/man5/bsd.port.mk.5
> +++ share/man/man5/bsd.port.mk.5
> @@ -1648,6 +1648,7 @@ List of distfile templates to use, each consisting of 
>  The template
>  .Ar name
>  should be one of
> +.Sq codeberg ,
>  .Sq github ,
>  .Sq gitlab ,
>  or
> @@ -1656,7 +1657,8 @@ at the moment
>  .Po see
>  .Pa ${PORTSDIR}/db/dist-tuple.pattern ,
>  additional
> -.Ev TEMPLATE_DISTFILES.<name>
> +.Ev TEMPLATE_DISTFILES.<name> ,
> +.Ev TEMPLATE_WRKSRC.<name>
>  and
>  .Ev TEMPLATE_HOMEPAGE.<name>
>  entries can be added as needed
> @@ -3452,6 +3454,12 @@ when using
>  .Ev DIST_TUPLE .
>  Very similar to
>  .Ev TEMPLATE_DISTFILES.<name> .
> +.It Ev TEMPLATE_WRKSRC.<name>
> +Template for automatically generated the name of the source
> +directory extracted when using
> +.Ev DIST_TUPLE .
> +Very similar to
> +.Ev TEMPLATE_DISTFILES.<name> .
>  .It Ev TEST_DEPENDS
>  See
>  .Ev BUILD_DEPENDS
> 
We should also stop defining TEMPLATE_WRKSRC.sufx and EXTRACT_SUFX.sufx
individually.

Setting it in the loop as
EXTRACT_SUFX.${_template} ?= ${EXTRACT_SUF}
and
TEMPLATE_WRKSRC.${_template} ?= ${TEMPLATE_WRKSRC}

makes things more regular

(along with setting
TEMPLATE_WRKSRC = ${WRKDIR}/<project>-<id>
TEMPLATE_WRKSRC.codeberg = ${WRKDIR}/<project>
)

Reply via email to