From: Greg Steuck Subject: Support data-dir from cabal package dependencies To: ports@openbsd.org, kili@openbsd.org Date: Sun, 21 Dec 2025 20:46:14 -0800 Hi Matthias, I previously didn't want to update happy due to the infra missing a piece, so I implemented that. What do you think about the following? The main point of interest is MODCABAL_DATA_DIR. I previously didn't want to update happy due to the infra missing a piece, so I implemented that. What do you think about the following? The main point of interest is MODCABAL_DATA_DIR. The update to happy-2.1.7 includes the Hackage package split into a library and binary packages. The data-dir is now part of the library-dependent package. We previously didn't have support for installing such packages with data files provided by dependency libraries. This patch adds such support by iterating through the dependencies and collecting their data files. This also means preparing more complicated wrapper scripts with slightly longer data file installation paths. The change is visible in the PLIST of alex, which otherwise could remain unchanged. One side effect of this patch is that MODCABAL_DATA_DIR no longer needs to have any particular value; it just needs to be enabled for this automated machinery to find the relevant pieces. I could change the variable's meaning to be a simple flag enabling the feature. Since only two packages use the feature so far, it would be a simple documentation update with no ports churn. The happy update itself loses some features - documentation is no longer included in Hackage tarballs. --- devel/alex/pkg/PLIST | 5 +-- devel/cabal/cabal.port.mk | 16 +++++---- devel/cabal/populate-datadir.pl | 61 +++++++++++++++++++++++++++++++++ devel/happy/Makefile | 21 +++--------- devel/happy/distinfo | 6 ++-- devel/happy/pkg/PLIST | 54 +++-------------------------- 6 files changed, 87 insertions(+), 76 deletions(-) create mode 100755 devel/cabal/populate-datadir.pl diff --git a/devel/alex/pkg/PLIST b/devel/alex/pkg/PLIST index 194d5300d94..ae4bb7cf510 100644 --- a/devel/alex/pkg/PLIST +++ b/devel/alex/pkg/PLIST @@ -2,5 +2,6 @@ bin/${MODCABAL_STEM} libexec/cabal/ @bin libexec/cabal/${MODCABAL_STEM} share/${PKGNAME}/ -share/${PKGNAME}/AlexTemplate.hs -share/${PKGNAME}/AlexWrappers.hs +share/${PKGNAME}/${MODCABAL_STEM}_datadir/ +share/${PKGNAME}/${MODCABAL_STEM}_datadir/AlexTemplate.hs +share/${PKGNAME}/${MODCABAL_STEM}_datadir/AlexWrappers.hs diff --git a/devel/cabal/cabal.port.mk b/devel/cabal/cabal.port.mk index 0df4dc7560a..e1b116efe5c 100644 --- a/devel/cabal/cabal.port.mk +++ b/devel/cabal/cabal.port.mk @@ -117,11 +117,10 @@ MODCABAL_INSTALL_TARGET = true .if defined(MODCABAL_DATA_DIR) _MODCABAL_LIBEXEC = libexec/cabal MODCABAL_INSTALL_TARGET += \ - && mkdir -p ${PREFIX}/${_MODCABAL_LIBEXEC} - -MODCABAL_INSTALL_TARGET += \ - && ${INSTALL_DATA_DIR} ${WRKSRC}/${MODCABAL_DATA_DIR} ${PREFIX}/share/${DISTNAME} \ - && cd ${WRKSRC}/${MODCABAL_DATA_DIR} && umask 022 && pax -rw . ${PREFIX}/share/${DISTNAME} + && mkdir -p ${PREFIX}/${_MODCABAL_LIBEXEC} \ + && ${INSTALL_DATA_DIR} ${PREFIX}/share/${DISTNAME} \ + && ${SETENV} ${MAKE_ENV} WRKSRC=${WRKSRC} DISTNAME=${DISTNAME} \ + ${PORTSDIR}/devel/cabal/populate-datadir.pl .endif # Appends installation fragments for each executable. @@ -138,7 +137,7 @@ MODCABAL_INSTALL_TARGET += \ ${MODCABAL_BUILT_EXECUTABLE_${_exe}} \ ${PREFIX}/${_MODCABAL_LIBEXEC}/${_exe} \ && echo '\#!/bin/sh' > ${PREFIX}/bin/${_exe} \ - && echo 'export ${_exe}_datadir=${LOCALBASE}/share/${DISTNAME}' >> ${PREFIX}/bin/${_exe} \ + && cat ${PREFIX}/share/${DISTNAME}/env >> ${PREFIX}/bin/${_exe} \ && echo 'exec ${LOCALBASE}/${_MODCABAL_LIBEXEC}/${_exe} "$$@"' >> ${PREFIX}/bin/${_exe} \ && chmod +x ${STAGEDIR}${PREFIX}/bin/${_exe} . else @@ -148,6 +147,11 @@ MODCABAL_INSTALL_TARGET += \ . endif .endfor +.if defined(MODCABAL_DATA_DIR) +MODCABAL_INSTALL_TARGET += \ + && rm -f ${PREFIX}/share/${DISTNAME}/env +.endif + .if !target(do-build) do-build: @${MODCABAL_BUILD_TARGET} diff --git a/devel/cabal/populate-datadir.pl b/devel/cabal/populate-datadir.pl new file mode 100755 index 00000000000..73c59beb724 --- /dev/null +++ b/devel/cabal/populate-datadir.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +# Collects data-dir for a Haskell package in ports tree. Writes an +# evironment prep fragment for inclusion into wrapper scripts. +# Tightly integrated with cabal.port.mk. + +use strict; +use warnings; +use File::Glob ':bsd_glob'; +use File::Path qw(make_path); + +my $wrksrc = $ENV{WRKSRC} // die "WRKSRC not set\n"; +my $prefix = $ENV{PREFIX} // die "PREFIX not set\n"; +my $distname = $ENV{DISTNAME} // die "DISTNAME not set\n"; + +my ($pkgdb) = bsd_glob("$wrksrc/dist-newstyle/packagedb/ghc-*"); +die "No package database found\n" unless defined $pkgdb; + +my $datapath = "$prefix/share/$distname"; + +umask 022; + +sub try_record_pkg { + my ($datadir, $pkg) = @_; + + return if !defined $datadir || $datadir eq '' || $datadir eq '.' + || $datadir =~ m{/\.\z}; + + my $pkgname = $pkg =~ s/-[0-9][0-9.]*\z//r; + my $envvar = $pkgname =~ tr/-/_/r . '_datadir'; + my $destdir = "$datapath/$envvar"; + + make_path($destdir); + system("cd \Q$datadir\E && pax -rw . \Q$destdir\E") == 0 + or die "pax failed: $?\n"; + + open my $fh, '>>', "$datapath/env" or die "Cannot open env: $!\n"; + print $fh "export $envvar=/usr/local/share/$distname/$envvar\n"; + close $fh; +} + +my @pkgs = split ' ', `ghc-pkg --package-db='$pkgdb' list --simple-output`; + +for my $pkg (@pkgs) { + next if $pkg =~ /\Az-/; + + chomp(my $datadir = `ghc-pkg --package-db='$pkgdb' field '$pkg' data-dir --simple-output`); + try_record_pkg($datadir, $pkg); +} + +my ($cabal) = bsd_glob("$wrksrc/*.cabal"); +die "No .cabal file found in $wrksrc\n" unless defined $cabal; + +open my $fh, '<', $cabal or die "Cannot open $cabal: $!\n"; +while (<$fh>) { + if (/^data-dir:\s*(\S+)/) { + try_record_pkg("$wrksrc/$1", $distname); + last; + } +} +close $fh; diff --git a/devel/happy/Makefile b/devel/happy/Makefile index 6d3fb7fda12..2e708dd661b 100644 --- a/devel/happy/Makefile +++ b/devel/happy/Makefile @@ -1,8 +1,8 @@ COMMENT= parser generator for Haskell MODCABAL_STEM= happy -MODCABAL_VERSION= 1.20.1.1 -MODCABAL_DATA_DIR= data +MODCABAL_VERSION= 2.1.7 +MODCABAL_DATA_DIR= data # unused CATEGORIES= devel @@ -19,26 +19,15 @@ LIB_DEPENDS= converters/libiconv \ devel/gmp \ devel/libffi -BUILD_DEPENDS+= textproc/docbook-xsl - # Required for building the documentation and for the regression tests: USE_GMAKE= Yes -CONFIGURE_STYLE= autoconf no-autoheader -AUTOCONF_VERSION= 2.69 -AUTOCONF_DIR= ${WRKSRC}/doc -WRKCONF= ${AUTOCONF_DIR} - -post-build: - @cd ${WRKBUILD}/doc && exec ${SETENV} ${MAKE_ENV} \ - ${MAKE_PROGRAM} html -post-install: - ${INSTALL_DATA_DIR} ${PREFIX}/share/doc - cd ${WRKBUILD}/doc && umask 022 && pax -rw happy ${PREFIX}/share/doc +MODCABAL_MANIFEST = \ + happy-lib 2.1.7 0 \ do-test: @cd ${WRKBUILD}/tests && exec ${SETENV} ${MAKE_ENV} \ ${MAKE_PROGRAM} -j${MAKE_JOBS} HAPPY=${MODCABAL_BUILT_EXECUTABLE_happy} \ - TEST_HAPPY_OPTS="-t ${WRKBUILD}/data --strict" + TEST_HAPPY_OPTS="--ghc -t ${WRKDIR}/happy-lib-${MODCABAL_VERSION}/data --strict" all .include diff --git a/devel/happy/distinfo b/devel/happy/distinfo index d519748875c..2bd2d859e2c 100644 --- a/devel/happy/distinfo +++ b/devel/happy/distinfo @@ -1,2 +1,4 @@ -SHA256 (hackage/happy-1.20.1.1.tar.gz) = i059xabF/WZvj3FjIykxqyh0bQ0X2o+hy9aL6eh4iBs= -SIZE (hackage/happy-1.20.1.1.tar.gz) = 183409 +SHA256 (hackage/happy-2.1.7.tar.gz) = njkPCrCC0R1GWY9iFbL26CUwWXIYYPgQgkCQkVMtfio= +SHA256 (hackage/happy-lib-2.1.7.tar.gz) = 9iWyxKPytfr6PFYPqHV1AsyN6D2ahMJpL8lDOAkA8mk= +SIZE (hackage/happy-2.1.7.tar.gz) = 62023 +SIZE (hackage/happy-lib-2.1.7.tar.gz) = 94227 diff --git a/devel/happy/pkg/PLIST b/devel/happy/pkg/PLIST index 14d5b50e1ff..07841141789 100644 --- a/devel/happy/pkg/PLIST +++ b/devel/happy/pkg/PLIST @@ -1,56 +1,10 @@ bin/${MODCABAL_STEM} libexec/cabal/ @bin libexec/cabal/${MODCABAL_STEM} -share/doc/${MODCABAL_STEM}/ @comment share/doc/${PKGNAME}/ @comment share/doc/${PKGNAME}/LICENSE -share/doc/${MODCABAL_STEM}/fptools.css -share/doc/${MODCABAL_STEM}/${MODCABAL_STEM}-introduction.html -share/doc/${MODCABAL_STEM}/index.html -share/doc/${MODCABAL_STEM}/ix01.html -share/doc/${MODCABAL_STEM}/sec-AtrributeGrammarsInHappy.html -share/doc/${MODCABAL_STEM}/sec-AttrGrammarLimits.html -share/doc/${MODCABAL_STEM}/sec-AttributeGrammar.html -share/doc/${MODCABAL_STEM}/sec-AttributeGrammarExample.html -share/doc/${MODCABAL_STEM}/sec-Precedences.html -share/doc/${MODCABAL_STEM}/sec-compilation-time.html -share/doc/${MODCABAL_STEM}/sec-conflict-tips.html -share/doc/${MODCABAL_STEM}/sec-directives.html -share/doc/${MODCABAL_STEM}/sec-error.html -share/doc/${MODCABAL_STEM}/sec-finding-errors.html -share/doc/${MODCABAL_STEM}/sec-glr-misc.html -share/doc/${MODCABAL_STEM}/sec-glr-semantics.html -share/doc/${MODCABAL_STEM}/sec-glr-using.html -share/doc/${MODCABAL_STEM}/sec-glr.html -share/doc/${MODCABAL_STEM}/sec-grammar-files.html -share/doc/${MODCABAL_STEM}/sec-grammar.html -share/doc/${MODCABAL_STEM}/sec-${MODCABAL_STEM}-ghci.html -share/doc/${MODCABAL_STEM}/sec-info-files-conflicts.html -share/doc/${MODCABAL_STEM}/sec-info-files.html -share/doc/${MODCABAL_STEM}/sec-invoking.html -share/doc/${MODCABAL_STEM}/sec-license.html -share/doc/${MODCABAL_STEM}/sec-module-header.html -share/doc/${MODCABAL_STEM}/sec-module-trailer.html -share/doc/${MODCABAL_STEM}/sec-monad-alex.html -share/doc/${MODCABAL_STEM}/sec-monads.html -share/doc/${MODCABAL_STEM}/sec-multiple-parsers.html -share/doc/${MODCABAL_STEM}/sec-obtaining.html -share/doc/${MODCABAL_STEM}/sec-reporting-bugs.html -share/doc/${MODCABAL_STEM}/sec-sequences.html -share/doc/${MODCABAL_STEM}/sec-tips.html -share/doc/${MODCABAL_STEM}/sec-type-signatures.html -share/doc/${MODCABAL_STEM}/sec-using.html share/${PKGNAME}/ -share/${PKGNAME}/GLR_Base -share/${PKGNAME}/GLR_Lib -share/${PKGNAME}/GLR_Lib-ghc -share/${PKGNAME}/GLR_Lib-ghc-debug -share/${PKGNAME}/HappyTemplate -share/${PKGNAME}/HappyTemplate-arrays -share/${PKGNAME}/HappyTemplate-arrays-coerce -share/${PKGNAME}/HappyTemplate-arrays-coerce-debug -share/${PKGNAME}/HappyTemplate-arrays-debug -share/${PKGNAME}/HappyTemplate-arrays-ghc -share/${PKGNAME}/HappyTemplate-arrays-ghc-debug -share/${PKGNAME}/HappyTemplate-coerce -share/${PKGNAME}/HappyTemplate-ghc +share/${PKGNAME}/${MODCABAL_STEM}_lib_datadir/ +share/${PKGNAME}/${MODCABAL_STEM}_lib_datadir/GLR_Base.hs +share/${PKGNAME}/${MODCABAL_STEM}_lib_datadir/GLR_Lib.hs +share/${PKGNAME}/${MODCABAL_STEM}_lib_datadir/HappyTemplate.hs -- 2.51.2