mime.bbclass 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. #
  7. # This class is used by recipes installing mime types
  8. #
  9. DEPENDS += "${@bb.utils.contains('BPN', 'shared-mime-info', '', 'shared-mime-info', d)}"
  10. PACKAGE_WRITE_DEPS += "shared-mime-info-native"
  11. MIMEDIR = "${datadir}/mime"
  12. mime_postinst() {
  13. if [ "x$D" != "x" ]; then
  14. $INTERCEPT_DIR/postinst_intercept update_mime_database ${PKG} \
  15. mlprefix=${MLPREFIX} \
  16. mimedir=${MIMEDIR}
  17. else
  18. echo "Updating MIME database... this may take a while."
  19. update-mime-database $D${MIMEDIR}
  20. fi
  21. }
  22. mime_postrm() {
  23. if [ "x$D" != "x" ]; then
  24. $INTERCEPT_DIR/postinst_intercept update_mime_database ${PKG} \
  25. mlprefix=${MLPREFIX} \
  26. mimedir=${MIMEDIR}
  27. else
  28. echo "Updating MIME database... this may take a while."
  29. # $D${MIMEDIR}/packages belong to package shared-mime-info-data,
  30. # packages like libfm-mime depend on shared-mime-info-data.
  31. # after shared-mime-info-data uninstalled, $D${MIMEDIR}/packages
  32. # is removed, but update-mime-database need this dir to update
  33. # database, workaround to create one and remove it later
  34. if [ ! -d $D${MIMEDIR}/packages ]; then
  35. mkdir -p $D${MIMEDIR}/packages
  36. update-mime-database $D${MIMEDIR}
  37. rmdir --ignore-fail-on-non-empty $D${MIMEDIR}/packages
  38. else
  39. update-mime-database $D${MIMEDIR}
  40. fi
  41. fi
  42. }
  43. python populate_packages:append () {
  44. packages = d.getVar('PACKAGES').split()
  45. pkgdest = d.getVar('PKGDEST')
  46. mimedir = d.getVar('MIMEDIR')
  47. for pkg in packages:
  48. mime_packages_dir = '%s/%s%s/packages' % (pkgdest, pkg, mimedir)
  49. mimes_types_found = False
  50. if os.path.exists(mime_packages_dir):
  51. for f in os.listdir(mime_packages_dir):
  52. if f.endswith('.xml'):
  53. mimes_types_found = True
  54. break
  55. if mimes_types_found:
  56. bb.note("adding mime postinst and postrm scripts to %s" % pkg)
  57. postinst = d.getVar('pkg_postinst:%s' % pkg)
  58. if not postinst:
  59. postinst = '#!/bin/sh\n'
  60. postinst += d.getVar('mime_postinst')
  61. d.setVar('pkg_postinst:%s' % pkg, postinst)
  62. postrm = d.getVar('pkg_postrm:%s' % pkg)
  63. if not postrm:
  64. postrm = '#!/bin/sh\n'
  65. postrm += d.getVar('mime_postrm')
  66. d.setVar('pkg_postrm:%s' % pkg, postrm)
  67. if pkg != 'shared-mime-info-data':
  68. bb.note("adding shared-mime-info-data dependency to %s" % pkg)
  69. d.appendVar('RDEPENDS:' + pkg, " " + d.getVar('MLPREFIX')+"shared-mime-info-data")
  70. }