Skip to content

Commit

Permalink
install-qa-check.d: migrate xdg-utils checks over from preinst/postin…
Browse files Browse the repository at this point in the history
…st to ${D}

It's practically criminal to run these at merge time instead of src_install
time. It disproportionately affects binpkg consumers, because it applies
to the entirety of ROOT. We actually don't want to do... basically any
of this. It's not even accurate because we are heavily reliant on mtime
of installed files to check whether the commands were actually run.

What we actually want to do is significantly simpler: every package that
installs specific files to ${D} has to also inherit an eclass and run a
function in pkg_postinst. We can check for inherits quite trivially, and
warn about those. We can also slightly less efficiently check the
contents of pkg_* functions to see if they make certain calls; bash can
print the function contents and we can grep for that.

It doesn't catch cases where a custom eclass runs the xdg functions, but
we manually include those in our matching.

Signed-off-by: Eli Schwartz <[email protected]>
  • Loading branch information
eli-schwartz committed Aug 3, 2024
1 parent a28a0fd commit e6965c9
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 157 deletions.
107 changes: 107 additions & 0 deletions bin/install-qa-check.d/50xdg-utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Check for missing calls to xdg-utils regen functions

xdg_desktop_database_check() {
local d f all_files=() missing
for d in usr/share/applications; do
[[ -d ${d} ]] || continue

# Look for any .desktop files that have any mime types defined
while read -r -d $'\0' f; do
all_files+=( "${f}" )
done < <(find "${d}" -name '*.desktop' \
-exec grep -lZi '^MimeType=' {} +)
done

if [[ -z ${all_files[@]} ]]; then
:
elif ! has xdg-utils ${INHERITED}; then
missing='xdg-utils was not inherited'
elif ! declare -f pkg_postinst | grep -q -E '(xdg_desktop_database_update|(ecm|gnome|java-vm-2|xdg)_pkg_postinst)'; then
missing='xdg-utils was not used'
elif ! declare -f pkg_postrm | grep -q -E '(xdg_desktop_database_update|(ecm|gnome|java-vm-2|xdg)_pkg_postrm)'; then
missing='xdg-utils was not used'
fi

if [[ ${missing} && ${all_files[@]} ]]; then
eqawarn "QA Notice: .desktop files with MimeType= were found installed"
eqawarn "but ${missing}:"
eqatag -v xdg-utils.desktop "${all_files[@]/#//}"
eqawarn "Please make sure to call xdg_desktop_database_update()"
eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
fi
}

xdg_icon_cache_check() {
local d f all_files=() missing
for d in usr/share/icons/*/; do
local find_args=(
# gtk-update-icon-cache supports only specific file
# suffixes; match that to avoid false positives
'(' -name '*.png' -o -name '*.svg'
-o -name '*.xpm' -o -name '*.icon' ')'
)

# (use -mindepth 2 to easily skip the cache files)
while read -r -d $'\0' f; do
all_files+=( "${f}" )
done < <(find "${d}" -mindepth 2 -type f "${find_args[@]}" -print0)
done

if [[ -z ${all_files[@]} ]]; then
:
elif ! has xdg-utils ${INHERITED}; then
missing='xdg-utils was not inherited'
elif ! declare -f pkg_postinst | grep -q -E '(xdg_icon_cache_update|(ecm|gnome|xdg)_pkg_postinst)'; then
missing='xdg-utils was not used'
elif ! declare -f pkg_postrm | grep -q -E '(xdg_icon_cache_update|(ecm|gnome|xdg)_pkg_postrm)'; then
missing='xdg-utils was not used'
fi

if [[ ${missing} ]]; then
eqawarn "QA Notice: new icons were found installed but ${missing}:"
eqatag -v xdg-utils.icon-cache "${all_files[@]/#//}"
eqawarn "Please make sure to call xdg_icon_cache_update()"
eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
fi
}

xdg_mimeinfo_database_check() {
local d f all_files=() missing
for d in usr/share/mime; do
[[ -d ${d} ]] || continue

while read -r -d $'\0' f; do
all_files+=( "${f}" )
done < <(find "${d}" -name '*.xml' -print0)
done

if [[ -z ${all_files[@]} ]]; then
:
elif ! has xdg-utils ${INHERITED}; then
missing='xdg-utils was not inherited'
elif ! declare -f pkg_postinst | grep -q -E '(xdg_mimeinfo_database_update|(ecm|gnome|xdg)_pkg_postinst)'; then
missing='xdg-utils was not used'
elif ! declare -f pkg_postrm | grep -q -E '(xdg_mimeinfo_database_update|(ecm|gnome|xdg)_pkg_postrm)'; then
missing='xdg-utils was not used'
fi

if [[ ${missing} && ${all_files[@]} ]]; then
eqawarn "QA Notice: mime-info files were found installed but"
eqawarn "${missing}:"
eqatag -v xdg-utils.mime-info "${all_files[@]/#//}"
eqawarn "Please make sure to call xdg_mimeinfo_database_update()"
eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
fi
}

xdg_utils_postinst_check() {
cd "${D}" || die
xdg_desktop_database_check
xdg_icon_cache_check
xdg_mimeinfo_database_check
}

xdg_utils_postinst_check
: # guarantee successful exit

# vim:ft=sh
156 changes: 0 additions & 156 deletions bin/postinst-qa-check.d/50xdg-utils

This file was deleted.

1 change: 0 additions & 1 deletion bin/preinst-qa-check.d/50xdg-utils

This file was deleted.

0 comments on commit e6965c9

Please sign in to comment.