1 |
On Tue, 2019-11-05 at 00:30 +0100, Andreas Sturmlechner wrote: |
2 |
> Support eclass for packages that use KDE extra-cmake-modules. |
3 |
> |
4 |
> This eclass is intended to streamline the creation of ebuilds for packages |
5 |
> that follow KDE upstream packaging conventions. It's primarily intended for |
6 |
> the three upstream release groups (Frameworks, Plasma, Applications) but |
7 |
> is also for any package that follows similar conventions. |
8 |
> |
9 |
> This eclass unconditionally inherits cmake-utils.eclass and all its public |
10 |
> variables and helper functions (not phase functions) may be considered as part |
11 |
> of this eclass's API. |
12 |
> |
13 |
> When used together with kde.org.eclass this will replace kde5.eclass and |
14 |
> kde5-functions.eclass, most of the latter is becoming obsolete. |
15 |
> |
16 |
> --- /dev/null |
17 |
> +++ b/eclass/ecm-utils.eclass |
18 |
|
19 |
I know we historically screwed this up repeatedly but please don't use |
20 |
'-utils' for eclasses that export phases. |
21 |
|
22 |
> @@ -0,0 +1,549 @@ |
23 |
> +# Copyright 1999-2019 Gentoo Authors |
24 |
> +# Distributed under the terms of the GNU General Public License v2 |
25 |
> + |
26 |
> +# @ECLASS: ecm-utils.eclass |
27 |
> +# @MAINTAINER: |
28 |
> +# kde@g.o |
29 |
> +# @SUPPORTED_EAPIS: 7 |
30 |
> +# @BLURB: Support eclass for packages that use KDE extra-cmake-modules. |
31 |
> +# @DESCRIPTION: |
32 |
> +# This eclass is intended to streamline the creation of ebuilds for packages |
33 |
> +# that follow KDE upstream packaging conventions. It's primarily intended for |
34 |
> +# the three upstream release groups (Frameworks, Plasma, Applications) but |
35 |
> +# is also for any package that follows similar conventions. |
36 |
> +# |
37 |
> +# This eclass unconditionally inherits cmake-utils.eclass and all its public |
38 |
> +# variables and helper functions (not phase functions) may be considered as |
39 |
> part |
40 |
> +# of this eclass's API. |
41 |
> +# |
42 |
> +# This eclass's phase functions are not intended to be mixed and matched, so |
43 |
> if |
44 |
> +# any phase functions are overridden the version here should also be called. |
45 |
> + |
46 |
> +if [[ -z ${_ECM_UTILS_ECLASS} ]]; then |
47 |
> +_ECM_UTILS_ECLASS=1 |
48 |
> + |
49 |
> +# @ECLASS-VARIABLE: VIRTUALX_REQUIRED |
50 |
> +# @DESCRIPTION: |
51 |
> +# For proper description see virtualx.eclass manpage. |
52 |
> +# Here we redefine default value to be manual, if your package needs virtualx |
53 |
> +# for tests you should proceed with setting VIRTUALX_REQUIRED=test. |
54 |
> +: ${VIRTUALX_REQUIRED:=manual} |
55 |
> + |
56 |
> +inherit cmake-utils flag-o-matic toolchain-funcs virtualx xdg |
57 |
> + |
58 |
> +case ${EAPI} in |
59 |
> + 7) ;; |
60 |
> + *) die "EAPI=${EAPI:-0} is not supported" ;; |
61 |
> +esac |
62 |
> + |
63 |
> +if [[ -v KDE_GCC_MINIMAL ]]; then |
64 |
> + EXPORT_FUNCTIONS pkg_pretend |
65 |
> +fi |
66 |
> + |
67 |
> +EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_test pkg_preinst |
68 |
> pkg_postinst pkg_postrm |
69 |
> + |
70 |
> +# @ECLASS-VARIABLE: ECM_KDEINSTALLDIRS |
71 |
> +# @DESCRIPTION: |
72 |
> +# If set to "false", do nothing. |
73 |
> +# For any other value, assume the package is using KDEInstallDirs macro and |
74 |
> switch |
75 |
> +# KDE_INSTALL_USE_QT_SYS_PATHS to ON. |
76 |
> +: ${ECM_KDEINSTALLDIRS:=true} |
77 |
> + |
78 |
> +# @ECLASS-VARIABLE: ECM_NONGUI |
79 |
> +# @DESCRIPTION: |
80 |
> +# If set to "false", add dependency on kde-frameworks/breeze-icons |
81 |
> +# or kde-frameworks/oxygen-icons and run the xdg.eclass routines for |
82 |
> +# pkg_preinst, pkg_postinst and pkg_postrm. |
83 |
> +# For any other value, do nothing. |
84 |
> +if [[ ${CATEGORY} = kde-frameworks ]]; then |
85 |
> + : ${ECM_NONGUI:=true} |
86 |
> +fi |
87 |
> +: ${ECM_NONGUI:=false} |
88 |
|
89 |
I don't think eclassdoc is going to parse this correctly. |
90 |
|
91 |
> + |
92 |
> +# @ECLASS-VARIABLE: ECM_DEBUG |
93 |
> +# @DESCRIPTION: |
94 |
> +# If set to "false", add -DNDEBUG (via cmake-utils_src_configure) and |
95 |
> +# -DQT_NO_DEBUG to CPPFLAGS. |
96 |
> +# Otherwise, add debug to IUSE. |
97 |
> +: ${ECM_DEBUG:=true} |
98 |
|
99 |
To be honest, I don't really like this 'anything-or-false' logic. It's |
100 |
rather confusing and error-prone. For example, if I misspell 'false' |
101 |
the eclass is going to silently assume true. |
102 |
|
103 |
> + |
104 |
> +# @ECLASS-VARIABLE: ECM_DESIGNERPLUGIN |
105 |
> +# @DESCRIPTION: |
106 |
> +# If set to "false", do nothing. |
107 |
> +# Otherwise, add "designer" to IUSE to toggle build of designer plugins |
108 |
> +# and add the necessary BDEPEND. |
109 |
> +: ${ECM_DESIGNERPLUGIN:=false} |
110 |
> + |
111 |
> +# @ECLASS-VARIABLE: ECM_EXAMPLES |
112 |
> +# @DESCRIPTION: |
113 |
> +# If set to "false", unconditionally ignore a top-level examples |
114 |
> subdirectory. |
115 |
> +# Otherwise, add "examples" to IUSE to toggle adding that subdirectory. |
116 |
> +: ${ECM_EXAMPLES:=false} |
117 |
> + |
118 |
> +# @ECLASS-VARIABLE: ECM_HANDBOOK |
119 |
> +# @DESCRIPTION: |
120 |
> +# If set to "false", do nothing. |
121 |
> +# Otherwise, add "+handbook" to IUSE, add the appropriate dependency, and let |
122 |
> +# KF5DocTools generate and install the handbook from docbook file(s) found in |
123 |
> +# ECM_HANDBOOK_DIR. However if USE handbook is disabled, disable build of |
124 |
> +# ECM_HANDBOOK_DIR in CMakeLists.txt. |
125 |
> +# If set to "optional", config with - |
126 |
> DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON |
127 |
> +# when USE=!handbook. In case package requires KF5KDELibs4Support, see next: |
128 |
> +# If set to "forceoptional", remove a KF5DocTools dependency from the root |
129 |
> +# CMakeLists.txt in addition to the above. |
130 |
> +: ${ECM_HANDBOOK:=false} |
131 |
> + |
132 |
> +# @ECLASS-VARIABLE: ECM_HANDBOOK_DIR |
133 |
> +# @DESCRIPTION: |
134 |
> +# Specifies the directory containing the docbook file(s) relative to ${S} to |
135 |
> be |
136 |
> +# processed by KF5DocTools (kdoctools_install) if not the default. |
137 |
> +: ${ECM_HANDBOOK_DIR:=doc} |
138 |
> + |
139 |
> +# @ECLASS-VARIABLE: ECM_PO_DIRS |
140 |
> +# @DESCRIPTION: |
141 |
> +# Specifies the top-level directories of l10n files relative to ${S} to be |
142 |
> +# processed by KF5I18n (ki18n_install) if not the default. If IUSE nls exists |
143 |
> +# and is disabled then disable build of these directories in CMakeLists.txt. |
144 |
> +: ${ECM_PO_DIRS:="po poqm"} |
145 |
> + |
146 |
> +# @ECLASS-VARIABLE: ECM_QTHELP |
147 |
> +# @DESCRIPTION: |
148 |
> +# If set to "false", do nothing. |
149 |
> +# Otherwise, add "doc" to IUSE, add the appropriate dependency, generate |
150 |
> +# and install Qt compressed help files with -DBUILD_QCH=ON when USE=doc. |
151 |
> +if [[ ${CATEGORY} = kde-frameworks ]]; then |
152 |
> + : ${ECM_QTHELP:=true} |
153 |
> +fi |
154 |
> +: ${ECM_QTHELP:=false} |
155 |
|
156 |
Again, I believe this and below won't be processed by eclassdoc |
157 |
correctly. |
158 |
|
159 |
> + |
160 |
> +# @ECLASS-VARIABLE: ECM_TEST |
161 |
> +# @DESCRIPTION: |
162 |
> +# If set to "false", do nothing. |
163 |
> +# For any other value, add test to IUSE and add a dependency on dev-qt/ |
164 |
> qttest:5. |
165 |
> +# If set to "optional", configure with - |
166 |
> DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON |
167 |
> +# when USE=!test. |
168 |
> +# If set to "forceoptional", remove a Qt5Test dependency and comment test |
169 |
> +# subdirs from the root CMakeLists.txt in addition to the above. |
170 |
> +# If set to "forceoptional-recursive", remove Qt5Test dependencies and make |
171 |
> +# autotest(s), unittest(s) and test(s) subdirs from *any* CMakeLists.txt in $ |
172 |
> {S} |
173 |
> +# and below conditional on BUILD_TESTING. This is always meant as a short- |
174 |
> term |
175 |
> +# fix and creates ${T}/${P}-tests-optional.patch to refine and submit |
176 |
> upstream. |
177 |
> +if [[ ${CATEGORY} = kde-frameworks ]]; then |
178 |
> + : ${ECM_TEST:=true} |
179 |
> +fi |
180 |
> +: ${ECM_TEST:=false} |
181 |
> + |
182 |
> +case ${ECM_NONGUI} in |
183 |
|
184 |
There's a @PRE_INHERIT thingie to indicate variables that need to be set |
185 |
before 'inherit' to work correctly. |
186 |
|
187 |
> + false) |
188 |
> + # gui applications need breeze or oxygen icons for basic iconset, |
189 |
> bug #564838 |
190 |
> + RDEPEND+=" || ( kde-frameworks/breeze-icons:5 kde-frameworks/ |
191 |
> oxygen-icons:* )" |
192 |
> + ;; |
193 |
> + *) ;; |
194 |
> +esac |
195 |
> + |
196 |
> +case ${ECM_DEBUG} in |
197 |
> + false) ;; |
198 |
> + *) |
199 |
> + IUSE+=" debug" |
200 |
> + ;; |
201 |
> +esac |
202 |
> + |
203 |
> +case ${ECM_DESIGNERPLUGIN} in |
204 |
> + false) ;; |
205 |
> + *) |
206 |
> + IUSE+=" designer" |
207 |
> + BDEPEND+=" designer? ( dev-qt/designer:5 )" |
208 |
> + ;; |
209 |
> +esac |
210 |
> + |
211 |
> +# @ECLASS-VARIABLE: KDE_DESIGNERPLUGIN |
212 |
> +# @DESCRIPTION: |
213 |
> +# If set to "false", do nothing. |
214 |
> +# Otherwise, add "designer" to IUSE to toggle build of designer plugins |
215 |
> +# and add the necessary BDEPEND. |
216 |
> +# TODO: drop after KDE Applications 19.08.3 removal |
217 |
> +: ${KDE_DESIGNERPLUGIN:=false} |
218 |
> +case ${KDE_DESIGNERPLUGIN} in |
219 |
> + false) ;; |
220 |
> + *) |
221 |
> + IUSE+=" designer" |
222 |
> + BDEPEND+=" designer? ( kde-frameworks/kdesignerplugin:5 )" |
223 |
> + ;; |
224 |
> +esac |
225 |
> + |
226 |
> +case ${ECM_EXAMPLES} in |
227 |
> + false) ;; |
228 |
> + *) |
229 |
> + IUSE+=" examples" |
230 |
> + ;; |
231 |
> +esac |
232 |
> + |
233 |
> +case ${ECM_HANDBOOK} in |
234 |
> + false) ;; |
235 |
> + *) |
236 |
> + IUSE+=" +handbook" |
237 |
> + BDEPEND+=" handbook? ( kde-frameworks/kdoctools:5 )" |
238 |
> + ;; |
239 |
> +esac |
240 |
> + |
241 |
> +case ${ECM_QTHELP} in |
242 |
> + false) ;; |
243 |
> + *) |
244 |
> + IUSE+=" doc" |
245 |
> + COMMONDEPEND+=" doc? ( dev-qt/qt-docs:5 )" |
246 |
> + BDEPEND+=" doc? ( |
247 |
> + >=app-doc/doxygen-1.8.13-r1 |
248 |
> + dev-qt/qthelp:5 |
249 |
> + )" |
250 |
> + ;; |
251 |
> +esac |
252 |
> + |
253 |
> +case ${ECM_TEST} in |
254 |
> + false) ;; |
255 |
> + *) |
256 |
> + IUSE+=" test" |
257 |
> + DEPEND+=" test? ( dev-qt/qttest:5 )" |
258 |
> + RESTRICT+=" !test? ( test )" |
259 |
> + ;; |
260 |
> +esac |
261 |
> + |
262 |
> +BDEPEND+=" >=kde-frameworks/extra-cmake-modules-5.60.0" |
263 |
> +RDEPEND+=" >=kde-frameworks/kf-env-4" |
264 |
> +COMMONDEPEND+=" dev-qt/qtcore:5" |
265 |
> + |
266 |
> +DEPEND+=" ${COMMONDEPEND}" |
267 |
> +RDEPEND+=" ${COMMONDEPEND}" |
268 |
> +unset COMMONDEPEND |
269 |
> + |
270 |
> +# @ECLASS-VARIABLE: KDE_GCC_MINIMAL |
271 |
> +# @DEFAULT_UNSET |
272 |
> +# @DESCRIPTION: |
273 |
> +# Minimum version of active GCC to require. This is checked in |
274 |
> +# ecm-utils_pkg_pretend and ecm-utils_pkg_setup. |
275 |
> + |
276 |
> +# @FUNCTION: _check_gcc_version |
277 |
|
278 |
Would be nice to prefix it with _ecm*. |
279 |
|
280 |
> +# @INTERNAL |
281 |
> +# @DESCRIPTION: |
282 |
> +# Determine if the current GCC version is acceptable, otherwise die. |
283 |
> +_check_gcc_version() { |
284 |
> + if [[ ${MERGE_TYPE} != binary && -v KDE_GCC_MINIMAL ]] && tc-is-gcc; |
285 |
> then |
286 |
> + |
287 |
> + local version=$(gcc-version) |
288 |
> + local major=${version%.*} |
289 |
> + local minor=${version#*.} |
290 |
> + local min_major=${KDE_GCC_MINIMAL%.*} |
291 |
> + local min_minor=${KDE_GCC_MINIMAL#*.} |
292 |
> + |
293 |
> + debug-print "GCC version check activated" |
294 |
> + debug-print "Version detected:" |
295 |
> + debug-print " - Full: ${version}" |
296 |
> + debug-print " - Major: ${major}" |
297 |
> + debug-print " - Minor: ${minor}" |
298 |
> + debug-print "Version required:" |
299 |
> + debug-print " - Major: ${min_major}" |
300 |
> + debug-print " - Minor: ${min_minor}" |
301 |
> + |
302 |
> + [[ ${major} -lt ${min_major} ]] || \ |
303 |
> + ( [[ ${major} -eq ${min_major} && ${minor} -lt $ |
304 |
> {min_minor} ]] ) \ |
305 |
> + && die "Sorry, but gcc-${KDE_GCC_MINIMAL} or later is |
306 |
> required for this package (found ${version})." |
307 |
|
308 |
Why not use ver_cmp from EAPI 7? |
309 |
|
310 |
> + fi |
311 |
> +} |
312 |
> + |
313 |
> +# @FUNCTION: ecm_punt_bogus_dep |
314 |
> +# @USAGE: <prefix> <dependency> |
315 |
> +# @DESCRIPTION: |
316 |
> +# Removes a specified dependency from a find_package call with multiple |
317 |
> components. |
318 |
> +ecm_punt_bogus_dep() { |
319 |
> + local prefix=${1} |
320 |
> + local dep=${2} |
321 |
> + |
322 |
> + if [[ ! -e "CMakeLists.txt" ]]; then |
323 |
|
324 |
Can this really ever happen in a valid use case? Maybe it should be |
325 |
an error instead. |
326 |
|
327 |
> + return |
328 |
> + fi |
329 |
> + |
330 |
> + pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}[^)]*?${dep}.*?\)" |
331 |
> CMakeLists.txt > "${T}/bogus${dep}" |
332 |
> + |
333 |
> + # pcregrep returns non-zero on no matches/error |
334 |
> + if [[ $? != 0 ]] ; then |
335 |
|
336 |
-ne |
337 |
|
338 |
> + return |
339 |
> + fi |
340 |
> + |
341 |
> + local length=$(wc -l "${T}/bogus${dep}" | cut -d " " -f 1) |
342 |
|
343 |
'wc -l < ...' and you won't have to cut. |
344 |
|
345 |
> + local first=$(head -n 1 "${T}/bogus${dep}" | cut -d ":" -f 1) |
346 |
> + local last=$(( ${length} + ${first} - 1)) |
347 |
|
348 |
$(( length + first - 1 )) |
349 |
|
350 |
> + |
351 |
> + sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die |
352 |
> + |
353 |
> + if [[ ${length} = 1 ]] ; then |
354 |
|
355 |
-eq |
356 |
|
357 |
> + sed -e "/find_package\s*(\s*${prefix}\(\s\+\(REQUIRED\|CONFIG\| |
358 |
> COMPONENTS\|\${[A-Z0-9_]*}\)\)\+\s*)/Is/^/# removed by kde5-functions.eclass - |
359 |
> /" -i CMakeLists.txt || die |
360 |
> + fi |
361 |
> +} |
362 |
> + |
363 |
> +# @FUNCTION: ecm-utils_pkg_pretend |
364 |
> +# @DESCRIPTION: |
365 |
> +# Checks if the active compiler meets the minimum version requirements. |
366 |
> +# phase function is only exported if KDE_GCC_MINIMAL is defined. |
367 |
> +ecm-utils_pkg_pretend() { |
368 |
> + debug-print-function ${FUNCNAME} "$@" |
369 |
> + _check_gcc_version |
370 |
> +} |
371 |
> + |
372 |
> +# @FUNCTION: ecm-utils_pkg_setup |
373 |
> +# @DESCRIPTION: |
374 |
> +# Checks if the active compiler meets the minimum version requirements. |
375 |
> +ecm-utils_pkg_setup() { |
376 |
> + debug-print-function ${FUNCNAME} "$@" |
377 |
> + _check_gcc_version |
378 |
> +} |
379 |
> + |
380 |
> +# @FUNCTION: ecm-utils_src_prepare |
381 |
> +# @DESCRIPTION: |
382 |
> +# Wrapper for cmake-utils_src_prepare with lots of extra logic for magic |
383 |
> +# handling of linguas, tests, handbook etc. |
384 |
> +ecm-utils_src_prepare() { |
385 |
> + debug-print-function ${FUNCNAME} "$@" |
386 |
> + |
387 |
> + cmake-utils_src_prepare |
388 |
> + |
389 |
> + # only build examples when required |
390 |
> + if ! { in_iuse examples && use examples; } ; then |
391 |
> + cmake_comment_add_subdirectory examples |
392 |
> + fi |
393 |
> + |
394 |
> + # only enable handbook when required |
395 |
> + if in_iuse handbook && ! use handbook ; then |
396 |
> + cmake_comment_add_subdirectory ${ECM_HANDBOOK_DIR} |
397 |
> + |
398 |
> + if [[ ${ECM_HANDBOOK} = forceoptional ]] ; then |
399 |
> + punt_bogus_dep KF5 DocTools |
400 |
> + sed -i -e "/kdoctools_install/ s/^/#DONT/" CMakeLists.txt || |
401 |
> die |
402 |
> + fi |
403 |
> + fi |
404 |
> + |
405 |
> + # drop translations when nls is not wanted |
406 |
> + if in_iuse nls && ! use nls ; then |
407 |
> + local po |
408 |
> + for po in ${ECM_PO_DIRS}; do |
409 |
> + if [[ -d ${po} ]] ; then |
410 |
|
411 |
Do you have a valid case for ${po} not being a directory? If not, |
412 |
I think the whole thing could be simplified to: |
413 |
|
414 |
rm -rf ${ECM_PO_DIRS} |
415 |
|
416 |
> + rm -r ${po} || die |
417 |
> + fi |
418 |
> + done |
419 |
> + fi |
420 |
> + |
421 |
> + # enable only the requested translations when required |
422 |
> + # always install unconditionally for kconfigwidgets - if you use |
423 |
> language |
424 |
> + # X as system language, and there is a combobox with language names, the |
425 |
> + # translated language name for language Y is taken from |
426 |
> + # /usr/share/locale/Y/kf5_entry.desktop |
427 |
> + if [[ -v LINGUAS && ${PN} != kconfigwidgets ]] ; then |
428 |
> + local po |
429 |
> + for po in ${ECM_PO_DIRS}; do |
430 |
> + if [[ -d ${po} ]] ; then |
431 |
|
432 |
Missing indent? |
433 |
|
434 |
> + pushd ${po} > /dev/null || die |
435 |
> + local lang |
436 |
> + for lang in *; do |
437 |
> + if [[ -e ${lang} ]] && ! has ${lang/.po/} ${LINGUAS} ; |
438 |
> then |
439 |
> + case ${lang} in |
440 |
> + cmake_modules | \ |
441 |
> + CMakeLists.txt | \ |
442 |
> + ${PN}.pot) ;; |
443 |
> + *) rm -r ${lang} || die ;; |
444 |
> + esac |
445 |
> + if [[ -e CMakeLists.txt ]] ; then |
446 |
> + cmake_comment_add_subdirectory ${lang} |
447 |
> + sed -e "/add_subdirectory([[:space:]]*$ |
448 |
> {lang}\/.*[[:space:]]*)/d" \ |
449 |
> + -i CMakeLists.txt || die |
450 |
> + fi |
451 |
> + fi |
452 |
> + done |
453 |
> + popd > /dev/null || die |
454 |
> + fi |
455 |
> + done |
456 |
> + fi |
457 |
> + |
458 |
|
459 |
Overall, I find this whole thing disgusting and fragile but up to you. |
460 |
|
461 |
> |
462 |
|
463 |
-- |
464 |
Best regards, |
465 |
Michał Górny |