From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 701D8138262 for ; Sat, 21 May 2016 20:48:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7EFEF141B8; Sat, 21 May 2016 20:48:23 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 62BBF224046 for ; Sat, 21 May 2016 20:48:22 +0000 (UTC) Received: from pomiot (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id E65ED340D3C; Sat, 21 May 2016 20:48:19 +0000 (UTC) Date: Sat, 21 May 2016 22:48:14 +0200 From: =?UTF-8?B?TWljaGHFgiBHw7Nybnk=?= 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 Message-ID: <20160521224814.55493d6c.mgorny@gentoo.org> In-Reply-To: <1463837160-622-1-git-send-email-aidecoe@gentoo.org> References: <1463610918-4062-1-git-send-email-aidecoe@gentoo.org> <1463837160-622-1-git-send-email-aidecoe@gentoo.org> Organization: Gentoo X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) 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 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/mGBDnYl+w+APR.93rsc8_PJ"; protocol="application/pgp-signature" X-Archives-Salt: 4e6fab88-d8b6-4464-8a1d-14bd13ffed0b X-Archives-Hash: cec61558ee786f3dcde8148bec1acf32 --Sig_/mGBDnYl+w+APR.93rsc8_PJ Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, 21 May 2016 14:26:00 +0100 aidecoe@gentoo.org wrote: > From: Amadeusz =C5=BBo=C5=82nowski >=20 > 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 | 217 ++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 217 insertions(+) > create mode 100644 eclass/rebar.eclass >=20 > diff --git a/eclass/rebar.eclass b/eclass/rebar.eclass > new file mode 100644 > index 0000000..9da1340 > --- /dev/null > +++ b/eclass/rebar.eclass > @@ -0,0 +1,217 @@ > +# Copyright 1999-2016 Gentoo Foundation > +# Distributed under the terms of the GNU General Public License v2 > +# $Id$ > + > +# @ECLASS: rebar.eclass > +# @MAINTAINER: > +# Amadeusz =C5=BBo=C5=82nowski > +# @AUTHOR: > +# Amadeusz =C5=BBo=C5=82nowski > +# @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 expect= ed 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|5) > + die "Unsupported EAPI=3D${EAPI:-0} (too old) for ${ECLASS}" > + ;; > + 6) > + ;; > + *) > + die "Unsupported EAPI=3D${EAPI} (unknown) for ${ECLASS}" > + ;; > +esac > + > +inherit eutils > + > +EXPORT_FUNCTIONS src_prepare src_compile src_install > + > +RDEPEND=3D"dev-lang/erlang" > +DEPEND=3D"${RDEPEND} > + dev-util/rebar" > + > +# @ECLASS-VARIABLE: REBAR_APP_SRC > +# @DESCRIPTION: > +# Relative path to .app.src description file. > +REBAR_APP_SRC=3D"${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_version > +# @INTERNAL > +# @USAGE: > +# @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 or > +# -* is returned. > +_rebar_find_dep_version() { > + local pn=3D"$1" > + local p > + > + pushd "${EPREFIX}$(get_erl_libs)" >/dev/null || die > + for p in ${pn} ${pn}-*; do > + if [[ -d ${p} ]]; then > + echo "${p#${pn}-}" > + break > + fi > + done > + popd >/dev/null || die > + > + [[ -d ${p} ]] > +} > + > +# @FUNCTION: erebar > +# @USAGE: > +# @DESCRIPTION: > +# Run rebar with verbose flag. Die on failure. > +erebar() { > + debug-print-function ${FUNCNAME} "${@}" > + > + (( $# > 0 )) || die 'erebar: at least one target is required' Why not [[ $# -gt 0 ]]? It's the first time I see someone using (( )) for conditionals. > + > + evar_push ERL_LIBS > + export ERL_LIBS=3D"${EPREFIX}$(get_erl_libs)" local -x ERL_LIBS=3D... We don't really have to employ terribly ugly eval hackery to have a local variable. > + rebar -v skip_deps=3Dtrue "$@" || die "rebar $@ failed" > + evar_pop > +} > + > +# @FUNCTION: rebar_fix_include_path > +# @USAGE: > +# @DESCRIPTION: > +# Fix path in rebar.config to 'include' directory of dependant project/p= ackage, > +# so it points to installation in system Erlang lib rather than relative= 'deps' > +# directory. > +# > +# The function dies on failure. > +rebar_fix_include_path() { > + debug-print-function ${FUNCNAME} "${@}" > + > + local pn=3D"$1" > + local erl_libs=3D"${EPREFIX}$(get_erl_libs)" > + local pv=3D"$(_rebar_find_dep_version "${pn}")" > + > + eawk rebar.config \ > + -v erl_libs=3D"${erl_libs}" -v pn=3D"${pn}" -v pv=3D"${pv}" \ > + '/^{[[:space:]]*erl_opts[[:space:]]*,/, /}[[:space:]]*\.$/ { > + pattern =3D "\"(./)?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 meant indent like this: + eawk rebar.config \ + -v erl_libs=3D"${erl_libs}" -v pn=3D"${pn}" -v pv=3D"${pv}" \ + '/^{[[:space:]]*erl_opts[[:space:]]*,/, /}[[:space:]]*\.$/ { + pattern =3D "\"(./)?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" > +} > + > +# @FUNCTION: rebar_remove_deps > +# @DESCRIPTION: > +# Remove dependencies list from rebar.config and deceive build rules tha= t any > +# dependencies are already fetched and built. Otherwise rebar tries to f= etch > +# dependencies and compile them. > +# > +# The function dies on failure. > +rebar_remove_deps() { > + debug-print-function ${FUNCNAME} "${@}" > + > + mkdir -p "${S}/deps" && :>"${S}/deps/.got" && :>"${S}/deps/.built" || d= ie > + 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: [] > +# @DESCRIPTION: > +# Set version in project description file if it's not set. > +# > +# is optional. Default is PV stripped from version suffix. > +# > +# The function dies on failure. > +rebar_set_vsn() { > + debug-print-function ${FUNCNAME} "${@}" > + > + local version=3D"${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 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'. > +rebar_src_prepare() { > + debug-print-function ${FUNCNAME} "${@}" > + > + default > + rebar_set_vsn > + [[ -f rebar.config ]] && rebar_remove_deps > +} > + > +# @FUNCTION: rebar_src_configure > +# @DESCRIPTION: > +# Configure with ERL_LIBS set. > +rebar_src_configure() { > + debug-print-function ${FUNCNAME} "${@}" > + > + evar_push ERL_LIBS > + export ERL_LIBS=3D"${EPREFIX}$(get_erl_libs)" > + default > + evar_pop > +} > + > +# @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. > +# > +# Function expects that project conforms to Erlang/OTP structure. > +rebar_src_install() { > + debug-print-function ${FUNCNAME} "${@}" > + > + local bin > + local dest=3D"$(get_erl_libs)/${P}" > + > + insinto "${dest}" > + doins -r ebin > + [[ -d include ]] && doins -r include > + [[ -d bin ]] && for bin in bin/*; do dobin "$bin"; done > + [[ -d priv ]] && cp -pR priv "${ED}${dest}/" Missing ||die. Just don't do it as one-liner :-P. > + > + einstalldocs > +} --=20 Best regards, Micha=C5=82 G=C3=B3rny --Sig_/mGBDnYl+w+APR.93rsc8_PJ Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQJ8BAEBCgBmBQJXQMmOXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQ2REJCMDdDQzRGMERBRDA2RUEwQUZFNDFC MDdBMUFFQUVGQjQ0NjRFAAoJELB6GurvtEZObzUQALu6tKffCLwc/OJZJpAOAi7p AEz5FmErDAh/RZoa0P9Ci+DQLObYceEHrUOoWhr0flZ8U+RczVJb7+jTtPQ1sizT wDB2GkYT+vPn1j1KycP2dcX1oFzHvI8yMVmQoX/1/J5VTHrfRPbLJxDFTNPbEnts M9YFEnwmkKkypnYbf/4k4wqDUMOeJ+Pi+t2NRHUEZj7Bx7TRWyzWE5ZNuGs+ZK36 Ev8zEp7uLl8j8DqoTIQ1Pp+MPWiB0/QYAb4+6IMK7W7pY9xJH2Lv8ni3EcUTyLcw 50KhsenKw3XdOEIdNIzgauXcgiuSZsxy1rmefWDfxIcjOZSLRe4gL6+LyVbDrSEZ zxq/HhHkRSH3Ucd/ggKJYK76E7ensz5S0UoT5wRDxDDbCOf1sENyMIvGe/O3zify 8oPXn/hp1PjlKf59CzxB4smBzWMadKrBiX2S7ogB5dCXWavcfg8SlWVg/gsEkb19 DYvYTImdrFiZCqfNsR+p7oLJVKFol6gAjsiy6eljIpb713+hrt4iE85RdIedZPt8 8C39dC6rYbMk9vcnQzTRxhXIkun6Mx93DHNRPZPEH4aEAEyNxBq9VXO1e/AlbrGS KdrHOJwgr3HBI8aB04bz5h47ha6oq20CcLCrGhmx7UaEtXsMq9NI6NzI+L2OeImX Jo4dmb9CFhcGZwCcjgRc =Bnai -----END PGP SIGNATURE----- --Sig_/mGBDnYl+w+APR.93rsc8_PJ--