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:12
Message-Id: 1656503546.d34b616bfc616418be86dab44d53f9397665a7bc.flow@gentoo
1 commit: d34b616bfc616418be86dab44d53f9397665a7bc
2 Author: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq <DOT> in>
3 AuthorDate: Wed Jun 29 07:13:20 2022 +0000
4 Commit: Florian Schmaus <flow <AT> gentoo <DOT> org>
5 CommitDate: Wed Jun 29 11:52:26 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=d34b616b
7
8 eclass/nim-utils.eclass: new eclass
9
10 Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo <AT> sysrq.in>
11
12 eclass/nim-utils.eclass | 115 ++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 115 insertions(+)
14
15 diff --git a/eclass/nim-utils.eclass b/eclass/nim-utils.eclass
16 new file mode 100644
17 index 000000000..12b077452
18 --- /dev/null
19 +++ b/eclass/nim-utils.eclass
20 @@ -0,0 +1,115 @@
21 +# Copyright 2022 Gentoo Authors
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +# @ECLASS: nim-utils.eclass
25 +# @MAINTAINER:
26 +# Anna Vyalkova <cyber+gentoo@×××××.in>
27 +# @AUTHOR:
28 +# Anna Vyalkova <cyber+gentoo@×××××.in>
29 +# @SUPPORTED_EAPIS: 8
30 +# @BLURB: utility functions for Nim packages
31 +# @DESCRIPTION:
32 +# A utility eclass providing functions to call and configure Nim.
33 +#
34 +# This eclass does not set any metadata variables nor export any phase
35 +# functions. It can be inherited safely.
36 +
37 +case ${EAPI} in
38 + 8) ;;
39 + *) die "${ECLASS}: EAPI ${EAPI} unsupported."
40 +esac
41 +
42 +if [[ ! ${_NIM_UTILS_ECLASS} ]]; then
43 +
44 +# @ECLASS_VARIABLE: NIMFLAGS
45 +# @USER_VARIABLE
46 +# @DEFAULT_UNSET
47 +# @DESCRIPTION:
48 +# Flags for the Nim compiler.
49 +
50 +# @ECLASS_VARIABLE: TESTAMENT_DISABLE_MEGATEST
51 +# @USER_VARIABLE
52 +# @DEFAULT_UNSET
53 +# @DESCRIPTION:
54 +# If set, pass '--megatest:off' to testament.
55 +
56 +# @VARIABLE: ETESTAMENT_DESELECT
57 +# @DEFAULT_UNSET
58 +# @DESCRIPTION:
59 +# Specifies an array of test files to be deselected via testament's --skipFrom
60 +# parameter, when calling etestament.
61 +
62 +inherit multiprocessing toolchain-funcs xdg-utils
63 +
64 +# @FUNCTION: enim
65 +# @USAGE: [<args>...]
66 +# @DESCRIPTION:
67 +# Call nim, passing the supplied arguments.
68 +# This function dies if nim fails. It also supports being called via 'nonfatal'.
69 +# If you need to call nim directly in your ebuilds, this is the way it should
70 +# be done.
71 +enim() {
72 + debug-print-function ${FUNCNAME} "${@}"
73 +
74 + set -- nim "${@}"
75 + echo "$@" >&2
76 + "$@" || die -n "${*} failed"
77 +}
78 +
79 +# @FUNCTION: etestament
80 +# @USAGE: [<args>...]
81 +# @DESCRIPTION:
82 +# Call testament, passing the supplied arguments.
83 +# This function dies if testament fails.
84 +etestament() {
85 + debug-print-function ${FUNCNAME} "${@}"
86 +
87 + local -a testament_args=()
88 + [[ ${TESTAMENT_DISABLE_MEGATEST} ]] && \
89 + testament_args+=( --megatest:off )
90 +
91 + [[ "${NOCOLOR}" == true || "${NOCOLOR}" == yes ]] && \
92 + testament_args+=( --colors:off )
93 +
94 + if [[ ${ETESTAMENT_DESELECT} ]]; then
95 + local skipfile="${T}"/testament.skipfile
96 + for t in "${ETESTAMENT_DESELECT[@]}"; do
97 + echo "${t}" >> "${skipfile}"
98 + done
99 + testament_args+=( --skipFrom:"${skipfile}" )
100 + fi
101 +
102 + set -- testament "${testament_args[@]}" "${@}"
103 + echo "$@" >&2
104 + "$@" || die -n "${*} failed"
105 +}
106 +
107 +# @FUNCTION: nim_gen_config
108 +# @USAGE:
109 +# @DESCRIPTION:
110 +# Generate the ${WORKDIR}/nim.cfg to respect user's toolchain and preferences.
111 +nim_gen_config() {
112 + debug-print-function ${FUNCNAME} "${@}"
113 +
114 + xdg_environment_reset
115 +
116 + cat > "${WORKDIR}/nim.cfg" <<- EOF || die "Failed to create Nim config"
117 + cc:"gcc"
118 + gcc.exe:"$(tc-getCC)"
119 + gcc.linkerexe:"$(tc-getCC)"
120 + gcc.cpp.exe:"$(tc-getCXX)"
121 + gcc.cpp.linkerexe:"$(tc-getCXX)"
122 + gcc.options.always:"${CFLAGS} ${CPPFLAGS}"
123 + gcc.options.linker:"${LDFLAGS}"
124 + gcc.cpp.options.always:"${CFLAGS} ${CPPFLAGS}"
125 + gcc.cpp.options.linker:"${LDFLAGS}"
126 +
127 + $([[ "${NOCOLOR}" == true || "${NOCOLOR}" == yes ]] && echo '--colors:"off"')
128 + -d:"release"
129 + --parallelBuild:"$(makeopts_jobs)"
130 + $(printf "%s\n" ${NIMFLAGS})
131 + EOF
132 +}
133 +
134 +_NIM_UTILS_ECLASS=1
135 +fi