Skip to content

Commit e6965c9

Browse files
committed
install-qa-check.d: migrate xdg-utils checks over from preinst/postinst 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]>
1 parent a28a0fd commit e6965c9

File tree

3 files changed

+107
-157
lines changed

3 files changed

+107
-157
lines changed

bin/install-qa-check.d/50xdg-utils

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Check for missing calls to xdg-utils regen functions
2+
3+
xdg_desktop_database_check() {
4+
local d f all_files=() missing
5+
for d in usr/share/applications; do
6+
[[ -d ${d} ]] || continue
7+
8+
# Look for any .desktop files that have any mime types defined
9+
while read -r -d $'\0' f; do
10+
all_files+=( "${f}" )
11+
done < <(find "${d}" -name '*.desktop' \
12+
-exec grep -lZi '^MimeType=' {} +)
13+
done
14+
15+
if [[ -z ${all_files[@]} ]]; then
16+
:
17+
elif ! has xdg-utils ${INHERITED}; then
18+
missing='xdg-utils was not inherited'
19+
elif ! declare -f pkg_postinst | grep -q -E '(xdg_desktop_database_update|(ecm|gnome|java-vm-2|xdg)_pkg_postinst)'; then
20+
missing='xdg-utils was not used'
21+
elif ! declare -f pkg_postrm | grep -q -E '(xdg_desktop_database_update|(ecm|gnome|java-vm-2|xdg)_pkg_postrm)'; then
22+
missing='xdg-utils was not used'
23+
fi
24+
25+
if [[ ${missing} && ${all_files[@]} ]]; then
26+
eqawarn "QA Notice: .desktop files with MimeType= were found installed"
27+
eqawarn "but ${missing}:"
28+
eqatag -v xdg-utils.desktop "${all_files[@]/#//}"
29+
eqawarn "Please make sure to call xdg_desktop_database_update()"
30+
eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
31+
fi
32+
}
33+
34+
xdg_icon_cache_check() {
35+
local d f all_files=() missing
36+
for d in usr/share/icons/*/; do
37+
local find_args=(
38+
# gtk-update-icon-cache supports only specific file
39+
# suffixes; match that to avoid false positives
40+
'(' -name '*.png' -o -name '*.svg'
41+
-o -name '*.xpm' -o -name '*.icon' ')'
42+
)
43+
44+
# (use -mindepth 2 to easily skip the cache files)
45+
while read -r -d $'\0' f; do
46+
all_files+=( "${f}" )
47+
done < <(find "${d}" -mindepth 2 -type f "${find_args[@]}" -print0)
48+
done
49+
50+
if [[ -z ${all_files[@]} ]]; then
51+
:
52+
elif ! has xdg-utils ${INHERITED}; then
53+
missing='xdg-utils was not inherited'
54+
elif ! declare -f pkg_postinst | grep -q -E '(xdg_icon_cache_update|(ecm|gnome|xdg)_pkg_postinst)'; then
55+
missing='xdg-utils was not used'
56+
elif ! declare -f pkg_postrm | grep -q -E '(xdg_icon_cache_update|(ecm|gnome|xdg)_pkg_postrm)'; then
57+
missing='xdg-utils was not used'
58+
fi
59+
60+
if [[ ${missing} ]]; then
61+
eqawarn "QA Notice: new icons were found installed but ${missing}:"
62+
eqatag -v xdg-utils.icon-cache "${all_files[@]/#//}"
63+
eqawarn "Please make sure to call xdg_icon_cache_update()"
64+
eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
65+
fi
66+
}
67+
68+
xdg_mimeinfo_database_check() {
69+
local d f all_files=() missing
70+
for d in usr/share/mime; do
71+
[[ -d ${d} ]] || continue
72+
73+
while read -r -d $'\0' f; do
74+
all_files+=( "${f}" )
75+
done < <(find "${d}" -name '*.xml' -print0)
76+
done
77+
78+
if [[ -z ${all_files[@]} ]]; then
79+
:
80+
elif ! has xdg-utils ${INHERITED}; then
81+
missing='xdg-utils was not inherited'
82+
elif ! declare -f pkg_postinst | grep -q -E '(xdg_mimeinfo_database_update|(ecm|gnome|xdg)_pkg_postinst)'; then
83+
missing='xdg-utils was not used'
84+
elif ! declare -f pkg_postrm | grep -q -E '(xdg_mimeinfo_database_update|(ecm|gnome|xdg)_pkg_postrm)'; then
85+
missing='xdg-utils was not used'
86+
fi
87+
88+
if [[ ${missing} && ${all_files[@]} ]]; then
89+
eqawarn "QA Notice: mime-info files were found installed but"
90+
eqawarn "${missing}:"
91+
eqatag -v xdg-utils.mime-info "${all_files[@]/#//}"
92+
eqawarn "Please make sure to call xdg_mimeinfo_database_update()"
93+
eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
94+
fi
95+
}
96+
97+
xdg_utils_postinst_check() {
98+
cd "${D}" || die
99+
xdg_desktop_database_check
100+
xdg_icon_cache_check
101+
xdg_mimeinfo_database_check
102+
}
103+
104+
xdg_utils_postinst_check
105+
: # guarantee successful exit
106+
107+
# vim:ft=sh

bin/postinst-qa-check.d/50xdg-utils

-156
This file was deleted.

bin/preinst-qa-check.d/50xdg-utils

-1
This file was deleted.

0 commit comments

Comments
 (0)