kde5.eclass: introduce forceoptional value for KDE_TEST
[gentoo.git] / eclass / kde5.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: kde5.eclass
6 # @MAINTAINER:
7 # kde@gentoo.org
8 # @BLURB: Support eclass for KDE 5-related packages.
9 # @DESCRIPTION:
10 # The kde5.eclass provides support for building KDE 5-related packages.
11
12 if [[ -z ${_KDE5_ECLASS} ]]; then
13 _KDE5_ECLASS=1
14
15 # @ECLASS-VARIABLE: VIRTUALX_REQUIRED
16 # @DESCRIPTION:
17 # For proper description see virtualx.eclass manpage.
18 # Here we redefine default value to be manual, if your package needs virtualx
19 # for tests you should proceed with setting VIRTUALX_REQUIRED=test.
20 : ${VIRTUALX_REQUIRED:=manual}
21
22 inherit kde5-functions fdo-mime flag-o-matic gnome2-utils versionator virtualx eutils cmake-utils
23
24 if [[ ${KDE_BUILD_TYPE} = live ]]; then
25         case ${KDE_SCM} in
26                 svn) inherit subversion ;;
27                 git) inherit git-r3 ;;
28         esac
29 fi
30
31 EXPORT_FUNCTIONS pkg_pretend pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install pkg_preinst pkg_postinst pkg_postrm
32
33 # @ECLASS-VARIABLE: QT_MINIMAL
34 # @DESCRIPTION:
35 # Minimal Qt version to require for the package.
36 : ${QT_MINIMAL:=5.4.2}
37
38 # @ECLASS-VARIABLE: KDE_AUTODEPS
39 # @DESCRIPTION:
40 # If set to "false", do nothing.
41 # For any other value, add a dependency on dev-qt/qtcore:5 and kde-frameworks/extra-cmake-modules:5.
42 : ${KDE_AUTODEPS:=true}
43
44 # @ECLASS-VARIABLE: KDE_BLOCK_SLOT4
45 # @DESCRIPTION:
46 # This variable is used when KDE_AUTODEPS is set.
47 # If set to "true", add RDEPEND block on kde-{base,apps}/${PN}:4
48 : ${KDE_BLOCK_SLOT4:=true}
49
50 # @ECLASS-VARIABLE: KDE_DEBUG
51 # @DESCRIPTION:
52 # If set to "false", unconditionally build with -DNDEBUG.
53 # Otherwise, add debug to IUSE to control building with that flag.
54 : ${KDE_DEBUG:=true}
55
56 # @ECLASS-VARIABLE: KDE_DOXYGEN
57 # @DESCRIPTION:
58 # If set to "false", do nothing.
59 # Otherwise, add "doc" to IUSE, add appropriate dependencies, and generate and
60 # install API documentation.
61 if [[ ${CATEGORY} = kde-frameworks ]]; then
62         : ${KDE_DOXYGEN:=true}
63 else
64         : ${KDE_DOXYGEN:=false}
65 fi
66
67 # @ECLASS-VARIABLE: KDE_DOX_DIR
68 # @DESCRIPTION:
69 # Defaults to ".". Otherwise, use alternative KDE doxygen path.
70 : ${KDE_DOX_DIR:=.}
71
72 # @ECLASS-VARIABLE: KDE_EXAMPLES
73 # @DESCRIPTION:
74 # If set to "false", unconditionally ignore a top-level examples subdirectory.
75 # Otherwise, add "examples" to IUSE to toggle adding that subdirectory.
76 : ${KDE_EXAMPLES:=false}
77
78 # @ECLASS-VARIABLE: KDE_HANDBOOK
79 # @DESCRIPTION:
80 # If set to "false", do nothing.
81 # Otherwise, add "+handbook" to IUSE, add the appropriate dependency, and
82 # generate and install KDE handbook.
83 # If set to "forceoptional", remove a KF5DocTools dependency from the root
84 # CMakeLists.txt in addition to the above.
85 : ${KDE_HANDBOOK:=false}
86
87 # @ECLASS-VARIABLE: KDE_DOC_DIR
88 # @DESCRIPTION:
89 # Defaults to "doc". Otherwise, use alternative KDE handbook path.
90 : ${KDE_DOC_DIR:=doc}
91
92 # @ECLASS-VARIABLE: KDE_TEST
93 # @DESCRIPTION:
94 # If set to "false", do nothing.
95 # For any other value, add test to IUSE and add a dependency on dev-qt/qttest:5.
96 # If set to "forceoptional", remove a Qt5Test dependency from the root
97 # CMakeLists.txt in addition to the above.
98 if [[ ${CATEGORY} = kde-frameworks ]]; then
99         : ${KDE_TEST:=true}
100 else
101         : ${KDE_TEST:=false}
102 fi
103
104 # @ECLASS-VARIABLE: KDE_PUNT_BOGUS_DEPS
105 # @DESCRIPTION:
106 # If set to "false", do nothing.
107 # For any other value, do black magic to make hardcoded-but-optional dependencies
108 # optional again. An upstream solution is preferable and this is a last resort.
109 : ${KDE_PUNT_BOGUS_DEPS:=false}
110
111 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
112 # @DESCRIPTION:
113 # If set to "none", do nothing.
114 # For any other value, add selinux to IUSE, and depending on that useflag
115 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
116 : ${KDE_SELINUX_MODULE:=none}
117
118 if [[ ${KDEBASE} = kdevelop ]]; then
119         HOMEPAGE="https://www.kdevelop.org/"
120 else
121         HOMEPAGE="https://www.kde.org/"
122 fi
123
124 LICENSE="GPL-2"
125
126 if [[ ${CATEGORY} = kde-frameworks ]]; then
127         SLOT=5/$(get_version_component_range 1-2)
128 else
129         SLOT=5
130 fi
131
132 case ${KDE_AUTODEPS} in
133         false)  ;;
134         *)
135                 if [[ ${KDE_BUILD_TYPE} = live ]]; then
136                         case ${CATEGORY} in
137                                 kde-frameworks)
138                                         FRAMEWORKS_MINIMAL=9999
139                                 ;;
140                                 kde-plasma)
141                                         FRAMEWORKS_MINIMAL=9999
142                                 ;;
143                                 *) ;;
144                         esac
145                 fi
146
147                 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
148                 RDEPEND+=" >=kde-frameworks/kf-env-3"
149                 COMMONDEPEND+=" >=dev-qt/qtcore-${QT_MINIMAL}:5"
150
151                 if [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma && ${PN} != polkit-kde-agent ]]; then
152                         RDEPEND+="
153                                 !kde-apps/kde4-l10n[-minimal(-)]
154                                 !<kde-apps/kde4-l10n-15.08.0-r1
155                         "
156                 fi
157
158                 if [[ ${KDE_BLOCK_SLOT4} = true && ${CATEGORY} = kde-apps ]]; then
159                         RDEPEND+=" !kde-apps/${PN}:4"
160                 fi
161                 ;;
162 esac
163
164 case ${KDE_DOXYGEN} in
165         false)  ;;
166         *)
167                 IUSE+=" doc"
168                 DEPEND+=" doc? (
169                                 $(add_frameworks_dep kapidox)
170                                 app-doc/doxygen
171                         )"
172                 ;;
173 esac
174
175 case ${KDE_DEBUG} in
176         false)  ;;
177         *)
178                 IUSE+=" debug"
179                 ;;
180 esac
181
182 case ${KDE_EXAMPLES} in
183         false)  ;;
184         *)
185                 IUSE+=" examples"
186                 ;;
187 esac
188
189 case ${KDE_HANDBOOK} in
190         false)  ;;
191         *)
192                 IUSE+=" +handbook"
193                 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
194                 ;;
195 esac
196
197 case ${KDE_TEST} in
198         false)  ;;
199         *)
200                 IUSE+=" test"
201                 DEPEND+=" test? ( >=dev-qt/qttest-${QT_MINIMAL}:5 )"
202                 ;;
203 esac
204
205 case ${KDE_SELINUX_MODULE} in
206         none)   ;;
207         *)
208                 IUSE+=" selinux"
209                 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
210                 ;;
211 esac
212
213 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
214 RDEPEND+=" ${COMMONDEPEND}"
215 unset COMMONDEPEND
216
217 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
218         S=${WORKDIR}/${KMNAME}-${PV}
219 fi
220
221 # Determine fetch location for released tarballs
222 _calculate_src_uri() {
223         debug-print-function ${FUNCNAME} "$@"
224
225         local _kmname
226
227         if [[ -n ${KMNAME} ]]; then
228                 _kmname=${KMNAME}
229         else
230                 _kmname=${PN}
231         fi
232
233         case ${PN} in
234                 kdelibs4support | \
235                 khtml | \
236                 kjs | \
237                 kjsembed | \
238                 kmediaplayer | \
239                 kross | \
240                 krunner)
241                         _kmname="portingAids/${_kmname}"
242                         ;;
243         esac
244
245         DEPEND+=" app-arch/xz-utils"
246
247         case ${CATEGORY} in
248                 kde-apps)
249                         case ${PV} in
250                                 ??.?.[6-9]? | ??.??.[6-9]? )
251                                         SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
252                                         RESTRICT+=" mirror"
253                                         ;;
254                                 *)
255                                         SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
256                         esac
257                         ;;
258                 kde-frameworks)
259                         SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
260                 kde-plasma)
261                         case ${PV} in
262                                 5.?.[6-9]? )
263                                         # Plasma 5 beta releases
264                                         SRC_URI="mirror://kde/unstable/plasma/${PV}/${_kmname}-${PV}.tar.xz"
265                                         RESTRICT+=" mirror"
266                                         ;;
267                                 *)
268                                         # Plasma 5 stable releases
269                                         SRC_URI="mirror://kde/stable/plasma/${PV}/${_kmname}-${PV}.tar.xz" ;;
270                         esac
271                         ;;
272         esac
273 }
274
275 # Determine fetch location for live sources
276 _calculate_live_repo() {
277         debug-print-function ${FUNCNAME} "$@"
278
279         SRC_URI=""
280
281         case ${KDE_SCM} in
282                 svn)
283                         # @ECLASS-VARIABLE: ESVN_MIRROR
284                         # @DESCRIPTION:
285                         # This variable allows easy overriding of default kde mirror service
286                         # (anonsvn) with anything else you might want to use.
287                         ESVN_MIRROR=${ESVN_MIRROR:=svn://anonsvn.kde.org/home/kde}
288
289                         local branch_prefix="trunk/KDE"
290
291                         if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
292                                 branch_prefix="branches/Applications/$(get_version_component_range 1-2)"
293                         fi
294
295                         if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
296                                 branch_prefix="branches/plasma/$(get_version_component_range 1-2)"
297                         fi
298
299                         local _kmname
300
301                         if [[ -n ${KMNAME} ]]; then
302                                 _kmname=${KMNAME}
303                         else
304                                 _kmname=${PN}
305                         fi
306
307                         ESVN_REPO_URI="${ESVN_MIRROR}/${branch_prefix}/${_kmname}"
308                         ;;
309                 git)
310                         # @ECLASS-VARIABLE: EGIT_MIRROR
311                         # @DESCRIPTION:
312                         # This variable allows easy overriding of default kde mirror service
313                         # (anongit) with anything else you might want to use.
314                         EGIT_MIRROR=${EGIT_MIRROR:=git://anongit.kde.org}
315
316                         local _kmname
317
318                         # @ECLASS-VARIABLE: EGIT_REPONAME
319                         # @DESCRIPTION:
320                         # This variable allows overriding of default repository
321                         # name. Specify only if this differ from PN and KMNAME.
322                         if [[ -n ${EGIT_REPONAME} ]]; then
323                                 # the repository and kmname different
324                                 _kmname=${EGIT_REPONAME}
325                         elif [[ -n ${KMNAME} ]]; then
326                                 _kmname=${KMNAME}
327                         else
328                                 _kmname=${PN}
329                         fi
330
331                         if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
332                                 EGIT_BRANCH="Applications/$(get_version_component_range 1-2)"
333                         fi
334
335                         if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
336                                 EGIT_BRANCH="Plasma/$(get_version_component_range 1-2)"
337                         fi
338
339                         EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
340                         ;;
341         esac
342 }
343
344 case ${KDE_BUILD_TYPE} in
345         live) _calculate_live_repo ;;
346         *) _calculate_src_uri ;;
347 esac
348
349 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
350
351 # @FUNCTION: kde5_pkg_pretend
352 # @DESCRIPTION:
353 # Do some basic settings
354 kde5_pkg_pretend() {
355         debug-print-function ${FUNCNAME} "$@"
356         if [[ ${MERGE_TYPE} != binary ]]; then
357                 _check_gcc_version
358         fi
359 }
360
361 # @FUNCTION: kde5_pkg_setup
362 # @DESCRIPTION:
363 # Do some basic settings
364 kde5_pkg_setup() {
365         debug-print-function ${FUNCNAME} "$@"
366         if [[ ${MERGE_TYPE} != binary ]]; then
367                 _check_gcc_version
368         fi
369 }
370
371 # @FUNCTION: kde5_src_unpack
372 # @DESCRIPTION:
373 # Function for unpacking KDE 5.
374 kde5_src_unpack() {
375         debug-print-function ${FUNCNAME} "$@"
376
377         if [[ ${KDE_BUILD_TYPE} = live ]]; then
378                 case ${KDE_SCM} in
379                         svn)
380                                 subversion_src_unpack
381                                 ;;
382                         git)
383                                 git-r3_src_unpack
384                                 ;;
385                 esac
386         else
387                 default
388         fi
389 }
390
391 # @FUNCTION: kde5_src_prepare
392 # @DESCRIPTION:
393 # Function for preparing the KDE 5 sources.
394 kde5_src_prepare() {
395         debug-print-function ${FUNCNAME} "$@"
396
397         # only build examples when required
398         if ! use_if_iuse examples || ! use examples ; then
399                 comment_add_subdirectory examples
400         fi
401
402         # only enable handbook when required
403         if ! use_if_iuse handbook ; then
404                 comment_add_subdirectory ${KDE_DOC_DIR}
405         fi
406
407         # enable only the requested translations
408         # when required
409         if [[ ${KDE_BUILD_TYPE} = release ]] ; then
410                 if [[ -d po ]] ; then
411                         pushd po > /dev/null || die
412                         for lang in *; do
413                                 if ! has ${lang} ${LINGUAS} ; then
414                                         if [[ ${lang} != CMakeLists.txt ]] ; then
415                                                 rm -rf ${lang}
416                                         fi
417                                         if [[ -e CMakeLists.txt ]] ; then
418                                                 comment_add_subdirectory ${lang}
419                                         fi
420                                 fi
421                         done
422                         popd > /dev/null || die
423                 fi
424
425                 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && ${CATEGORY} != kde-apps ]] ; then
426                         pushd ${KDE_DOC_DIR} > /dev/null || die
427                         for lang in *; do
428                                 if ! has ${lang} ${LINGUAS} ; then
429                                         comment_add_subdirectory ${lang}
430                                 fi
431                         done
432                         popd > /dev/null || die
433                 fi
434         else
435                 rm -rf po
436         fi
437
438         # in frameworks, tests = manual tests so never
439         # build them
440         if [[ ${CATEGORY} = kde-frameworks ]]; then
441                 comment_add_subdirectory tests
442         fi
443
444         if [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
445                 # only build unit tests when required
446                 if ! use_if_iuse test ; then
447                         comment_add_subdirectory autotests
448                         comment_add_subdirectory test
449                         comment_add_subdirectory tests
450                 fi
451         fi
452
453         case ${KDE_PUNT_BOGUS_DEPS} in
454                 false)  ;;
455                 *)
456                         if ! use_if_iuse test ; then
457                                 punt_bogus_dep Qt5 Test
458                         fi
459                         if ! use_if_iuse handbook ; then
460                                 punt_bogus_dep KF5 DocTools
461                         fi
462                         ;;
463         esac
464
465         if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
466                 if ! use_if_iuse handbook ; then
467                         punt_bogus_dep KF5 DocTools
468                 fi
469         fi
470
471         if [[ ${KDE_TEST} = forceoptional ]] ; then
472                 if ! use_if_iuse test ; then
473                         punt_bogus_dep Qt5 Test
474                 fi
475         fi
476
477         cmake-utils_src_prepare
478 }
479
480 # @FUNCTION: kde5_src_configure
481 # @DESCRIPTION:
482 # Function for configuring the build of KDE 5.
483 kde5_src_configure() {
484         debug-print-function ${FUNCNAME} "$@"
485
486         # we rely on cmake-utils.eclass to append -DNDEBUG too
487         if ! use_if_iuse debug; then
488                 append-cppflags -DQT_NO_DEBUG
489         fi
490
491         local cmakeargs
492
493         if ! use_if_iuse test ; then
494                 cmakeargs+=( -DBUILD_TESTING=OFF )
495         fi
496
497         # install mkspecs in the same directory as qt stuff
498         cmakeargs+=(-DKDE_INSTALL_USE_QT_SYS_PATHS=ON)
499
500         # allow the ebuild to override what we set here
501         mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
502
503         cmake-utils_src_configure
504 }
505
506 # @FUNCTION: kde5_src_compile
507 # @DESCRIPTION:
508 # Function for compiling KDE 5.
509 kde5_src_compile() {
510         debug-print-function ${FUNCNAME} "$@"
511
512         cmake-utils_src_compile "$@"
513
514         # Build doxygen documentation if applicable
515         if use_if_iuse doc ; then
516                 kgenapidox ${KDE_DOX_DIR} || die
517         fi
518 }
519
520 # @FUNCTION: kde5_src_test
521 # @DESCRIPTION:
522 # Function for testing KDE 5.
523 kde5_src_test() {
524         debug-print-function ${FUNCNAME} "$@"
525
526         _test_runner() {
527                 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
528                         export $(dbus-launch)
529                 fi
530
531                 cmake-utils_src_test
532         }
533
534         # When run as normal user during ebuild development with the ebuild command, the
535         # kde tests tend to access the session DBUS. This however is not possible in a real
536         # emerge or on the tinderbox.
537         # > make sure it does not happen, so bad tests can be recognized and disabled
538         unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
539
540         if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
541                 VIRTUALX_COMMAND="_test_runner" virtualmake
542         else
543                 _test_runner
544         fi
545
546         if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
547                 kill ${DBUS_SESSION_BUS_PID}
548         fi
549 }
550
551 # @FUNCTION: kde5_src_install
552 # @DESCRIPTION:
553 # Function for installing KDE 5.
554 kde5_src_install() {
555         debug-print-function ${FUNCNAME} "$@"
556
557         # Install doxygen documentation if applicable
558         if use_if_iuse doc ; then
559                 dodoc -r apidocs/html
560         fi
561
562         cmake-utils_src_install
563
564         # We don't want ${PREFIX}/share/doc/HTML to be compressed,
565         # because then khelpcenter can't find the docs
566         if [[ -d ${ED}/${PREFIX}/share/doc/HTML ]]; then
567                 docompress -x ${PREFIX}/share/doc/HTML
568         fi
569 }
570
571 # @FUNCTION: kde5_pkg_preinst
572 # @DESCRIPTION:
573 # Function storing icon caches
574 kde5_pkg_preinst() {
575         debug-print-function ${FUNCNAME} "$@"
576
577         gnome2_icon_savelist
578 }
579
580 # @FUNCTION: kde5_pkg_postinst
581 # @DESCRIPTION:
582 # Function to rebuild the KDE System Configuration Cache after an application has been installed.
583 kde5_pkg_postinst() {
584         debug-print-function ${FUNCNAME} "$@"
585
586         gnome2_icon_cache_update
587         fdo-mime_desktop_database_update
588 }
589
590 # @FUNCTION: kde5_pkg_postrm
591 # @DESCRIPTION:
592 # Function to rebuild the KDE System Configuration Cache after an application has been removed.
593 kde5_pkg_postrm() {
594         debug-print-function ${FUNCNAME} "$@"
595
596         gnome2_icon_cache_update
597         fdo-mime_desktop_database_update
598 }
599
600 fi