forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dune.eclass
193 lines (162 loc) · 4.07 KB
/
dune.eclass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: dune.eclass
# @MAINTAINER:
# Mark Wright <[email protected]>
# ML <[email protected]>
# @AUTHOR:
# Rafael Kitover <[email protected]>
# @SUPPORTED_EAPIS: 7 8
# @BLURB: Provides functions for installing Dune packages.
# @DESCRIPTION:
# Provides dependencies on Dune and OCaml and default src_compile, src_test and
# src_install for Dune-based packages.
case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
if [[ ! ${_DUNE_ECLASS} ]]; then
_DUNE_ECLASS=1
# @ECLASS_VARIABLE: DUNE_PKG_NAME
# @PRE_INHERIT
# @DESCRIPTION:
# Sets the actual Dune package name, if different from Gentoo package name.
# Set before inheriting the eclass.
: ${DUNE_PKG_NAME:=${PN}}
inherit edo multiprocessing
# Do not complain about CFLAGS etc since ml projects do not use them.
QA_FLAGS_IGNORED='.*'
RDEPEND="
>=dev-lang/ocaml-4:=[ocamlopt?]
dev-ml/dune:=
"
DEPEND="${RDEPEND}"
BDEPEND="
dev-lang/ocaml
dev-ml/dune
"
# @FUNCTION: edune
# @USAGE: <arg> ...
# @DESCRIPTION:
# A thin wrapper for the `dune` command.
# Runs `dune` with given arguments and dies on failure.
#
# Example use:
# @CODE
# edune clean
# @CODE
edune() {
debug-print-function ${FUNCNAME} "${@}"
edo dune "${@}"
}
# @FUNCTION: dune-release
# @USAGE: <subcommand> [--target target] [package] ...
# @DESCRIPTION:
# Run a selected subcommand for either all of dune packages in current
# directory or only the selected packages. In case of all packages the package
# detection is done via dune itself.
# The `--target` option specifies a target for the selected subcommand,
# it is primarily used for `dune build`, for more info see `man dune-build`.
#
# Example use:
# @CODE
# dune-release build --target @install menhir menhirLib menhirSdk
# @CODE
dune-release() {
debug-print-function ${FUNCNAME} "${@}"
local subcommand
local target
# Get the subcommand.
if [[ -z "${1}" ]] ; then
die "dune-release: missing subcommand"
else
subcommand="${1}"
shift
fi
# Detect if the target is specified.
case "${1}" in
--target )
target="${2}"
shift
shift
;;
esac
local -a myduneopts=(
--display=short
--profile release
-j $(makeopts_jobs)
)
# Resolve the package flag.
if [[ -n "${1}" ]] ; then
myduneopts+=( --for-release-of-packages="$(IFS="," ; echo "${*}")" )
fi
edune ${subcommand} ${target} "${myduneopts[@]}"
}
# @FUNCTION: dune-compile
# @USAGE: [package] ...
# @DESCRIPTION:
# Builds either all of or selected dune packages in current directory.
#
# Example use:
# @CODE
# dune-compile menhir menhirLib menhirSdk
# @CODE
dune-compile() {
debug-print-function ${FUNCNAME} "${@}"
dune-release build --target @install "${@}"
}
# @FUNCTION: dune-test
# @USAGE: [package] ...
# @DESCRIPTION:
# Tests either all of or selected dune packages in current directory.
#
# Example use:
# @CODE
# dune-test menhir menhirLib menhirSdk
# @CODE
dune-test() {
debug-print-function ${FUNCNAME} "${@}"
dune-release runtest "${@}"
}
dune_src_compile() {
dune-compile
}
dune_src_test() {
dune-test
}
# @FUNCTION: dune-install
# @USAGE: <list of packages>
# @DESCRIPTION:
# Installs the dune packages given as arguments. For each "${pkg}" element in
# that list, "${pkg}.install" must be readable from "${PWD}/_build/default"
#
# Example use:
# @CODE
# dune-install menhir menhirLib menhirSdk
# @CODE
dune-install() {
debug-print-function ${FUNCNAME} "${@}"
local -a pkgs=( "${@}" )
[[ ${#pkgs[@]} -eq 0 ]] && pkgs=( "${DUNE_PKG_NAME}" )
local -a myduneopts=(
--prefix="${ED}/usr"
--libdir="${D}$(ocamlc -where)"
--mandir="${ED}/usr/share/man"
)
local pkg
for pkg in "${pkgs[@]}" ; do
edune install ${myduneopts[@]} ${pkg}
# Move docs to the appropriate place.
if [[ -d "${ED}/usr/doc/${pkg}" ]] ; then
mkdir -p "${ED}/usr/share/doc/${PF}/" || die
mv "${ED}/usr/doc/${pkg}" "${ED}/usr/share/doc/${PF}/" || die
rm -rf "${ED}/usr/doc" || die
fi
done
}
dune_src_install() {
dune-install ${1:-${DUNE_PKG_NAME}}
}
fi
EXPORT_FUNCTIONS src_compile src_test src_install