git: 934c0a2d759f - main - Uses/cabal.mk: Add support for building multi-repository cabal.projects.

From: Gleb Popov <arrowd_at_FreeBSD.org>
Date: Sun, 20 Nov 2022 17:40:02 UTC
The branch main has been updated by arrowd:

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

commit 934c0a2d759fe09a92739e4ed84e154b6d8e1970
Author:     Gleb Popov <arrowd@FreeBSD.org>
AuthorDate: 2022-11-20 16:35:05 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2022-11-20 17:39:29 +0000

    Uses/cabal.mk: Add support for building multi-repository cabal.projects.
    
    To build such projects a port must add the repository to MASTER_SITES under
    some group and then use this group in USE_CABAL.
    
    Cabal2Tuple (ports-mgmt/hs-cabal2tuple) supports this feature starting with
    version 2.0. Running `make make-use-cabal` will automatically pass necessary
    flags to it.
---
 Mk/Uses/cabal.mk | 45 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/Mk/Uses/cabal.mk b/Mk/Uses/cabal.mk
index 7d2aafc1534a..27237bde3974 100644
--- a/Mk/Uses/cabal.mk
+++ b/Mk/Uses/cabal.mk
@@ -145,12 +145,21 @@ BUILD_TARGET?=	${CABAL_EXECUTABLES:S/^/exe:&/}
 _use_cabal=	${USE_CABAL:O:u}
 
 .  for package in ${_use_cabal}
-.    for pkg_name xrev in ${package:C/_[0-9]+//} x${package:C/[^_]*//:S/_//}
+.    for pkg_without_group xgroup in ${package:C/:.*$$//} x${package:S/${package:C/:.*$$//}//:C/^.*://}
+.      for pkg_name xrev in ${pkg_without_group:C/_[0-9]+//} x${pkg_without_group:C/[^_]*//:S/_//}
+.        if ${xgroup} == "x"
 DISTFILES+=	${pkg_name}/${pkg_name}${CABAL_EXTRACT_SUFX}${_hackage_group}
-.    if ${xrev} != "x"
-DISTFILES+=	${pkg_name}/revision/${xrev:S/x//}.cabal${_hackage_group}
-.    endif
+.          if ${xrev} != "x"
+DISTFILES+=	${pkg_name}/revision/${xrev:S/^x//}.cabal${_hackage_group}
+.          endif
+.        else
+DISTFILES+=	${pkg_name}${CABAL_EXTRACT_SUFX}:${xgroup:S/^x//}
+.          if ${xrev} != "x"
+DISTFILES+=	${pkg_name}/revision/${xrev:S/^x//}.cabal:${xgroup:S/^x//}
+.          endif
+.        endif # ${xgroup} == "x"
 _CABAL_EXTRACT_ONLY+=	${pkg_name}/${pkg_name}${CABAL_EXTRACT_SUFX}
+.      endfor
 .    endfor
 .  endfor
 
@@ -162,6 +171,11 @@ EXTRACT_ONLY+= ${_CABAL_EXTRACT_ONLY}
 .    endif
 .  endif
 
+.  if defined(CABAL_REPOSITORIES) && !empty(CABAL_REPOSITORIES)
+.    for r in ${CABAL_REPOSITORIES}
+CABAL2TUPLE_ARGS+=	--group=${r} --master-site=${MASTER_SITES:M*\:${r}:[1]:S/:${r}//}
+.    endfor
+.  endif
 
 # Auxiliary targets used during port creation/updating.
 
@@ -175,7 +189,7 @@ cabal-extract: check-cabal
 	@${MAKE} -C ${.CURDIR} extract SKIP_CABAL_EXTRACT=yes USE_CABAL=
 	${RM} -rf ${CABAL_HOME}
 .  endif
-	@${ECHO_MSG} "===> Fetching Cabal package index into ${CABAL_HOME}/.cabal"
+	@${ECHO_MSG} "===> Fetching Hackage index into ${CABAL_HOME}/.cabal"
 	@${SETENV} HOME=${CABAL_HOME} ${CABAL_CMD} update
 .  if ${_hackage_is_default} == yes
 	@cd ${WRKDIR} && \
@@ -188,6 +202,11 @@ cabal-extract: check-cabal
 .  endif
 # Remove Haskell dependencies that come from GH_TUPLE
 	@${RM} -r ${WRKSRC}/dist-newstyle
+.  ifdef CABAL_REPOSITORIES
+	@${ECHO_MSG} "===> Fetching additional Cabal repositories index into ${CABAL_HOME}/.cabal"
+	@cd ${WRKSRC} && \
+		${SETENV} HOME=${CABAL_HOME} ${CABAL_CMD} update
+.  endif
 # Create a cookie for cabal-post-patch
 	@${TOUCH} ${EXTRACT_COOKIE} ${CABAL_COOKIE}
 
@@ -206,7 +225,7 @@ cabal-build: check-cabal
 # Generates USE_CABAL= ... line ready to be pasted into the port based on the plan.json file generated by cabal configure.
 make-use-cabal: check-cabal2tuple
 	@${ECHO_MSG} "===> Processing plan.json"
-	@${_CABAL2TUPLE_CMD} ${WRKSRC} || (${ECHO_CMD} "Did you forget to make cabal-configure ?" ; exit 1)
+	@${_CABAL2TUPLE_CMD} ${CABAL2TUPLE_ARGS} ${WRKSRC} || (${ECHO_CMD} "Did you forget to make cabal-configure ?" ; exit 1)
 .  if ${_hackage_is_default} == yes
 	@if ${GREP} -q 'x-revision' ${WRKSRC}/*.cabal; then \
 		${ECHO_MSG} "Downloaded .cabal file contains x-revision, make sure to add CABAL_REVISION=" `${GREP} 'x-revision' ${WRKSRC}/*.cabal | ${SED} -e s/x-revision://`; \
@@ -244,14 +263,16 @@ cabal-post-extract:
 # Move extracted dependencies into ${CABAL_DEPSDIR} directory
 	${MKDIR} ${CABAL_DEPSDIR}
 .    for package in ${_use_cabal}
-.      for pkg_name xrev in ${package:C/_[0-9]+//} x${package:C/[^_]*//:S/_//}
+.      for pkg_without_group in ${package:C/:.*$$//}
+.        for pkg_name xrev in ${pkg_without_group:C/_[0-9]+//} x${pkg_without_group:C/[^_]*//:S/_//}
 # Copy revised .cabal file if present
-.        if ${xrev} != "x"
-		${CP} ${DISTDIR}/${DIST_SUBDIR}/${pkg_name}/revision/${xrev:S/x//}.cabal `find ${WRKDIR}/${pkg_name} -name '*.cabal' -depth 1`
-.        endif
+.          if ${xrev} != "x"
+		${CP} ${DISTDIR}/${DIST_SUBDIR}/${pkg_name}/revision/${xrev:S/^x//}.cabal `find ${WRKDIR}/${pkg_name} -name '*.cabal' -depth 1`
+.          endif
 # Move the dependency source itself
 	cd ${WRKDIR} && \
 		${MV} ${pkg_name} ${CABAL_DEPSDIR}/
+.        endfor
 .      endfor
 .    endfor
 # Create the cabal-install config
@@ -268,8 +289,10 @@ cabal-post-patch:
 	${ECHO_CMD} "-- added by USES=cabal" >> ${WRKSRC}/cabal.project.local
 	${ECHO_CMD} "packages:" >> ${WRKSRC}/cabal.project.local
 .    for package in ${_use_cabal}
-.      for pkg_name in ${package:C/_[0-9]+//}
+.      for pkg_without_group in ${package:C/:.*$$//}
+.        for pkg_name in ${pkg_without_group:C/_[0-9]+//}
 	${ECHO_CMD} "        ${CABAL_DEPS_SUBDIR}/${pkg_name}" >> ${WRKSRC}/cabal.project.local
+.        endfor
 .      endfor
 .    endfor
 .  endif # SKIP_CABAL_EXTRACT && !CABAL_COOKIE