public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH v3] eclass/dune.eclass: fix dune-install function
@ 2021-12-09 22:36 Maciej Barć
  2021-12-10  6:54 ` Ulrich Mueller
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej Barć @ 2021-12-09 22:36 UTC (permalink / raw)
  To: gentoo-dev; +Cc: ml, Maciej Barć

Support EAPI 8 and drop support for EAPI 5.
Set DUNE_PKG_NAME to PN by default.
Move "Move docs to the appropriate place" block to dune-install
to make dune-install now handle a list of subpackages correctly.

Signed-off-by: Maciej Barć <xgqt@gentoo.org>
---
 eclass/dune.eclass | 50 ++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/eclass/dune.eclass b/eclass/dune.eclass
index 02a8a870e..8cf8ededa 100644
--- a/eclass/dune.eclass
+++ b/eclass/dune.eclass
@@ -8,7 +8,7 @@
 # ML <ml@gentoo.org>
 # @AUTHOR:
 # Rafael Kitover <rkitover@gmail.com>
-# @SUPPORTED_EAPIS: 5 6 7
+# @SUPPORTED_EAPIS: 6 7 8
 # @BLURB: Provides functions for installing Dune packages.
 # @DESCRIPTION:
 # Provides dependencies on dDne and OCaml and default src_compile, src_test and
@@ -19,9 +19,10 @@
 # @DESCRIPTION:
 # Sets the actual Dune package name, if different from Gentoo package name.
 # Set before inheriting the eclass.
+: ${DUNE_PKG_NAME:-${PN}}
 
 case ${EAPI:-0} in
-	5|6|7) ;;
+	6|7|8) ;;
 	*) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
 esac
 
@@ -32,7 +33,7 @@ EXPORT_FUNCTIONS src_compile src_test src_install
 
 RDEPEND=">=dev-lang/ocaml-4:=[ocamlopt?] dev-ml/dune:="
 case ${EAPI:-0} in
-	5|6)
+	6)
 		DEPEND="${RDEPEND} dev-ml/dune"
 		;;
 	*)
@@ -54,26 +55,37 @@ dune_src_test() {
 # @DESCRIPTION:
 # Installs the dune packages given as arguments. For each "${pkg}" element in
 # that list, "${pkg}.install" must be readable from "${PWD}/_build/default"
+#
+# Example use:
+# @CODE
+# dune-install menhir menhirLib menhirSdk
+# @CODE
 dune-install() {
+	local pkgs
+	if [[ -n "${@}" ]] ; then
+		pkgs="${@}"
+	else
+		pkgs=${DUNE_PKG_NAME}
+	fi
+
+	local myduneopts=(
+		--prefix="${ED%/}/usr"
+		--libdir="${D%/}$(ocamlc -where)"
+		--mandir="${ED%/}/usr/share/man"
+	)
 	local pkg
-	for pkg ; do
-		dune install \
-			--prefix="${ED%/}/usr" \
-			--libdir="${D%/}$(ocamlc -where)" \
-			--mandir="${ED%/}/usr/share/man" \
-			"${pkg}" || die
+	for pkg in ${pkgs[@]} ; do
+		dune install ${myduneopts[@]} ${pkg} || die
+
+		# Move docs to the appropriate place.
+		if [ -d "${ED%/}/usr/doc/${pkg}" ] ; then
+			mkdir -p "${ED%/}/usr/share/doc/${PF}/" || die
+			mv "${ED%/}/usr/doc/${pkg}" "${ED%/}/usr/share/doc/${PF}/" || die
+			rm -rf "${ED%/}/usr/doc" || die
+		fi
 	done
 }
 
 dune_src_install() {
-	local pkg="${1:-${DUNE_PKG_NAME:-${PN}}}"
-
-	dune-install "${pkg}"
-
-	# Move docs to the appropriate place.
-	if [ -d "${ED%/}/usr/doc/${pkg}" ] ; then
-		mkdir -p "${ED%/}/usr/share/doc/${PF}/" || die
-		mv "${ED%/}/usr/doc/${pkg}/"* "${ED%/}/usr/share/doc/${PF}/" || die
-		rm -rf "${ED%/}/usr/doc" || die
-	fi
+	dune-install ${1:-${DUNE_PKG_NAME}}
 }
-- 
2.32.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [gentoo-dev] [PATCH v3] eclass/dune.eclass: fix dune-install function
  2021-12-09 22:36 [gentoo-dev] [PATCH v3] eclass/dune.eclass: fix dune-install function Maciej Barć
@ 2021-12-10  6:54 ` Ulrich Mueller
  2021-12-10  7:53   ` Ulrich Mueller
  0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Mueller @ 2021-12-10  6:54 UTC (permalink / raw)
  To: Maciej Barć; +Cc: gentoo-dev, ml

[-- Attachment #1: Type: text/plain, Size: 1196 bytes --]

>>>>> On Thu, 09 Dec 2021, Maciej Barć wrote:

>  dune-install() {
> +	local pkgs
> +	if [[ -n "${@}" ]] ; then
> +		pkgs="${@}"

Here pkgs is a scalar ...

> +	else
> +		pkgs=${DUNE_PKG_NAME}
> +	fi
> +
> +	local myduneopts=(
> +		--prefix="${ED%/}/usr"
> +		--libdir="${D%/}$(ocamlc -where)"
> +		--mandir="${ED%/}/usr/share/man"
> +	)
>  	local pkg
> -	for pkg ; do
> -		dune install \
> -			--prefix="${ED%/}/usr" \
> -			--libdir="${D%/}$(ocamlc -where)" \
> -			--mandir="${ED%/}/usr/share/man" \
> -			"${pkg}" || die
> +	for pkg in ${pkgs[@]} ; do

... and here it's an array?

> +		dune install ${myduneopts[@]} ${pkg} || die
> +
> +		# Move docs to the appropriate place.
> +		if [ -d "${ED%/}/usr/doc/${pkg}" ] ; then
> +			mkdir -p "${ED%/}/usr/share/doc/${PF}/" || die
> +			mv "${ED%/}/usr/doc/${pkg}" "${ED%/}/usr/share/doc/${PF}/" || die
> +			rm -rf "${ED%/}/usr/doc" || die
> +		fi
>  	done
>  }

I'd write something like this:

	local -a pkgs=("$@")
	[[ ${#pkgs[@]} -eq 0 ]] && pkgs=(${DUNE_PKG_NAME})

And the loop like this (note the double quotes to be whitespace-safe):

	for pkg in "${pkgs[@]}"; do
		...
	done

Ulrich

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-dev] [PATCH v3] eclass/dune.eclass: fix dune-install function
  2021-12-10  6:54 ` Ulrich Mueller
@ 2021-12-10  7:53   ` Ulrich Mueller
  0 siblings, 0 replies; 3+ messages in thread
From: Ulrich Mueller @ 2021-12-10  7:53 UTC (permalink / raw)
  To: Maciej Barć; +Cc: gentoo-dev, ml

[-- Attachment #1: Type: text/plain, Size: 422 bytes --]

>>>>> On Fri, 10 Dec 2021, Ulrich Mueller wrote:

> I'd write something like this:

> 	local -a pkgs=("$@")
> 	[[ ${#pkgs[@]} -eq 0 ]] && pkgs=(${DUNE_PKG_NAME})

Looks like I'm not immune against missing quotes either. :/
The line should read:

	[[ ${#pkgs[@]} -eq 0 ]] && pkgs=("${DUNE_PKG_NAME}")

> And the loop like this (note the double quotes to be whitespace-safe):

> 	for pkg in "${pkgs[@]}"; do
> 		...
> 	done

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-10  7:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 22:36 [gentoo-dev] [PATCH v3] eclass/dune.eclass: fix dune-install function Maciej Barć
2021-12-10  6:54 ` Ulrich Mueller
2021-12-10  7:53   ` Ulrich Mueller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox