I took this a bit further and I get a working devel/happy package now.

This is still a complete WIP but I wanted to get some early feedback on
the implementation choices as this is my first foray into port-modules.

The patch is currently tested on top of a bunch of hacked ghc-8.10 and
cabal-3.4 patches. I'll have to figure out if there's a way to go back
to ghc-8.6 and cabal-2.4.

Thanks
Greg

>From 44e3d9a1b52ffd5ef6ff327d929fe22977c77082 Mon Sep 17 00:00:00 2001
From: Greg Steuck <g...@nest.cx>
Date: Thu, 20 Aug 2020 11:54:08 -0700
Subject: [PATCH] Build devel/happy with cabal v2-install

Passes `make test` and produces a package good enough for ghc build.
---
 devel/cabal/cabal.port.mk | 92 +++++++++++++++++++++++++++++++++++++++
 devel/happy/Makefile      | 15 ++++---
 devel/happy/distinfo      |  4 +-
 devel/happy/pkg/PLIST     |  4 +-
 4 files changed, 105 insertions(+), 10 deletions(-)
 create mode 100644 devel/cabal/cabal.port.mk

diff --git devel/cabal/cabal.port.mk devel/cabal/cabal.port.mk
new file mode 100644
index 00000000000..d48c4a29c14
--- /dev/null
+++ devel/cabal/cabal.port.mk
@@ -0,0 +1,92 @@
+# $OpenBSD$
+
+# Module for building Haskell programs with cabal-install.
+# Inspired by FreeBSD cabal.mk by Gleb Popov.
+
+ONLY_FOR_ARCHS =	i386 amd64
+
+BUILD_DEPENDS+=	devel/cabal \
+		lang/ghc
+
+.if ${MODCABAL_BUILD:L:Mhackage}
+MODGHC_HACKAGE_NAME =		${DISTNAME:C,-[0-9.]*$,,}
+MODGHC_HACKAGE_VERSION =	${DISTNAME:C,.*-([0-9.]*)$,\1,}
+HOMEPAGE ?=			https://hackage.haskell.org/package/${MODGHC_HACKAGE_NAME}
+MASTER_SITES =			https://hackage.haskell.org/package/${DISTNAME}/
+SUBST_VARS +=			DISTNAME MODGHC_HACKAGE_VERSION
+.endif
+
+MASTER_SITES0 = https://hackage.haskell.org/package/
+DIST_SUBDIR ?= hackage
+
+_MODCABAL_HOME=${WRKSRC}
+
+MODCABAL_post-extract = \
+	mkdir -p ${_MODCABAL_HOME}/.cabal \
+	&& touch ${_MODCABAL_HOME}/.cabal/config
+
+.if defined(MODCABAL_MANIFEST)
+
+.for package version revision in ${MODCABAL_MANIFEST}
+DISTFILES += {${package}-${version}/}${package}-${version}.tar.gz:0
+DISTFILES += ${package}-${version}_${revision}{${package}-${version}/revision/${revision}}.cabal:0
+.endfor
+
+
+MODCABAL_post-extract += \
+.for package version revision in ${MODCABAL_MANIFEST}
+	&& tar zxf ${FULLDISTDIR}/${package}-${version}.tar.gz -C ${WRKBUILD} \
+	&& ln -s ${FULLDISTDIR}/${package}-${version}_${revision}.cabal ${WRKBUILD}/_build/tarballs/${package}.cabal \
+.endfor
+.endif
+
+CABAL	=  ${SETENV} ${MAKE_ENV} HOME=${_MODCABAL_HOME} ${LOCALBASE}/bin/cabal
+
+MODCABAL_BUILD_ARGS = --datadir=${PREFIX}/share/${PKGNAME}
+_MODCABAL_BUILD_TARGETS ?=	${MODCABAL_EXECUTABLES:C/^/exe:&/}
+
+MODCABAL_BUILD_TARGET =	\
+	cd ${WRKBUILD} \
+	&& ${CABAL} v2-build --offline --disable-benchmarks --disable-tests \
+		--flags "${MODCABAL_FLAGS}" ${MODCABAL_BUILD_ARGS} ${MODCABAL_BUILD_TARGETS}
+
+_MODCABAL_LIBEXEC = libexec/cabal
+MODCABAL_INSTALL_TARGET = \
+	mkdir -p ${PREFIX}/${_MODCABAL_LIBEXEC}
+
+.for data in ${MODCABAL_DATA_DIRS}
+MODCABAL_INSTALL_TARGET += \
+	&& ${INSTALL_DATA_DIR} ${WRKSRC}/${data} ${PREFIX}/share/${DISTNAME} \
+	&& cd ${WRKSRC}/${data} && umask 022 && pax -rw . ${PREFIX}/share/${DISTNAME}
+.endfor
+
+.for exe in ${MODCABAL_EXECUTABLES}
+
+# Exports the paths to executables for testing.
+MODCABAL_BUILT_EXECUTABLE_${exe} = $$(find ${WRKSRC}/dist-newstyle -name ${exe} -type f -perm -a+x)
+
+.for data in ${MODCABAL_DATA_DIRS}
+_MODCABAL_EXPORTS += \
+	&& echo 'export ${exe}_datadir=${LOCALBASE}/share/${DISTNAME}' >> ${PREFIX}/bin/${exe}
+.endfor
+
+MODCABAL_INSTALL_TARGET += \
+	&& ${INSTALL_PROGRAM} \
+		${MODCABAL_BUILT_EXECUTABLE_${exe}} \
+		${PREFIX}/${_MODCABAL_LIBEXEC}/${exe} \
+	&& echo '\#!/bin/sh' > ${PREFIX}/bin/${exe} \
+	${_MODCABAL_EXPORTS} \
+	&& echo 'exec ${LOCALBASE}/${_MODCABAL_LIBEXEC}/${exe} "$$@"' >> ${PREFIX}/bin/${exe} \
+	&& chmod +x ${STAGEDIR}${PREFIX}/bin/${exe}
+.endfor
+
+
+.if !target(do-build)
+do-build:
+	@${MODCABAL_BUILD_TARGET}
+.endif
+
+.if !target(do-install)
+do-install:
+	@${MODCABAL_INSTALL_TARGET}
+.endif
diff --git devel/happy/Makefile devel/happy/Makefile
index 341a5ba2d73..8e1bede8bc3 100644
--- devel/happy/Makefile
+++ devel/happy/Makefile
@@ -2,9 +2,7 @@
 
 COMMENT=		parser generator for Haskell
 
-PORTROACH =		ignore:1
-
-DISTNAME=		happy-1.19.10
+DISTNAME=		happy-1.19.12
 CATEGORIES=		devel
 
 HOMEPAGE=		http://www.haskell.org/happy/
@@ -14,8 +12,11 @@ PERMIT_PACKAGE=	Yes
 
 WANTLIB=		c ffi gmp iconv m pthread
 
-MODULES=		lang/ghc
-MODGHC_BUILD=		cabal hackage nort
+MODULES=		devel/cabal
+
+MODCABAL_EXECUTABLES=	happy
+MODCABAL_BUILD=		hackage
+MODCABAL_DATA_DIRS=	data
 
 LIB_DEPENDS=		converters/libiconv \
 			devel/gmp \
@@ -40,7 +41,7 @@ post-install:
 
 do-test:
 	@cd ${WRKBUILD}/tests && exec ${SETENV} ${MAKE_ENV} \
-		${MAKE_PROGRAM} HAPPY=${WRKBUILD}/dist/build/happy/happy \
-		TEST_HAPPY_OPTS="-t ${WRKBUILD} --strict"
+		${MAKE_PROGRAM} -j${MAKE_JOBS} HAPPY=${MODCABAL_BUILT_EXECUTABLE_happy} \
+		TEST_HAPPY_OPTS="-t ${WRKBUILD}/data --strict"
 
 .include <bsd.port.mk>
diff --git devel/happy/distinfo devel/happy/distinfo
index 0e2838f9490..97a135fa555 100644
--- devel/happy/distinfo
+++ devel/happy/distinfo
@@ -1,2 +1,2 @@
-SHA256 (ghc/happy-1.19.10.tar.gz) = IutgbJcQWzluHH3CfhIMoCAlqH8+RNLqUr5qZTpSyu0=
-SIZE (ghc/happy-1.19.10.tar.gz) = 181506
+SHA256 (hackage/happy-1.19.12.tar.gz) = +5oj5BQBcRo7KI+Tzwpm25+X2hzjLsT//qS3ig2utA8=
+SIZE (hackage/happy-1.19.12.tar.gz) = 183254
diff --git devel/happy/pkg/PLIST devel/happy/pkg/PLIST
index c6e8375e5f6..7e49e9c615f 100644
--- devel/happy/pkg/PLIST
+++ devel/happy/pkg/PLIST
@@ -1,5 +1,7 @@
 @comment $OpenBSD: PLIST,v 1.7 2020/05/15 21:50:24 kili Exp $
-@bin bin/happy
+bin/happy
+libexec/cabal/
+@bin libexec/cabal/happy
 share/doc/happy/
 @comment share/doc/${DISTNAME}/
 @comment share/doc/${DISTNAME}/LICENSE
-- 
2.28.0

Reply via email to