Marc Espie <[email protected]> writes:

> According to port-modules, variables starting with MOD* are public, so
> should get documented, SOONER RATHER THAN LATER.

Like semarie@ I followed the recommended convention of putting the
variables into the MOD* namespace. I didn't intend for
MODCABAL_post-extract to be user-facing.

> the cargo stuff seems to come from the loops on MODCARGO_CRATES.
> It can probably be shortened by building a single list of
> ${_cratename}-${_cratever} and using that in the various targets.
>
> Likewise, MODCABAL_post-extract can be halved fairly easily (haven't addressed
> that yet)

See if the attached is close to what you had in mind. I only minimally
tested it and it's been decades since I wrote perl for a living.

>From 3024ba34f0c20946284888b53852b7603ace7a91 Mon Sep 17 00:00:00 2001
From: Greg Steuck <[email protected]>
Date: Thu, 24 Aug 2023 22:34:32 -0700
Subject: [PATCH] Move some logic from cabal.port.mk into a perl script

Mainly to reduce make time for processing large variables.
---
 devel/cabal/cabal.port.mk | 22 +++++-----------
 devel/cabal/prep-cabal.pl | 54 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 15 deletions(-)
 create mode 100755 devel/cabal/prep-cabal.pl

diff --git a/devel/cabal/cabal.port.mk b/devel/cabal/cabal.port.mk
index f90e6ce59cf..ac8a419315f 100644
--- a/devel/cabal/cabal.port.mk
+++ b/devel/cabal/cabal.port.mk
@@ -74,25 +74,17 @@ MODCABAL_post-extract += \
 DISTFILES += {${_package}-${_version}/}${_package}-${_version}.tar.gz:9
 .  if ${_revision} > 0
 DISTFILES += 
${_package}-${_version}_${_revision}{${_package}-${_version}/revision/${_revision}}.cabal:9
-MODCABAL_post-extract += \
-       && cp ${FULLDISTDIR}/${_package}-${_version}_${_revision}.cabal \
-               ${WRKDIR}/${_package}-${_version}/${_package}.cabal
 .  endif
-# References all the locally available dependencies.  Ideally these
-# should be command line options, tracking issue:
-# https://github.com/haskell/cabal/issues/3585
-MODCABAL_post-extract += \
-       && echo "packages: ${WRKDIR}/${_package}-${_version}/${_package}.cabal" 
>> ${WRKSRC}/cabal.project.local
 .endfor  # MODCABAL_MANIFEST
 
 MODCABAL_post-extract += \
-       && echo "package *\n ghc-options: -split-sections\n" >> 
${WRKSRC}/cabal.project.local \
-       && echo "package ${MODCABAL_STEM}\n ld-options: 
-Wl,--gc-sections,--build-id" >> ${WRKSRC}/cabal.project.local
-
-# Automatically copies the cabal.project file if any.
-MODCABAL_post-extract += \
-       && (test -f ${FILESDIR}/cabal.project \
-           && cp -v ${FILESDIR}/cabal.project ${WRKSRC}; true)
+       && env FILESDIR=${FILESDIR} \
+               FULLDISTDIR=${FULLDISTDIR} \
+               WRKDIR=${WRKDIR} \
+               WRKSRC=${WRKSRC} \
+               MODCABAL_MANIFEST="${MODCABAL_MANIFEST}" \
+               MODCABAL_STEM="${MODCABAL_STEM}" \
+               ${PORTSDIR}/devel/cabal/prep-cabal.pl
 
 # Invokes cabal with HOME set up to use .cabal directory created in
 # post-extract.
diff --git a/devel/cabal/prep-cabal.pl b/devel/cabal/prep-cabal.pl
new file mode 100755
index 00000000000..1073c643d13
--- /dev/null
+++ b/devel/cabal/prep-cabal.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+
+# $OpenBSD$
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+# Prepares the contents of a cabal build directory based on the passed
+# environment variables. The reason for moving to a separate script is
+# to reduce make variable processing.
+
+use v5.36;
+use File::Copy;
+
+my @manifest = split /\s+/, $ENV{'MODCABAL_MANIFEST'};
+(scalar @manifest % 3 == 0) or die ("invalid manifest size " . scalar 
@manifest);
+
+open my $cabal_project, '>', "$ENV{WRKSRC}/cabal.project.local" or die "can't 
open";
+
+for (my $i = 0;  $i < scalar @manifest; $i += 3) {
+    my $package = $manifest[$i];
+    my $version = $manifest[$i + 1];
+    my $revision = $manifest[$i + 2];
+    my $dest_cabal = "$ENV{WRKDIR}/$package-$version/$package.cabal";
+    if ($revision > 0) {
+       copy("$ENV{FULLDISTDIR}/${package}-${version}_${revision}.cabal", 
$dest_cabal)
+           or die "Failed to copy to $dest_cabal: $!";
+    }
+
+    # References all the locally available dependencies.  Ideally these
+    # should be command line options, tracking issue:
+    # https://github.com/haskell/cabal/issues/3585
+    print $cabal_project "packages: $dest_cabal\n";
+}
+
+print $cabal_project "package *\n ghc-options: -split-sections\n";
+print $cabal_project "package $ENV{MODCABAL_STEM}\n ld-options: 
-Wl,--gc-sections,--build-id\n";
+close $cabal_project;
+
+# Automatically copies the cabal.project file if any.
+my $project = "$ENV{FILESDIR}/cabal.project";
+if (-e $project) {
+    my $dest = "$ENV{WRKSRC}/cabal.project";
+    copy($project, $dest) or die "Failed to copy to $dest: $!";
+}
-- 
2.41.0

Reply via email to