Gentoo Archives: gentoo-commits

From: Florian Schmaus <flow@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/guru:master commit in: eclass/
Date: Wed, 29 Jun 2022 15:38:11
Message-Id: 1656503552.56b12ae84dcc932450abcab8e2099582cf4e22c0.flow@gentoo
1 commit: 56b12ae84dcc932450abcab8e2099582cf4e22c0
2 Author: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq <DOT> in>
3 AuthorDate: Wed Jun 29 08:18:03 2022 +0000
4 Commit: Florian Schmaus <flow <AT> gentoo <DOT> org>
5 CommitDate: Wed Jun 29 11:52:32 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=56b12ae8
7
8 eclass/nimble.eclass: new eclass
9
10 Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq.in>
11
12 eclass/nimble.eclass | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 169 insertions(+)
14
15 diff --git a/eclass/nimble.eclass b/eclass/nimble.eclass
16 new file mode 100644
17 index 000000000..177a2fbd4
18 --- /dev/null
19 +++ b/eclass/nimble.eclass
20 @@ -0,0 +1,169 @@
21 +# Copyright 2022 Gentoo Authors
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +# @ECLASS: nimble.eclass
25 +# @MAINTAINER:
26 +# Anna Vyalkova <cyber+gentoo@×××××.in>
27 +# @AUTHOR:
28 +# Anna Vyalkova <cyber+gentoo@×××××.in>
29 +# @SUPPORTED_EAPIS: 8
30 +# @PROVIDES: nim-utils
31 +# @BLURB: eclass to build Nim packages that use nimble as a build system
32 +# @EXAMPLE:
33 +# Typical ebuild for a Nim application:
34 +#
35 +# EAPI=8
36 +#
37 +# inherit nimble
38 +#
39 +# ...
40 +#
41 +# src_compile() {
42 +# nimble_src_compile
43 +# nimble_build scss
44 +# }
45 +#
46 +# ...
47 +#
48 +#
49 +# Typical ebuild for a Nim library:
50 +#
51 +# EAPI=8
52 +#
53 +# inherit nimble
54 +#
55 +# ...
56 +# SLOT=${PV}
57 +#
58 +# set_package_url "https://github.com/example/example"
59 +
60 +
61 +case ${EAPI} in
62 + 8) ;;
63 + *) die "${ECLASS}: EAPI ${EAPI} unsupported."
64 +esac
65 +
66 +if [[ ! ${_NIMBLE_ECLASS} ]]; then
67 +
68 +# @ECLASS_VARIABLE: BUILD_DIR
69 +# @DEFAULT_UNSET
70 +# @DESCRIPTION:
71 +# Build directory, location where all generated files should be placed.
72 +# If this isn't set, it defaults to ${WORKDIR}/${P}-build.
73 +
74 +inherit edo nim-utils ninja-utils
75 +
76 +BDEPEND="${NINJA_DEPEND}
77 + dev-lang/nim
78 + dev-nim/nimbus
79 +"
80 +
81 +# @FUNCTION: set_package_url
82 +# @USAGE: <url>
83 +# @DESCRIPTION:
84 +# If this function is called, nimbus will generate and install a nimblemeta.json
85 +# file. Some packages specify their dependencies using URLs and nimbus is
86 +# unable to find them unless a metadata file exists.
87 +set_package_url() {
88 + debug-print-function ${FUNCNAME} "${@}"
89 +
90 + (( $# == 1 )) || \
91 + die "${FUNCNAME} takes exactly one argument"
92 +
93 + _PACKAGE_URL="${1}"
94 +}
95 +
96 +# @FUNCTION: get_package_url
97 +# @USAGE:
98 +# @INTERNAL
99 +# @RETURN: package URL
100 +get_package_url() {
101 + echo "${_PACKAGE_URL}"
102 +}
103 +
104 +# @FUNCTION: nimble_src_configure
105 +# @USAGE:
106 +# @DESCRIPTION:
107 +# Configure the package with nimbus. This will start an out-of-source build.
108 +# Passes arguments to Nim by reading from an optionally pre-defined local
109 +# mynimargs bash array.
110 +# @CODE
111 +# src_configure() {
112 +# local mynimargs=(
113 +# --threads:on
114 +# )
115 +# nimble_src_configure
116 +# }
117 +# @CODE
118 +nimble_src_configure() {
119 + debug-print-function ${FUNCNAME} "${@}"
120 +
121 + [[ -n "${NINJA_DEPEND}" ]] || \
122 + ewarn "Unknown value '${NINJA}' for \${NINJA}"
123 +
124 + BUILD_DIR="${BUILD_DIR:-${WORKDIR}/${P}-build}"
125 +
126 + [[ -z ${mynimargs} ]] && local -a mynimargs=()
127 + local mynimargstype=$(declare -p mynimargs 2>&-)
128 + if [[ "${mynimargstype}" != "declare -a mynimargs="* ]]; then
129 + die "mynimargs must be declared as array"
130 + fi
131 +
132 + nim_gen_config
133 +
134 + local nimbusargs=(
135 + --nimbleDir:"${EPREFIX}"/opt/nimble
136 + --binDir:"${EPREFIX}"/usr/bin
137 + --url:"$(get_package_url)"
138 + "${mynimargs[@]}"
139 + )
140 +
141 + edo nimbus "${nimbusargs[@]}" "${S}" "${BUILD_DIR}"
142 +}
143 +
144 +# @FUNCTION: nimble_build
145 +# @USAGE: [ninja args...]
146 +# @DESCRIPTION:
147 +# Function for building the package. All arguments are passed to eninja.
148 +nimble_build() {
149 + debug-print-function ${FUNCNAME} "${@}"
150 +
151 + eninja -C "${BUILD_DIR}" "${@}"
152 +}
153 +
154 +# @FUNCTION: nimble_src_compile
155 +# @USAGE: [ninja args...]
156 +# @DESCRIPTION:
157 +# Build the package with Ninja. All arguments are passed to nimble_build.
158 +nimble_src_compile() {
159 + debug-print-function ${FUNCNAME} "${@}"
160 +
161 + nimble_build "${@}"
162 +}
163 +
164 +# @FUNCTION: nimble_src_test
165 +# @USAGE: [ninja args...]
166 +# @DESCRIPTION:
167 +# Test the package. All arguments are passed to nimble_build.
168 +nimble_src_test() {
169 + debug-print-function ${FUNCNAME} "${@}"
170 +
171 + if nonfatal nimble_build test -n &> /dev/null; then
172 + nimble_build test "${@}"
173 + fi
174 +}
175 +
176 +# @FUNCTION: nimble_src_install
177 +# @DESCRIPTION:
178 +# Install the package with Ninja. All arguments are passed to nimble_build.
179 +nimble_src_install() {
180 + debug-print-function ${FUNCNAME} "${@}"
181 +
182 + DESTDIR="${D}" nimble_build install "${@}"
183 + einstalldocs
184 +}
185 +
186 +_NIMBLE_ECLASS=1
187 +fi
188 +
189 +EXPORT_FUNCTIONS src_configure src_compile src_test src_install