diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-10 14:35:29 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-12 15:27:17 +0100 |
commit | fd1517e2b51a170f2427122c6b95396db251d827 (patch) | |
tree | dabfe3e631339c2fc99a9ee7febb0f9c128e325e /meta/classes-recipe/mime-xdg.bbclass | |
parent | 10317912ee319ccf7f83605d438b5cbf9663f296 (diff) | |
download | poky-fd1517e2b51a170f2427122c6b95396db251d827.tar.gz |
classes: Update classes to match new bitbake class scope functionality
Move classes to classes-global or classes-recipe as appropriate to take
advantage of new bitbake functionality to check class scope/usage.
(From OE-Core rev: f5c128008365e141082c129417eb72d2751e8045)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/mime-xdg.bbclass')
-rw-r--r-- | meta/classes-recipe/mime-xdg.bbclass | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/meta/classes-recipe/mime-xdg.bbclass b/meta/classes-recipe/mime-xdg.bbclass new file mode 100644 index 0000000000..cbdcb4c7e9 --- /dev/null +++ b/meta/classes-recipe/mime-xdg.bbclass | |||
@@ -0,0 +1,78 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | # This class creates mime <-> application associations based on entry | ||
7 | # 'MimeType' in *.desktop files | ||
8 | # | ||
9 | |||
10 | DEPENDS += "desktop-file-utils" | ||
11 | PACKAGE_WRITE_DEPS += "desktop-file-utils-native" | ||
12 | DESKTOPDIR = "${datadir}/applications" | ||
13 | |||
14 | # There are recipes out there installing their .desktop files as absolute | ||
15 | # symlinks. For us these are dangling and cannot be introspected for "MimeType" | ||
16 | # easily. By addding package-names to MIME_XDG_PACKAGES, packager can force | ||
17 | # proper update-desktop-database handling. Note that all introspection is | ||
18 | # skipped for MIME_XDG_PACKAGES not empty | ||
19 | MIME_XDG_PACKAGES ?= "" | ||
20 | |||
21 | mime_xdg_postinst() { | ||
22 | if [ "x$D" != "x" ]; then | ||
23 | $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \ | ||
24 | mlprefix=${MLPREFIX} \ | ||
25 | desktop_dir=${DESKTOPDIR} | ||
26 | else | ||
27 | update-desktop-database $D${DESKTOPDIR} | ||
28 | fi | ||
29 | } | ||
30 | |||
31 | mime_xdg_postrm() { | ||
32 | if [ "x$D" != "x" ]; then | ||
33 | $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \ | ||
34 | mlprefix=${MLPREFIX} \ | ||
35 | desktop_dir=${DESKTOPDIR} | ||
36 | else | ||
37 | update-desktop-database $D${DESKTOPDIR} | ||
38 | fi | ||
39 | } | ||
40 | |||
41 | python populate_packages:append () { | ||
42 | packages = d.getVar('PACKAGES').split() | ||
43 | pkgdest = d.getVar('PKGDEST') | ||
44 | desktop_base = d.getVar('DESKTOPDIR') | ||
45 | forced_mime_xdg_pkgs = (d.getVar('MIME_XDG_PACKAGES') or '').split() | ||
46 | |||
47 | for pkg in packages: | ||
48 | desktops_with_mime_found = pkg in forced_mime_xdg_pkgs | ||
49 | if d.getVar('MIME_XDG_PACKAGES') == '': | ||
50 | desktop_dir = '%s/%s%s' % (pkgdest, pkg, desktop_base) | ||
51 | if os.path.exists(desktop_dir): | ||
52 | for df in os.listdir(desktop_dir): | ||
53 | if df.endswith('.desktop'): | ||
54 | try: | ||
55 | with open(desktop_dir + '/'+ df, 'r') as f: | ||
56 | for line in f.read().split('\n'): | ||
57 | if 'MimeType' in line: | ||
58 | desktops_with_mime_found = True | ||
59 | break; | ||
60 | except: | ||
61 | bb.warn('Could not open %s. Set MIME_XDG_PACKAGES in recipe or add mime-xdg to INSANE_SKIP.' % desktop_dir + '/'+ df) | ||
62 | if desktops_with_mime_found: | ||
63 | break | ||
64 | if desktops_with_mime_found: | ||
65 | bb.note("adding mime-xdg postinst and postrm scripts to %s" % pkg) | ||
66 | postinst = d.getVar('pkg_postinst:%s' % pkg) | ||
67 | if not postinst: | ||
68 | postinst = '#!/bin/sh\n' | ||
69 | postinst += d.getVar('mime_xdg_postinst') | ||
70 | d.setVar('pkg_postinst:%s' % pkg, postinst) | ||
71 | postrm = d.getVar('pkg_postrm:%s' % pkg) | ||
72 | if not postrm: | ||
73 | postrm = '#!/bin/sh\n' | ||
74 | postrm += d.getVar('mime_xdg_postrm') | ||
75 | d.setVar('pkg_postrm:%s' % pkg, postrm) | ||
76 | bb.note("adding desktop-file-utils dependency to %s" % pkg) | ||
77 | d.appendVar('RDEPENDS:' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils") | ||
78 | } | ||