Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] new eclass: meson.eclass for the meson build system
Date: Thu, 04 May 2017 06:07:28
Message-Id: 1493878027.1446.4.camel@gentoo.org
In Reply to: [gentoo-dev] new eclass: meson.eclass for the meson build system by William Hubbs
1 On śro, 2017-05-03 at 22:11 -0500, William Hubbs wrote:
2 > # Copyright 2017 Gentoo Foundation
3 > # Distributed under the terms of the GNU General Public License v2
4 >
5 > # @ECLASS: meson.eclass
6 > # @MAINTAINER:
7 > # William Hubbs <williamh@g.o>
8 > # @BLURB: common ebuild functions for meson-based packages
9 > # @DESCRIPTION:
10 > #
11 > # @EXAMPLE:
12 > # Typical ebuild using meson.eclass:
13 > #
14 > # @CODE
15 > # EAPI=6
16 > #
17 > # inherit meson
18 > #
19 > # ...
20 > #
21 > # src_configure() {
22 > # local mymesonargs=(
23 > # -Dqt4=$(usex qt4 true false)
24 > # -Dthreads=$(usex threads true false)
25 > # -Dtiff=$(usex tiff true false)
26 > # )
27 > # meson_src_configure
28 > # }
29 > #
30 > # ...
31 > #
32 > # @CODE
33 >
34 > case ${EAPI:-0} in
35 > 6) ;;
36 > *) die "EAPI=${EAPI} is not supported" ;;
37 > esac
38 >
39 > EXPORT_FUNCTIONS src_configure src_compile src_install src_test
40
41 It's usually better to order them in run order, i.e. test before
42 install.
43
44 >
45 > if [[ -z ${_MESON} ]]; then
46 > _MESON=1
47
48 _MESON_ECLASS would fit the common naming (and reduce risk of accidental
49 collisions).
50
51 >
52 > inherit ninja-utils toolchain-funcs
53 >
54 > DEPEND=">=dev-util/meson-0.39.1
55 > >=dev-util/ninja-1.7.2"
56 >
57 > # @ECLASS-VARIABLE: BUILD_DIR
58 > # @DEFAULT_UNSET
59 > # @DESCRIPTION:
60 > # Build directory, location where all generated files should be placed.
61 > # If this isn't set, it defaults to ${WORKDIR}/${P}_build.
62 >
63 > # @ECLASS-VARIABLE: EMESON_SOURCE
64 > # @DEFAULT_UNSET
65 > # @DESCRIPTION:
66 > # The location of the source files for the project;this is the source
67 > # directory to pass to meson.
68 > # If this isn't set, it defaults to ${S}
69 >
70 > # @VARIABLE: mymesonargs
71 > # @DEFAULT_UNSET
72 > # @DESCRIPTION:
73 > # Optional meson arguments as Bash array; this should be defined before
74 > # calling meson_src_configure.
75 >
76 > # create a cross file for meson
77 > # fixme: populate one instead of just touching it
78 > _create_cross_file() {
79
80 You definitely want to prefix those functions with '_meson', otherwise
81 there's high risk of collisions.
82
83 > touch "${T}"/meson.crossfile
84 > }
85 >
86 > # set the build directory
87 > _set_build_dir(){
88 > BUILD_DIR="${BUILD_DIR:-${WORKDIR}/${P}-build}"
89
90 : "${BUILD_DIR:=${WORKDIR}/${P}-build}"
91
92 Plus mis-indent. Plus the doc before said it's using underscore between
93 ${P} and build, so you may want to unify that.
94
95 > }
96 >
97 > # @FUNCTION: meson_src_configure
98 > # @DESCRIPTION:
99 > # this is the meson_src_configure function
100 > meson_src_configure() {
101 > debug-print-function ${FUNCNAME} "$@"
102 >
103 > # Common args
104 > local mesonargs=(
105 > --buildtype plain
106 > --libdir "$(get_libdir)"
107 > --localstatedir "${EPREFIX}/var/lib"
108 > --prefix "${EPREFIX}"/usr
109 > --sysconfdir "${EPREFIX}/etc"
110 > )
111 >
112 > if tc-is-cross-compiler; then
113 > _create_cross_file || die "unable to write meson cross file"
114 > mesonargs+=(
115 > --cross-file "${T}"/meson.crossfile
116 > )
117 > fi
118 >
119 > # Append additional arguments from ebuild
120 > mesonargs+=("${mymesonargs[@]}")
121 >
122 > _set_build_dir
123 > set -- meson "${mesonargs[@]}" "$@" \
124 > "${EMESON_SOURCE:-${S}}" "${BUILD_DIR}"
125
126 You've got double space between the paths.
127
128 > echo "$@"
129 > "$@" || die
130 > }
131 >
132 > # @FUNCTION: meson_src_compile
133 > # @DESCRIPTION:
134 > # This is the meson_src_compile function.
135 > meson_src_compile() {
136 > debug-print-function ${FUNCNAME} "$@"
137 >
138 > eninja -v -C "${BUILD_DIR}" || die
139
140 eninja dies on its own in EAPI 4+.
141
142 > }
143 >
144 > # @FUNCTION: meson_src_test
145 > # @DESCRIPTION:
146 > # this is the meson_src_test function.
147 > meson_src_test() {
148 > debug-print-function ${FUNCNAME} "$@"
149 >
150 > eninja -C "${BUILD_DIR}" test || die
151
152 Why no -v here?
153
154 > }
155 >
156 > # @FUNCTION: meson_src_install
157 > # @DESCRIPTION:
158 > # this is the meson_src_install function.
159 > meson_src_install() {
160 > debug-print-function ${FUNCNAME} "$@"
161 >
162 > DESTDIR="${ED}" eninja -C "${BUILD_DIR}" install || die
163
164 Wouldn't this result in double EPREFIX, since you're passing EPREFIX to
165 configure already?
166
167 > }
168 >
169 > fi
170
171 --
172 Best regards,
173 Michał Górny

Attachments

File name MIME type
signature.asc application/pgp-signature