1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: xdg-utils.eclass
9 # Original author: Gilles Dartiguelongue <eva@gentoo.org>
10 # @BLURB: Auxiliary functions commonly used by XDG compliant packages.
12 # This eclass provides a set of auxiliary functions needed by most XDG
14 # It provides XDG stack related functions such as:
15 # * XDG .desktop files cache management
16 # * XDG mime information database management
20 *) die "EAPI=${EAPI} is not supported" ;;
23 # @ECLASS-VARIABLE: DESKTOP_DATABASE_UPDATE_BIN
26 # Path to update-desktop-database
27 : ${DESKTOP_DATABASE_UPDATE_BIN:="/usr/bin/update-desktop-database"}
29 # @ECLASS-VARIABLE: DESKTOP_DATABASE_DIR
32 # Directory where .desktop files database is stored
33 : ${DESKTOP_DATABASE_DIR="/usr/share/applications"}
35 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_UPDATE_BIN
38 # Path to update-desktop-database
39 : ${MIMEINFO_DATABASE_UPDATE_BIN:="/usr/bin/update-mime-database"}
41 # @ECLASS-VARIABLE: MIMEINFO_DATABASE_DIR
44 # Directory where .desktop files database is stored
45 : ${MIMEINFO_DATABASE_DIR:="/usr/share/mime"}
47 # @FUNCTION: xdg_environment_reset
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
62 unset DBUS_SESSION_BUS_ADDRESS
65 # @FUNCTION: fdo-xdg_desktop_database_update
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}"
72 if [[ ${EBUILD_PHASE} != post* ]] ; then
73 die "xdg_desktop_database_update must be used in pkg_post* phases."
76 if [[ ! -x "${updater}" ]] ; then
77 debug-print "${updater} is not executable"
81 ebegin "Updating .desktop files database"
82 "${updater}" -q "${EROOT}${DESKTOP_DATABASE_DIR}"
86 # @FUNCTION: xdg_mimeinfo_database_update
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}"
93 if [[ ${EBUILD_PHASE} != post* ]] ; then
94 die "xdg_mimeinfo_database_update must be used in pkg_post* phases."
97 if [[ ! -x "${updater}" ]] ; then
98 debug-print "${updater} is not executable"
102 ebegin "Updating shared mime info database"
103 "${updater}" "${EROOT}${MIMEINFO_DATABASE_DIR}"