1 |
On Sun, 22 May 2016 00:19:49 +0100 |
2 |
aidecoe@g.o wrote: |
3 |
|
4 |
> From: Amadeusz Żołnowski <aidecoe@g.o> |
5 |
> |
6 |
> It is an eclass providing functions to build Erlang/OTP projects using |
7 |
> dev-util/rebar. All packages in upcoming category dev-erlang are going |
8 |
> to use this eclass. |
9 |
> --- |
10 |
> eclass/rebar.eclass | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 |
> 1 file changed, 223 insertions(+) |
12 |
> create mode 100644 eclass/rebar.eclass |
13 |
> |
14 |
> diff --git a/eclass/rebar.eclass b/eclass/rebar.eclass |
15 |
> new file mode 100644 |
16 |
> index 0000000..1a4eaba |
17 |
> --- /dev/null |
18 |
> +++ b/eclass/rebar.eclass |
19 |
> @@ -0,0 +1,223 @@ |
20 |
> +# Copyright 1999-2016 Gentoo Foundation |
21 |
> +# Distributed under the terms of the GNU General Public License v2 |
22 |
> +# $Id$ |
23 |
> + |
24 |
> +# @ECLASS: rebar.eclass |
25 |
> +# @MAINTAINER: |
26 |
> +# Amadeusz Żołnowski <aidecoe@g.o> |
27 |
> +# @AUTHOR: |
28 |
> +# Amadeusz Żołnowski <aidecoe@g.o> |
29 |
> +# @BLURB: Build Erlang/OTP projects using dev-util/rebar. |
30 |
> +# @DESCRIPTION: |
31 |
> +# An eclass providing functions to build Erlang/OTP projects using |
32 |
> +# dev-util/rebar. |
33 |
> +# |
34 |
> +# rebar is a tool which tries to resolve dependencies itself which is by |
35 |
> +# cloning remote git repositories. Dependant projects are usually expected to |
36 |
> +# be in sub-directory 'deps' rather than looking at system Erlang lib |
37 |
> +# directory. Projects relying on rebar usually don't have 'install' make |
38 |
> +# targets. The eclass workarounds some of these problems. It handles |
39 |
> +# installation in a generic way for Erlang/OTP structured projects. |
40 |
> + |
41 |
> +case "${EAPI:-0}" in |
42 |
> + 0|1|2|3|4|5) |
43 |
> + die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" |
44 |
> + ;; |
45 |
> + 6) |
46 |
> + ;; |
47 |
> + *) |
48 |
> + die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" |
49 |
> + ;; |
50 |
> +esac |
51 |
> + |
52 |
> +EXPORT_FUNCTIONS src_prepare src_compile src_install |
53 |
> + |
54 |
> +RDEPEND="dev-lang/erlang" |
55 |
> +DEPEND="${RDEPEND} |
56 |
> + dev-util/rebar |
57 |
> + >=sys-apps/gawk-4.1" |
58 |
> + |
59 |
> +# @ECLASS-VARIABLE: REBAR_APP_SRC |
60 |
> +# @DESCRIPTION: |
61 |
> +# Relative path to .app.src description file. |
62 |
> +REBAR_APP_SRC="${REBAR_APP_SRC-src/${PN}.app.src}" |
63 |
> + |
64 |
> +# @FUNCTION: get_erl_libs |
65 |
> +# @RETURN: the path to Erlang lib directory |
66 |
> +# @DESCRIPTION: |
67 |
> +# Get the full path without EPREFIX to Erlang lib directory. |
68 |
> +get_erl_libs() { |
69 |
> + echo "/usr/$(get_libdir)/erlang/lib" |
70 |
> +} |
71 |
> + |
72 |
> +# @FUNCTION: _rebar_find_dep |
73 |
> +# @INTERNAL |
74 |
> +# @USAGE: <project_name> |
75 |
> +# @RETURN: full path with EPREFIX to a Erlang package/project on success, |
76 |
> +# code 1 when dependency is not found and code 2 if multiple versions of |
77 |
> +# dependency are found. |
78 |
> +# @DESCRIPTION: |
79 |
> +# Find a Erlang package/project by name in Erlang lib directory. Project |
80 |
> +# directory is usually suffixed with version. It is matched to '<project_name>' |
81 |
> +# or '<project_name>-*'. |
82 |
> +_rebar_find_dep() { |
83 |
> + local pn="$1" |
84 |
> + local p |
85 |
> + local result |
86 |
> + |
87 |
> + pushd "${EPREFIX}$(get_erl_libs)" >/dev/null || return 1 |
88 |
> + for p in ${pn} ${pn}-*; do |
89 |
> + if [[ -d ${p} ]]; then |
90 |
> + # Ensure there's at most one matching. |
91 |
> + [[ ${result} ]] && return 2 |
92 |
> + result="${p}" |
93 |
> + fi |
94 |
> + done |
95 |
> + popd >/dev/null || die |
96 |
> + |
97 |
> + [[ ${result} ]] || return 1 |
98 |
> + echo "${result}" |
99 |
> +} |
100 |
> + |
101 |
> +# @FUNCTION: erebar |
102 |
> +# @USAGE: <targets> |
103 |
> +# @DESCRIPTION: |
104 |
> +# Run rebar with verbose flag. Die on failure. |
105 |
> +erebar() { |
106 |
> + debug-print-function ${FUNCNAME} "${@}" |
107 |
> + |
108 |
> + (( $# > 0 )) || die "erebar: at least one target is required" |
109 |
> + |
110 |
> + local -x ERL_LIBS="${EPREFIX}$(get_erl_libs)" |
111 |
> + rebar -v skip_deps=true "$@" || die "rebar $@ failed" |
112 |
|
113 |
Maybe 'die -n', for consistency with emake? |
114 |
|
115 |
> +} |
116 |
> + |
117 |
> +# @FUNCTION: rebar_fix_include_path |
118 |
> +# @USAGE: <project_name> |
119 |
> +# @DESCRIPTION: |
120 |
> +# Fix path in rebar.config to 'include' directory of dependant project/package, |
121 |
> +# so it points to installation in system Erlang lib rather than relative 'deps' |
122 |
> +# directory. |
123 |
> +# |
124 |
> +# The function dies on failure. |
125 |
> +rebar_fix_include_path() { |
126 |
> + debug-print-function ${FUNCNAME} "${@}" |
127 |
> + |
128 |
> + local pn="$1" |
129 |
> + local erl_libs="${EPREFIX}$(get_erl_libs)" |
130 |
> + local p |
131 |
> + |
132 |
> + p="$(_rebar_find_dep "${pn}")" \ |
133 |
> + || die "failed to unambiguously resolve dependency of '${pn}'" |
134 |
> + |
135 |
> + gawk -i inplace \ |
136 |
> + -v erl_libs="${erl_libs}" -v pn="${pn}" -v p="${p}" ' |
137 |
> +/^{[[:space:]]*erl_opts[[:space:]]*,/, /}[[:space:]]*\.$/ { |
138 |
> + pattern = "\"(./)?deps/" pn "/include\""; |
139 |
> + if (match($0, "{i,[[:space:]]*" pattern "[[:space:]]*}")) { |
140 |
> + sub(pattern, "\"" erl_libs "/" p "/include\""); |
141 |
> + } |
142 |
> + print $0; |
143 |
> + next; |
144 |
> +} |
145 |
> +1 |
146 |
> +' rebar.config || die "failed to fix include paths in rebar.config for '${pn}'" |
147 |
> +} |
148 |
> + |
149 |
> +# @FUNCTION: rebar_remove_deps |
150 |
> +# @DESCRIPTION: |
151 |
> +# Remove dependencies list from rebar.config and deceive build rules that any |
152 |
> +# dependencies are already fetched and built. Otherwise rebar tries to fetch |
153 |
> +# dependencies and compile them. |
154 |
> +# |
155 |
> +# The function dies on failure. |
156 |
> +rebar_remove_deps() { |
157 |
> + debug-print-function ${FUNCNAME} "${@}" |
158 |
> + |
159 |
> + mkdir -p "${S}/deps" && :>"${S}/deps/.got" && :>"${S}/deps/.built" || die |
160 |
> + gawk -i inplace ' |
161 |
> +/^{[[:space:]]*deps[[:space:]]*,/, /}[[:space:]]*\.$/ { |
162 |
> + if ($0 ~ /}[[:space:]]*\.$/) { |
163 |
> + print "{deps, []}."; |
164 |
> + } |
165 |
> + next; |
166 |
> +} |
167 |
> +1 |
168 |
> +' rebar.config || die "failed to remove deps from rebar.config" |
169 |
> +} |
170 |
> + |
171 |
> +# @FUNCTION: rebar_set_vsn |
172 |
> +# @USAGE: [<version>] |
173 |
> +# @DESCRIPTION: |
174 |
> +# Set version in project description file if it's not set. |
175 |
> +# |
176 |
> +# <version> is optional. Default is PV stripped from version suffix. |
177 |
> +# |
178 |
> +# The function dies on failure. |
179 |
> +rebar_set_vsn() { |
180 |
> + debug-print-function ${FUNCNAME} "${@}" |
181 |
> + |
182 |
> + local version="${1:-${PV%_*}}" |
183 |
> + |
184 |
> + sed -e "s/vsn, git/vsn, \"${version}\"/" \ |
185 |
> + -i "${S}/${REBAR_APP_SRC}" \ |
186 |
> + || die "failed to set version in src/${PN}.app.src" |
187 |
> +} |
188 |
> + |
189 |
> +# @FUNCTION: rebar_src_prepare |
190 |
> +# @DESCRIPTION: |
191 |
> +# Prevent rebar from fetching in compiling dependencies. Set version in project |
192 |
|
193 |
I think this sentence is incorrect. |
194 |
|
195 |
> +# description file if it's not set. |
196 |
> +# |
197 |
> +# Existence of rebar.config is optional, but file description file must exist |
198 |
> +# at 'src/${PN}.app.src'. |
199 |
> +rebar_src_prepare() { |
200 |
> + debug-print-function ${FUNCNAME} "${@}" |
201 |
> + |
202 |
> + default |
203 |
> + rebar_set_vsn |
204 |
> + [[ -f rebar.config ]] && rebar_remove_deps |
205 |
> +} |
206 |
> + |
207 |
> +# @FUNCTION: rebar_src_configure |
208 |
> +# @DESCRIPTION: |
209 |
> +# Configure with ERL_LIBS set. |
210 |
> +rebar_src_configure() { |
211 |
> + debug-print-function ${FUNCNAME} "${@}" |
212 |
> + |
213 |
> + local -x ERL_LIBS="${EPREFIX}$(get_erl_libs)" |
214 |
> + default |
215 |
> +} |
216 |
> + |
217 |
> +# @FUNCTION: rebar_src_compile |
218 |
> +# @DESCRIPTION: |
219 |
> +# Compile project with rebar. |
220 |
> +rebar_src_compile() { |
221 |
> + debug-print-function ${FUNCNAME} "${@}" |
222 |
> + |
223 |
> + erebar compile |
224 |
> +} |
225 |
> + |
226 |
> +# @FUNCTION: rebar_src_install |
227 |
> +# @DESCRIPTION: |
228 |
> +# Install BEAM files, include headers, executables and native libraries. |
229 |
> +# Install standard docs like README or defined in DOCS variable. |
230 |
> +# |
231 |
> +# Function expects that project conforms to Erlang/OTP structure. |
232 |
> +rebar_src_install() { |
233 |
> + debug-print-function ${FUNCNAME} "${@}" |
234 |
> + |
235 |
> + local bin |
236 |
> + local dest="$(get_erl_libs)/${P}" |
237 |
> + |
238 |
> + insinto "${dest}" |
239 |
> + doins -r ebin |
240 |
> + [[ -d include ]] && doins -r include |
241 |
> + [[ -d bin ]] && for bin in bin/*; do dobin "$bin"; done |
242 |
> + |
243 |
> + if [[ -d priv ]]; then |
244 |
> + cp -pR priv "${ED}${dest}/" || die "failed to install priv/" |
245 |
> + fi |
246 |
> + |
247 |
> + einstalldocs |
248 |
> +} |
249 |
|
250 |
I think I have no further comments, so the two things above considered, |
251 |
looks good to go. |
252 |
|
253 |
-- |
254 |
Best regards, |
255 |
Michał Górny |
256 |
<http://dev.gentoo.org/~mgorny/> |