Gentoo Archives: gentoo-dev

From: "Maciej Barć" <xgqt@g.o>
To: gentoo-dev@l.g.o
Cc: "Maciej Barć" <xgqt@g.o>
Subject: [gentoo-dev] [PATCH] eclass/dune.eclass: introduce edune and dune-compile (v3)
Date: Wed, 04 Jan 2023 19:02:00
Message-Id: 20230104190132.95884-1-xgqt@gentoo.org
1 edune is a thin wrapper for dune, which will help to run special,
2 uncommon dune commands;
3 dune-compile is a function to selectively pick which packages will be
4 compiled "for-release" (as dune call it);
5 dune-compile without any arguments replaces the current dune_src_compile
6
7 Signed-off-by: Maciej Barć <xgqt@g.o>
8 ---
9 eclass/dune.eclass | 114 ++++++++++++++++++++++++++++++++++++++++-----
10 1 file changed, 103 insertions(+), 11 deletions(-)
11
12 diff --git a/eclass/dune.eclass b/eclass/dune.eclass
13 index 4bc73eda8..655a41be8 100644
14 --- a/eclass/dune.eclass
15 +++ b/eclass/dune.eclass
16 @@ -1,4 +1,4 @@
17 -# Copyright 1999-2022 Gentoo Authors
18 +# Copyright 1999-2023 Gentoo Authors
19 # Distributed under the terms of the GNU General Public License v2
20
21 # @ECLASS: dune.eclass
22 @@ -29,7 +29,7 @@ _DUNE_ECLASS=1
23 # Set before inheriting the eclass.
24 : ${DUNE_PKG_NAME:=${PN}}
25
26 -inherit multiprocessing
27 +inherit edo multiprocessing
28
29 # Do not complain about CFLAGS etc since ml projects do not use them.
30 QA_FLAGS_IGNORED='.*'
31 @@ -44,16 +44,108 @@ BDEPEND="
32 dev-ml/dune
33 "
34
35 +# @FUNCTION: edune
36 +# @USAGE: <arg> ...
37 +# @DESCRIPTION:
38 +# A thin wrapper for the `dune` command.
39 +# Runs `dune` with given arguments and dies on failure.
40 +#
41 +# Example use:
42 +# @CODE
43 +# edune clean
44 +# @CODE
45 +edune() {
46 + debug-print-function ${FUNCNAME} "${@}"
47 +
48 + edo dune "${@}"
49 +}
50 +
51 +# @FUNCTION: dune-release
52 +# @USAGE: <subcommand> [--target target] [package] ...
53 +# @DESCRIPTION:
54 +# Run a selected subcommand for either all of dune packages in current
55 +# directory or only the selected packages. In case of all packages the package
56 +# detection is done via dune itself.
57 +# The `--target` option specifies a target for the selected subcommand,
58 +# it is primarily used for `dune build`, for more info see `man dune-build`.
59 +#
60 +# Example use:
61 +# @CODE
62 +# dune-release build --target @install menhir menhirLib menhirSdk
63 +# @CODE
64 +dune-release() {
65 + debug-print-function ${FUNCNAME} "${@}"
66 +
67 + local subcommand
68 + local target
69 +
70 + # Get the subcommand.
71 + if [[ -z "${1}" ]] ; then
72 + die "dune-release: missing subcommand"
73 + else
74 + subcommand="${1}"
75 + shift
76 + fi
77 +
78 + # Detect if the target is specified.
79 + case "${1}" in
80 + --target )
81 + target="${2}"
82 + shift
83 + shift
84 + ;;
85 + esac
86 +
87 + local -a myduneopts=(
88 + --display=short
89 + --profile release
90 + -j $(makeopts_jobs)
91 + )
92 +
93 + # Resolve the package flag.
94 + if [[ -n "${1}" ]] ; then
95 + myduneopts+=( --for-release-of-packages="$(IFS="," ; echo "${*}")" )
96 + fi
97 +
98 + edune ${subcommand} ${target} "${myduneopts[@]}"
99 +}
100 +
101 +# @FUNCTION: dune-compile
102 +# @USAGE: [package] ...
103 +# @DESCRIPTION:
104 +# Builds either all of or selected dune packages in current directory.
105 +#
106 +# Example use:
107 +# @CODE
108 +# dune-compile menhir menhirLib menhirSdk
109 +# @CODE
110 +dune-compile() {
111 + debug-print-function ${FUNCNAME} "${@}"
112 +
113 + dune-release build --target @install "${@}"
114 +}
115 +
116 +# @FUNCTION: dune-test
117 +# @USAGE: [package] ...
118 +# @DESCRIPTION:
119 +# Tests either all of or selected dune packages in current directory.
120 +#
121 +# Example use:
122 +# @CODE
123 +# dune-test menhir menhirLib menhirSdk
124 +# @CODE
125 +dune-test() {
126 + debug-print-function ${FUNCNAME} "${@}"
127 +
128 + dune-release runtest "${@}"
129 +}
130 +
131 dune_src_compile() {
132 - ebegin "Building"
133 - dune build @install -j $(makeopts_jobs) --profile release
134 - eend $? || die
135 + dune-compile
136 }
137
138 dune_src_test() {
139 - ebegin "Testing"
140 - dune runtest -j $(makeopts_jobs) --profile release
141 - eend $? || die
142 + dune-test
143 }
144
145 # @FUNCTION: dune-install
146 @@ -67,6 +159,8 @@ dune_src_test() {
147 # dune-install menhir menhirLib menhirSdk
148 # @CODE
149 dune-install() {
150 + debug-print-function ${FUNCNAME} "${@}"
151 +
152 local -a pkgs=( "${@}" )
153
154 [[ ${#pkgs[@]} -eq 0 ]] && pkgs=( "${DUNE_PKG_NAME}" )
155 @@ -79,9 +173,7 @@ dune-install() {
156
157 local pkg
158 for pkg in "${pkgs[@]}" ; do
159 - ebegin "Installing ${pkg}"
160 - dune install ${myduneopts[@]} ${pkg}
161 - eend $? || die
162 + edune install ${myduneopts[@]} ${pkg}
163
164 # Move docs to the appropriate place.
165 if [[ -d "${ED}/usr/doc/${pkg}" ]] ; then
166 --
167 2.38.2