public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: aidecoe@gentoo.org
Cc: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] [PATCH] rebar.eclass: Build Erlang/OTP projects using dev-util/rebar
Date: Thu, 19 May 2016 06:39:09 +0200	[thread overview]
Message-ID: <20160519063909.651a07e8.mgorny@gentoo.org> (raw)
In-Reply-To: <1463610918-4062-1-git-send-email-aidecoe@gentoo.org>

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

On Wed, 18 May 2016 23:35:18 +0100
aidecoe@gentoo.org wrote:

> From: Amadeusz Żołnowski <aidecoe@gentoo.org>
> 
> It is an eclass providing functions to build Erlang/OTP projects using
> dev-util/rebar. All packages in upcoming category dev-erlang are going
> to use this eclass.
> ---
>  eclass/rebar.eclass | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 220 insertions(+)
>  create mode 100644 eclass/rebar.eclass
> 
> diff --git a/eclass/rebar.eclass b/eclass/rebar.eclass
> new file mode 100644
> index 0000000..e1ac52f
> --- /dev/null
> +++ b/eclass/rebar.eclass
> @@ -0,0 +1,220 @@
> +# Copyright 1999-2016 Gentoo Foundation
> +# Distributed under the terms of the GNU General Public License v2
> +# $Id$
> +
> +# @ECLASS: rebar.eclass
> +# @MAINTAINER:
> +# Amadeusz Żołnowski <aidecoe@gentoo.org>
> +# @AUTHOR:
> +# Amadeusz Żołnowski <aidecoe@gentoo.org>
> +# @BLURB: Build Erlang/OTP projects 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. Dependant 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:-0}" in
> +	0|1|2|3|4)
> +		die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
> +		;;
> +	5|6)
> +		;;
> +	*)
> +		die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
> +		;;
> +esac
> +
> +[[ ${EAPI} = 5 ]] && inherit eutils
> +
> +EXPORT_FUNCTIONS src_prepare src_compile src_install
> +
> +RDEPEND="dev-lang/erlang"
> +DEPEND="${RDEPEND}
> +	dev-util/rebar"
> +
> +# @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"

Missing multilib inherit for EAPI 5.

> +}
> +
> +# @VARIABLE: ERL_LIBS
> +# @DESCRIPTION:
> +# Full path with EPREFIX to Erlang lib directory. Some rebar scripts expect it.
> +export ERL_LIBS="${EPREFIX}$(get_erl_libs)"

I think calling get_libdir in global scope is forbidden. You should
really export this somewhere in phase function.

> +
> +# @FUNCTION: _find_dep_version

Namespace it, please. Just in case.

> +# @INTERNAL
> +# @USAGE: <project_name>
> +# @RETURN: full path with EPREFIX to a Erlang package/project
> +# @DESCRIPTION:
> +# Find a Erlang package/project by name in Erlang lib directory. Project
> +# directory is usually suffixed with version. First match to <project_name> or
> +# <project_name>-* is returned.
> +_find_dep_version() {
> +	local pn="$1"
> +	local p
> +
> +	pushd "${EPREFIX}$(get_erl_libs)" >/dev/null

|| die

> +	for p in ${pn} ${pn}-*; do
> +		if [[ -d ${p} ]]; then
> +			echo "${p#${pn}-}"
> +			return 0
> +		fi
> +	done
> +	popd >/dev/null

|| die

> +
> +	return 1
> +}
> +
> +# @FUNCTION: eawk
> +# @USAGE: <file> <args>
> +# @DESCRIPTION:
> +# Edit file <file> in place with awk. Pass all arguments following <file> to
> +# awk.
> +eawk() {
> +	local f="$1"; shift
> +	local tmpf="$(emktemp)"

Missing eutils inherit for EAPI 6.

> +
> +	cat "${f}" >"${tmpf}" || return 1
> +	awk "$@" "${tmpf}" >"${f}"
> +}
> +
> +# @FUNCTION: erebar
> +# @USAGE: <target>
> +# @DESCRIPTION:
> +# Run rebar with verbose flag. Die on failure.
> +erebar() {
> +	debug-print-function ${FUNCNAME} "${@}"
> +
> +	rebar -v skip_deps=true "$1" || die "rebar $1 failed"
> +}

Any reason it doesn't pass all the parameters? This inconsistency with
emake etc. could be mildly confusing, esp. that you don't check for
wrong argc.

> +
> +# @FUNCTION: rebar_fix_include_path
> +# @USAGE: <project_name> [<rebar_config>]
> +# @DESCRIPTION:
> +# Fix path in rebar.config to 'include' directory of dependant project/package,
> +# so it points to installation in system Erlang lib rather than relative 'deps'
> +# directory.
> +#
> +# <rebar_config> is optional. Default is 'rebar.config'.

Is it likely that you would be passing different values to it? Maybe it
would be reasonable to make this an eclass variable.

> +#
> +# 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 pv="$(_find_dep_version "${pn}")"
> +
> +	eawk "${rebar_config}" \
> +		-v erl_libs="${erl_libs}" -v pn="${pn}" -v pv="${pv}" \
> +		'/^{[[:space:]]*erl_opts[[:space:]]*,/, /}[[:space:]]*\.$/ {
> +	pattern = "\"(./)?deps/" pn "/include\"";
> +	if (match($0, "{i,[[:space:]]*" pattern "[[:space:]]*}")) {
> +		sub(pattern, "\"" erl_libs "/" pn "-" pv "/include\"");
> +	}
> +	print $0;
> +	next;
> +}
> +1
> +' || die "failed to fix include paths in ${rebar_config}"

I suggest you indent this a bit more since it feels like you start at
two tabs and finish at zero.

> +}
> +
> +# @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
> +	eawk "${rebar_config}" \
> +		'/^{[[:space:]]*deps[[:space:]]*,/, /}[[:space:]]*\.$/ {
> +	if ($0 ~ /}[[:space:]]*\.$/) {
> +		print "{deps, []}.";
> +	}
> +	next;
> +}
> +1
> +' || 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}/src/${PN}.app.src" \
> +		|| die "failed to set version in src/${PN}.app.src"
> +}
> +
> +# @FUNCTION: rebar_src_prepare
> +# @DESCRIPTION:
> +# Prevent rebar from fetching in 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'.

Wouldn't it be reasonable to make this configurable? Of course, it
might be better to leave it for a possible future extension when
it becomes necessary.

> +rebar_src_prepare() {
> +	debug-print-function ${FUNCNAME} "${@}"
> +
> +	rebar_set_vsn
> +	[[ -f rebar.config ]] && rebar_remove_deps
> +}

You're missing obligatory default call for EAPI 6. You should really
test stuff before submitting it.

> +
> +# @FUNCTION: rebar_src_compile
> +# @DESCRIPTION:
> +# Compile project with rebar.
> +rebar_src_compile() {
> +	debug-print-function ${FUNCNAME} "${@}"
> +
> +	erebar compile
> +}
> +
> +# @FUNCTION: rebar_src_install
> +# @DESCRIPTION:
> +# Install BEAM files, include headers, executables and native libraries.
> +# Install standard docs like README or defined in DOCS variable. Optionally

Optionally what? It looks like an unfinished sentence.

> +#
> +# 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

Please don't do inlines like this.

> +	[[ -d priv ]] && cp -pR priv "${ED}${dest}/"

This is about preserving executable bits, correct?

> +
> +	einstalldocs
> +}



-- 
Best regards,
Michał Górny
<http://dev.gentoo.org/~mgorny/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 949 bytes --]

  parent reply	other threads:[~2016-05-19  4:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-18 22:35 [gentoo-dev] [PATCH] rebar.eclass: Build Erlang/OTP projects using dev-util/rebar aidecoe
2016-05-18 23:26 ` Peter Stuge
2016-05-20 23:09   ` Amadeusz Żołnowski
2016-05-19  4:39 ` Michał Górny [this message]
2016-05-20 23:06   ` Amadeusz Żołnowski
2016-05-21  7:00     ` Michał Górny
2016-05-21  8:35       ` Amadeusz Żołnowski
2016-05-21 13:26 ` aidecoe
2016-05-21 20:48   ` Michał Górny
2016-05-21 22:11     ` Amadeusz Żołnowski
2016-05-21 23:19 ` aidecoe
2016-05-21 23:22   ` [gentoo-dev] [PATCH 2/2] Add tests for rebar.eclass aidecoe
2016-05-22 21:14   ` [gentoo-dev] [PATCH] rebar.eclass: Build Erlang/OTP projects using dev-util/rebar Michał Górny
2016-05-22 22:07     ` Amadeusz Żołnowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160519063909.651a07e8.mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=aidecoe@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox