perl-functions.eclass: should 'just work' in EAPI=6
[gentoo.git] / eclass / xdg-utils.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: xdg-utils.eclass
6 # @MAINTAINER:
7 # gnome@gentoo.org
8 # @AUTHOR:
9 # Original author: Gilles Dartiguelongue <eva@gentoo.org>
10 # @BLURB: Auxiliary functions commonly used by XDG compliant packages.
11 # @DESCRIPTION:
12 # This eclass provides a set of auxiliary functions needed by most XDG
13 # compliant packages.
14 # It provides XDG stack related functions such as:
15 #  * XDG .desktop files cache management
16 #  * XDG mime information database management
17
18 case "${EAPI:-0}" in
19         0|1|2|3|4|5|6) ;;
20         *) die "EAPI=${EAPI} is not supported" ;;
21 esac
22
23 # @ECLASS-VARIABLE: DESKTOP_DATABASE_UPDATE_BIN
24 # @INTERNAL
25 # @DESCRIPTION:
26 # Path to update-desktop-database
27 : ${DESKTOP_DATABASE_UPDATE_BIN:="/usr/bin/update-desktop-database"}
28
29 # @ECLASS-VARIABLE: DESKTOP_DATABASE_DIR
30 # @INTERNAL
31 # @DESCRIPTION:
32 # Directory where .desktop files database is stored
33 : ${DESKTOP_DATABASE_DIR="/usr/share/applications"}
34
35 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_UPDATE_BIN
36 # @INTERNAL
37 # @DESCRIPTION:
38 # Path to update-desktop-database
39 : ${MIMEINFO_DATABASE_UPDATE_BIN:="/usr/bin/update-mime-database"}
40
41 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_DIR
42 # @INTERNAL
43 # @DESCRIPTION:
44 # Directory where .desktop files database is stored
45 : ${MIMEINFO_DATABASE_DIR:="/usr/share/mime"}
46
47 # @FUNCTION: xdg_environment_reset
48 # @DESCRIPTION:
49 # Clean up environment for clean builds.
50 xdg_environment_reset() {
51         # Prepare XDG base directories
52         export XDG_DATA_HOME="${HOME}/.local/share"
53         export XDG_CONFIG_HOME="${HOME}/.config"
54         export XDG_CACHE_HOME="${HOME}/.cache"
55         export XDG_RUNTIME_DIR="${T}/run"
56         mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
57                 "${XDG_RUNTIME_DIR}" || die
58         # This directory needs to be owned by the user, and chmod 0700
59         # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
60         chmod 0700 "${XDG_RUNTIME_DIR}" || die
61
62         unset DBUS_SESSION_BUS_ADDRESS
63 }
64
65 # @FUNCTION: fdo-xdg_desktop_database_update
66 # @DESCRIPTION:
67 # Updates the .desktop files database.
68 # Generates a list of mimetypes linked to applications that can handle them
69 xdg_desktop_database_update() {
70         local updater="${EROOT}${DESKTOP_DATABASE_UPDATE_BIN}"
71
72         if [[ ${EBUILD_PHASE} != post* ]] ; then
73                 die "xdg_desktop_database_update must be used in pkg_post* phases."
74         fi
75
76         if [[ ! -x "${updater}" ]] ; then
77                 debug-print "${updater} is not executable"
78                 return
79         fi
80
81         ebegin "Updating .desktop files database"
82         "${updater}" -q "${EROOT}${DESKTOP_DATABASE_DIR}"
83         eend $?
84 }
85
86 # @FUNCTION: xdg_mimeinfo_database_update
87 # @DESCRIPTION:
88 # Update the mime database.
89 # Creates a general list of mime types from several sources
90 xdg_mimeinfo_database_update() {
91         local updater="${EROOT}${MIMEINFO_DATABASE_UPDATE_BIN}"
92
93         if [[ ${EBUILD_PHASE} != post* ]] ; then
94                 die "xdg_mimeinfo_database_update must be used in pkg_post* phases."
95         fi
96
97         if [[ ! -x "${updater}" ]] ; then
98                 debug-print "${updater} is not executable"
99                 return
100         fi
101
102         ebegin "Updating shared mime info database"
103         "${updater}" "${EROOT}${MIMEINFO_DATABASE_DIR}"
104         eend $?
105 }