1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: xdg-utils.eclass
8 # Original author: Gilles Dartiguelongue <eva@gentoo.org>
9 # @BLURB: Auxiliary functions commonly used by XDG compliant packages.
11 # This eclass provides a set of auxiliary functions needed by most XDG
13 # It provides XDG stack related functions such as:
14 # * XDG .desktop files cache management
15 # * XDG mime information database management
19 *) die "EAPI=${EAPI} is not supported" ;;
22 # @ECLASS-VARIABLE: DESKTOP_DATABASE_UPDATE_BIN
25 # Path to update-desktop-database
26 : ${DESKTOP_DATABASE_UPDATE_BIN:="/usr/bin/update-desktop-database"}
28 # @ECLASS-VARIABLE: DESKTOP_DATABASE_DIR
31 # Directory where .desktop files database is stored
32 : ${DESKTOP_DATABASE_DIR="/usr/share/applications"}
34 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_UPDATE_BIN
37 # Path to update-mime-database
38 : ${MIMEINFO_DATABASE_UPDATE_BIN:="/usr/bin/update-mime-database"}
40 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_DIR
43 # Directory where .desktop files database is stored
44 : ${MIMEINFO_DATABASE_DIR:="/usr/share/mime"}
46 # @FUNCTION: xdg_environment_reset
48 # Clean up environment for clean builds.
49 xdg_environment_reset() {
50 # Prepare XDG base directories
51 export XDG_DATA_HOME="${HOME}/.local/share"
52 export XDG_CONFIG_HOME="${HOME}/.config"
53 export XDG_CACHE_HOME="${HOME}/.cache"
54 export XDG_RUNTIME_DIR="${T}/run"
55 mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
56 "${XDG_RUNTIME_DIR}" || die
57 # This directory needs to be owned by the user, and chmod 0700
58 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
59 chmod 0700 "${XDG_RUNTIME_DIR}" || die
61 unset DBUS_SESSION_BUS_ADDRESS
64 # @FUNCTION: fdo-xdg_desktop_database_update
66 # Updates the .desktop files database.
67 # Generates a list of mimetypes linked to applications that can handle them
68 xdg_desktop_database_update() {
69 local updater="${EROOT}${DESKTOP_DATABASE_UPDATE_BIN}"
71 if [[ ${EBUILD_PHASE} != post* ]] ; then
72 die "xdg_desktop_database_update must be used in pkg_post* phases."
75 if [[ ! -x "${updater}" ]] ; then
76 debug-print "${updater} is not executable"
80 ebegin "Updating .desktop files database"
81 "${updater}" -q "${EROOT}${DESKTOP_DATABASE_DIR}"
85 # @FUNCTION: xdg_mimeinfo_database_update
87 # Update the mime database.
88 # Creates a general list of mime types from several sources
89 xdg_mimeinfo_database_update() {
90 local updater="${EROOT}${MIMEINFO_DATABASE_UPDATE_BIN}"
92 if [[ ${EBUILD_PHASE} != post* ]] ; then
93 die "xdg_mimeinfo_database_update must be used in pkg_post* phases."
96 if [[ ! -x "${updater}" ]] ; then
97 debug-print "${updater} is not executable"
101 ebegin "Updating shared mime info database"
102 "${updater}" "${EROOT}${MIMEINFO_DATABASE_DIR}"