From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 8AB781581C1 for ; Tue, 16 Jul 2024 09:37:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 06AAA2BC0F3; Tue, 16 Jul 2024 09:36:01 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id AA1222BC0F0 for ; Tue, 16 Jul 2024 09:36:00 +0000 (UTC) From: Florian Schmaus To: gentoo-dev@lists.gentoo.org Cc: Anna Vyalkova , Matthew Smith , Florian Schmaus Subject: [gentoo-dev] [PATCH 2/2] rebar3.eclass: add new eclass Date: Tue, 16 Jul 2024 11:35:31 +0200 Message-ID: <20240716093532.349861-3-flow@gentoo.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240716093532.349861-1-flow@gentoo.org> References: <20240716093532.349861-1-flow@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 90ce39f7-0410-4a96-a867-b678f4c37c7e X-Archives-Hash: ee5ca2afee9aaf983b1b6525bc69d259 Add a new eclass for dev-util/rebar:3, based on the work of Anna Vyalkova in ::guru (thanks!). The Erlang/OTP ecosystem is moving to Rebar3. Upstreams start to drop support for Rebar2, or at least consider it. Signed-off-by: Florian Schmaus --- eclass/rebar3.eclass | 194 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 eclass/rebar3.eclass diff --git a/eclass/rebar3.eclass b/eclass/rebar3.eclass new file mode 100644 index 000000000000..f6383b9c8cdd --- /dev/null +++ b/eclass/rebar3.eclass @@ -0,0 +1,194 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: rebar3.eclass +# @MAINTAINER: +# Florian Schmaus +# @AUTHOR: +# Amadeusz Żołnowski +# Anna (cybertailor) Vyalkova +# @SUPPORTED_EAPIS: 8 +# @PROVIDES: rebar-utils +# @BLURB: Build Erlang/OTP projects using dev-util/rebar:3. +# @DESCRIPTION: +# An eclass providing functions to build Erlang/OTP projects using +# dev-util/rebar:3. +# +# rebar is a tool which tries to resolve dependencies itself which is by +# cloning remote git repositories. Dependent projects are usually expected to +# be in sub-directory 'deps' rather than looking at system Erlang lib +# directory. Projects relying on rebar usually don't have 'install' make +# targets. The eclass workarounds some of these problems. It handles +# installation in a generic way for Erlang/OTP structured projects. + +case ${EAPI} in + 8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +if [[ -z ${_REBAR3_ECLASS} ]]; then +_REBAR3_ECLASS=1 + +inherit edo rebar-utils + +RDEPEND="dev-lang/erlang:=" +DEPEND="${RDEPEND}" +BDEPEND=" + dev-util/rebar:3 + >=sys-apps/gawk-4.1 +" + +# @ECLASS_VARIABLE: REBAR_PROFILE +# @DESCRIPTION: +# Rebar profile to use. Defaults to +# 'default'. +: "${REBAR_PROFILE:=default}" + +# @FUNCTION: _rebar_find_dep +# @INTERNAL +# @USAGE: +# @RETURN: 0 success, 1 dependency not found, 2 multiple versions found +# @DESCRIPTION: +# Find a Erlang package/project by name in Erlang lib directory. Project +# directory is usually suffixed with version. It is matched to '' +# or '-*'. +_rebar_find_dep() { + local pn="${1}" + local p + local result + + pushd "${EPREFIX}$(get_erl_libs)" >/dev/null || return 1 + for p in ${pn} ${pn}-*; do + if [[ -d ${p} ]]; then + # Ensure there's at most one matching. + [[ ${result} ]] && return 2 + result="${p}" + fi + done + popd >/dev/null || die + + [[ ${result} ]] || return 1 + echo "${result}" +} + +# @FUNCTION: erebar3 +# @USAGE: +# @DESCRIPTION: +# Run rebar with verbose flag. Die on failure. +erebar3() { + debug-print-function ${FUNCNAME} "${@}" + + (( $# > 0 )) || die "${FUNCNAME}: at least one target is required" + + case ${1} in + eunit|ct) + local -x ERL_LIBS="." ;; + *) + local -x ERL_LIBS="${EPREFIX}$(get_erl_libs)" ;; + esac + + local -x HEX_OFFLINE=true + edo rebar3 "$@" +} + +# @FUNCTION: rebar3_src_prepare +# @DESCRIPTION: +# Prevent rebar3 from fetching and compiling dependencies. Set version in +# project description file if it's not set. +# +# Existence of rebar.config is optional, but file description file must exist +# at 'src/${PN}.app.src'. +rebar3_src_prepare() { + debug-print-function ${FUNCNAME} "${@}" + + default + rebar_set_vsn + + if [[ -f rebar.lock ]]; then + rm rebar.lock || die + fi + + if [[ -f rebar.config ]]; then + rebar_disable_coverage + rebar_remove_deps + fi +} + +# @FUNCTION: rebar3_src_configure +# @DESCRIPTION: +# Configure with ERL_LIBS set. +rebar3_src_configure() { + debug-print-function ${FUNCNAME} "${@}" + + local -x ERL_LIBS="${EPREFIX}$(get_erl_libs)" + default +} + +# @FUNCTION: rebar3_src_compile +# @DESCRIPTION: +# Compile project with rebar3. +rebar3_src_compile() { + debug-print-function ${FUNCNAME} "${@}" + + erebar3 as "${REBAR_PROFILE}" release --all +} + +# @FUNCTION: rebar3_src_test +# @DESCRIPTION: +# Run unit tests. +rebar3_src_test() { + debug-print-function ${FUNCNAME} "${@}" + + erebar3 eunit -v +} + +# @FUNCTION: rebar3_install_lib +# @USAGE: +# @DESCRIPTION: +# Install BEAM files, include headers and native libraries. +# +# Function expects that project conforms to Erlang/OTP structure. +rebar3_install_lib() { + debug-print-function ${FUNCNAME} "${@}" + + local dest="$(get_erl_libs)/${P}" + insinto "${dest}" + + pushd "${1?}" >/dev/null || die + for dir in ebin include priv; do + if [[ -d ${dir} && ! -L ${dir} ]]; then + doins -r "${dir}" + fi + done + popd >/dev/null || die +} + +# @FUNCTION: rebar3_src_install +# @DESCRIPTION: +# Install built release or library. +# +# Function expects that project conforms to Erlang/OTP structure. +rebar3_src_install() { + debug-print-function ${FUNCNAME} "${@}" + + pushd "_build/${REBAR_PROFILE}" >/dev/null || die + if [[ -d rel/${PN} ]]; then + if ! declare -f rebar3_install_release >/dev/null; then + die "${FUNCNAME}: a custom function named 'rebar3_install_release' is required to install a release" + fi + pushd rel/${PN} >/dev/null || die + rebar3_install_release || die + popd >/dev/null || die + elif [[ -d lib/${PN} ]]; then + rebar3_install_lib lib/${PN} + else + die "No releases or libraries to install" + fi + popd >/dev/null || die + + einstalldocs +} + +fi + +EXPORT_FUNCTIONS src_prepare src_compile src_test src_install -- 2.44.2