commit: 44050f01a5de42d7c329e8e358cd42c4c9e9aeb8
Author: Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 9 17:06:12 2024 +0000
Commit: Florian Schmaus <flow <AT> gentoo <DOT> org>
CommitDate: Sun Jul 14 17:44:38 2024 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=44050f01
rebar.eclass: factor out common functions into rebar-utils.eclass
In preperation for rebar3.eclass, factor out common functions into
rebar-utils.eclass.
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
eclass/{rebar.eclass => rebar-utils.eclass} | 120 +++-------------------------
eclass/rebar.eclass | 112 +-------------------------
2 files changed, 13 insertions(+), 219 deletions(-)
diff --git a/eclass/rebar.eclass b/eclass/rebar-utils.eclass
similarity index 58%
copy from eclass/rebar.eclass
copy to eclass/rebar-utils.eclass
index 97638c761814..5657908eb8e9 100644
--- a/eclass/rebar.eclass
+++ b/eclass/rebar-utils.eclass
@@ -1,43 +1,30 @@
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-# @ECLASS: rebar.eclass
+# @ECLASS: rebar-utils.eclass
# @MAINTAINER:
-# [email protected]
+# Florian Schmaus <[email protected]>
# @AUTHOR:
# Amadeusz Żołnowski <[email protected]>
# @SUPPORTED_EAPIS: 7 8
-# @BLURB: Build Erlang/OTP projects using dev-util/rebar.
+# @BLURB: Auxiliary functions for using dev-util/rebar.
# @DESCRIPTION:
-# An eclass providing functions to build Erlang/OTP projects using
-# dev-util/rebar.
-#
-# 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.
+# This eclass provides a set of axiliary functions commonly needed
+# when building Erlang/OTP packages with rebar.
case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
-if [[ -z ${_REBAR_ECLASS} ]]; then
-_REBAR_ECLASS=1
-
-RDEPEND="dev-lang/erlang:="
-DEPEND="${RDEPEND}"
-BDEPEND="
- dev-util/rebar:0
- >=sys-apps/gawk-4.1
-"
+if [[ -z ${_REBAR_UTILS_ECLASS} ]]; then
+_REBAR_UTILS_ECLASS=1
# @ECLASS_VARIABLE: REBAR_APP_SRC
# @DESCRIPTION:
-# Relative path to .app.src description file.
-REBAR_APP_SRC="${REBAR_APP_SRC-src/${PN}.app.src}"
+# Relative path to .app.src description file. Defaults to
+# 'src/${PN}.app.src'.
+: "${REBAR_APP_SRC:=src/${PN}.app.src}"
# @FUNCTION: get_erl_libs
# @RETURN: the path to Erlang lib directory
@@ -90,21 +77,6 @@ rebar_disable_coverage() {
|| die "failed to disable coverage in ${rebar_config}"
}
-# @FUNCTION: erebar
-# @USAGE: <targets>
-# @DESCRIPTION:
-# Run rebar with verbose flag. Die on failure.
-erebar() {
- debug-print-function ${FUNCNAME} "${@}"
-
- (( $# > 0 )) || die "erebar: at least one target is required"
-
- local -x ERL_LIBS="${EPREFIX}$(get_erl_libs)"
- [[ ${1} == eunit ]] && local -x ERL_LIBS="."
-
- rebar -v skip_deps=true "$@" || die -n "rebar $@ failed"
-}
-
# @FUNCTION: rebar_fix_include_path
# @USAGE: <project_name> [<rebar_config>]
# @DESCRIPTION:
@@ -185,76 +157,4 @@ rebar_set_vsn() {
|| die "failed to set version in src/${PN}.app.src"
}
-# @FUNCTION: rebar_src_prepare
-# @DESCRIPTION:
-# Prevent rebar 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'.
-rebar_src_prepare() {
- debug-print-function ${FUNCNAME} "${@}"
-
- default
- rebar_set_vsn
- if [[ -f rebar.config ]]; then
- rebar_disable_coverage
- rebar_remove_deps
- fi
-}
-
-# @FUNCTION: rebar_src_configure
-# @DESCRIPTION:
-# Configure with ERL_LIBS set.
-rebar_src_configure() {
- debug-print-function ${FUNCNAME} "${@}"
-
- local -x ERL_LIBS="${EPREFIX}$(get_erl_libs)"
- default
-}
-
-# @FUNCTION: rebar_src_compile
-# @DESCRIPTION:
-# Compile project with rebar.
-rebar_src_compile() {
- debug-print-function ${FUNCNAME} "${@}"
-
- erebar compile
-}
-
-# @FUNCTION: rebar_src_test
-# @DESCRIPTION:
-# Run unit tests.
-rebar_src_test() {
- debug-print-function ${FUNCNAME} "${@}"
-
- erebar eunit
-}
-
-# @FUNCTION: rebar_src_install
-# @DESCRIPTION:
-# Install BEAM files, include headers, executables and native libraries.
-# Install standard docs like README or defined in DOCS variable.
-#
-# Function expects that project conforms to Erlang/OTP structure.
-rebar_src_install() {
- debug-print-function ${FUNCNAME} "${@}"
-
- local bin
- local dest="$(get_erl_libs)/${P}"
-
- insinto "${dest}"
- doins -r ebin
- [[ -d include ]] && doins -r include
- [[ -d bin ]] && for bin in bin/*; do dobin "$bin"; done
-
- if [[ -d priv ]]; then
- cp -pR priv "${ED}${dest}/" || die "failed to install priv/"
- fi
-
- einstalldocs
-}
-
fi
-
-EXPORT_FUNCTIONS src_prepare src_compile src_test src_install
diff --git a/eclass/rebar.eclass b/eclass/rebar.eclass
index 97638c761814..1e4e845a9adb 100644
--- a/eclass/rebar.eclass
+++ b/eclass/rebar.eclass
@@ -7,6 +7,7 @@
# @AUTHOR:
# Amadeusz Żołnowski <[email protected]>
# @SUPPORTED_EAPIS: 7 8
+# @PROVIDES: rebar-utils
# @BLURB: Build Erlang/OTP projects using dev-util/rebar.
# @DESCRIPTION:
# An eclass providing functions to build Erlang/OTP projects using
@@ -27,6 +28,8 @@ esac
if [[ -z ${_REBAR_ECLASS} ]]; then
_REBAR_ECLASS=1
+inherit rebar-utils
+
RDEPEND="dev-lang/erlang:="
DEPEND="${RDEPEND}"
BDEPEND="
@@ -34,19 +37,6 @@ BDEPEND="
>=sys-apps/gawk-4.1
"
-# @ECLASS_VARIABLE: REBAR_APP_SRC
-# @DESCRIPTION:
-# Relative path to .app.src description file.
-REBAR_APP_SRC="${REBAR_APP_SRC-src/${PN}.app.src}"
-
-# @FUNCTION: get_erl_libs
-# @RETURN: the path to Erlang lib directory
-# @DESCRIPTION:
-# Get the full path without EPREFIX to Erlang lib directory.
-get_erl_libs() {
- echo "/usr/$(get_libdir)/erlang/lib"
-}
-
# @FUNCTION: _rebar_find_dep
# @INTERNAL
# @USAGE: <project_name>
@@ -74,22 +64,6 @@ _rebar_find_dep() {
echo "${result}"
}
-# @FUNCTION: rebar_disable_coverage
-# @USAGE: [<rebar_config>]
-# @DESCRIPTION:
-# Disable coverage in rebar.config. This is a workaround for failing coverage.
-# Coverage is not relevant in this context, so there's no harm to disable it,
-# although the issue should be fixed.
-rebar_disable_coverage() {
- debug-print-function ${FUNCNAME} "${@}"
-
- local rebar_config="${1:-rebar.config}"
-
- sed -e 's/{cover_enabled, true}/{cover_enabled, false}/' \
- -i "${rebar_config}" \
- || die "failed to disable coverage in ${rebar_config}"
-}
-
# @FUNCTION: erebar
# @USAGE: <targets>
# @DESCRIPTION:
@@ -105,86 +79,6 @@ erebar() {
rebar -v skip_deps=true "$@" || die -n "rebar $@ failed"
}
-# @FUNCTION: rebar_fix_include_path
-# @USAGE: <project_name> [<rebar_config>]
-# @DESCRIPTION:
-# Fix path in rebar.config to 'include' directory of dependent project/package,
-# so it points to installation in system Erlang lib rather than relative 'deps'
-# directory.
-#
-# <rebar_config> is optional. Default is 'rebar.config'.
-#
-# The function dies on failure.
-rebar_fix_include_path() {
- debug-print-function ${FUNCNAME} "${@}"
-
- local pn="${1}"
- local rebar_config="${2:-rebar.config}"
- local erl_libs="${EPREFIX}$(get_erl_libs)"
- local p
-
- p="$(_rebar_find_dep "${pn}")" \
- || die "failed to unambiguously resolve dependency of '${pn}'"
-
- gawk -i inplace \
- -v erl_libs="${erl_libs}" -v pn="${pn}" -v p="${p}" '
-/^{[[:space:]]*erl_opts[[:space:]]*,/, /}[[:space:]]*\.$/ {
- pattern = "\"(./)?deps/" pn "/include\"";
- if (match($0, "{i,[[:space:]]*" pattern "[[:space:]]*}")) {
- sub(pattern, "\"" erl_libs "/" p "/include\"");
- }
- print $0;
- next;
-}
-1
-' "${rebar_config}" || die "failed to fix include paths in ${rebar_config} for
'${pn}'"
-}
-
-# @FUNCTION: rebar_remove_deps
-# @USAGE: [<rebar_config>]
-# @DESCRIPTION:
-# Remove dependencies list from rebar.config and deceive build rules that any
-# dependencies are already fetched and built. Otherwise rebar tries to fetch
-# dependencies and compile them.
-#
-# <rebar_config> is optional. Default is 'rebar.config'.
-#
-# The function dies on failure.
-rebar_remove_deps() {
- debug-print-function ${FUNCNAME} "${@}"
-
- local rebar_config="${1:-rebar.config}"
-
- mkdir -p "${S}/deps" && :>"${S}/deps/.got" && :>"${S}/deps/.built" ||
die
- gawk -i inplace '
-/^{[[:space:]]*deps[[:space:]]*,/, /}[[:space:]]*\.$/ {
- if ($0 ~ /}[[:space:]]*\.$/) {
- print "{deps, []}.";
- }
- next;
-}
-1
-' "${rebar_config}" || die "failed to remove deps from ${rebar_config}"
-}
-
-# @FUNCTION: rebar_set_vsn
-# @USAGE: [<version>]
-# @DESCRIPTION:
-# Set version in project description file if it's not set.
-#
-# <version> is optional. Default is PV stripped from version suffix.
-#
-# The function dies on failure.
-rebar_set_vsn() {
- debug-print-function ${FUNCNAME} "${@}"
-
- local version="${1:-${PV%_*}}"
-
- sed -e "s/vsn, git/vsn, \"${version}\"/" \
- -i "${S}/${REBAR_APP_SRC}" \
- || die "failed to set version in src/${PN}.app.src"
-}
-
# @FUNCTION: rebar_src_prepare
# @DESCRIPTION:
# Prevent rebar from fetching and compiling dependencies. Set version in