Gentoo Archives: gentoo-dev

From: Rafael Kitover <rkitover@×××××.com>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] New eclass "dune"
Date: Sun, 10 May 2020 19:48:15
Message-Id: CALHxfhKFOzo9aTrqG15Z6rZ408zVbre8RKKdEWniBkz-PrMxZw@mail.gmail.com
Hi, I am working on a PR to update some dependencies for libguestfs in dev-ml:

https://github.com/gentoo/gentoo/pull/15421

I made a new eclass "dune" for the OCaml Dune build system, it is
based on the "oasis" eclass for the Oasis build system for OCaml.

I was told I need to post it to this list for review, so here it is:

# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: dune.eclass
# @MAINTAINER:
# maintainer-needed@g.o
# @AUTHOR:
# Rafael Kitover <rkitover@×××××.com>
# @SUPPORTED_EAPIS: 5 6 7
# @BLURB: Provides functions for installing dune packages.
# @DESCRIPTION:
# Provides dependencies on dune and ocaml and default src_compile, src_test and
# src_install for dune-based packages.

# @ECLASS-VARIABLE: DUNE_PKG_NAME
# @DESCRIPTION:
# Sets the actual dune package name, if different from gentoo package name.
# Set before inheriting the eclass.

case ${EAPI:-0} in
        5|6|7) ;;
        *) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
esac

RDEPEND=">=dev-lang/ocaml-4:="
DEPEND="${RDEPEND}
        dev-ml/dune"

dune_src_compile() {
        dune build @install || die
}

dune_src_test() {
        dune runtest || die
}

# @FUNCTION: dune-install
# @USAGE: <list of packages>
# @DESCRIPTION:
# Installs the dune packages given as arguments. For each "${pkg}" element in
# that list, "${pkg}.install" must be readable from "${PWD}/_build/default"
dune-install() {
        local pkg
        for pkg ; do
                dune install \
                        --prefix="${ED%/}/usr" \
                        --libdir="${D%/}$(ocamlc -where)" \
                        "${pkg}" || die
        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
}

EXPORT_FUNCTIONS src_compile src_test src_install