From d9178f91517c97da8b249186e221c73a3bee1aa3 Mon Sep 17 00:00:00 2001 From: Rene Wagner Date: Mon, 6 Mar 2006 21:11:18 +0000 Subject: glibc, package.bbclass: generate old-style binary locales at build time using qemu. based on a patch originally written by Phil Blundell. fixes hh.org Bug #1385 (localedef OOM issue). - running localedef (in qemu...) for every locale takes a while. set BINARY_LOCALE_ARCHES = "" to avoid the new behaviour. --- packages/glibc/glibc-package.bbclass | 92 ++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 4 deletions(-) (limited to 'packages/glibc/glibc-package.bbclass') diff --git a/packages/glibc/glibc-package.bbclass b/packages/glibc/glibc-package.bbclass index 9a91e3ab24..e03d99b7c3 100644 --- a/packages/glibc/glibc-package.bbclass +++ b/packages/glibc/glibc-package.bbclass @@ -14,11 +14,14 @@ python __anonymous () { bb.data.getVar('TARGET_OS', d, 1)) } +BINARY_LOCALE_ARCHES ?= "arm" + PACKAGES = "glibc catchsegv sln nscd ldd localedef glibc-utils glibc-dev glibc-doc glibc-locale libsegfault glibc-extra-nss glibc-thread-db glibc-pcprofile" +PACKAGES_DYNAMIC = "glibc-gconv-* glibc-charmap-* glibc-localedata-*" libc_baselibs = "/lib/libc* /lib/libm* /lib/ld* /lib/libpthread* /lib/libresolv* /lib/librt* /lib/libutil* /lib/libnsl* /lib/libnss_files* /lib/libnss_compat* /lib/libnss_dns* /lib/libdl* /lib/libanl* /lib/libBrokenLocale*" -FILES_${PN} = "${sysconfdir} ${libc_baselibs} /sbin/ldconfig ${libexecdir} ${datadir}/zoneinfo ${libdir}/locale" +FILES_${PN} = "${sysconfdir} ${libc_baselibs} /sbin/ldconfig ${libexecdir} ${datadir}/zoneinfo" FILES_ldd = "${bindir}/ldd" FILES_libsegfault = "/lib/libSegFault*" FILES_glibc-extra-nss = "/lib/libnss*" @@ -60,6 +63,11 @@ do_install() { install -m 0644 ${WORKDIR}/etc/ld.so.conf ${D}/${sysconfdir}/ install -d ${D}${libdir}/locale make -f ${WORKDIR}/generate-supported.mk IN="${S}/localedata/SUPPORTED" OUT="${WORKDIR}/SUPPORTED" + # get rid of some broken files... + for i in ${GLIBC_BROKEN_LOCALES}; do + grep -v $i ${WORKDIR}/SUPPORTED > ${WORKDIR}/SUPPORTED.tmp + mv ${WORKDIR}/SUPPORTED.tmp ${WORKDIR}/SUPPORTED + done rm -f ${D}/etc/rpc } @@ -95,7 +103,37 @@ mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/ rm -rf ${TMP_LOCALE} } -PACKAGES_DYNAMIC = "glibc-gconv-* glibc-charmap-* glibc-localedata-*" +python __anonymous () { + target_arch = bb.data.getVar("TARGET_ARCH", d, 1) + binary_arches = bb.data.getVar("BINARY_LOCALE_ARCHES", d, 1) or "" + + if target_arch in binary_arches.split(" "): + depends = bb.data.getVar("DEPENDS", d, 1) + depends = "%s qemu-native" % depends + bb.data.setVar("DEPENDS", depends, d) + bb.data.setVar("USE_BINARY_LOCALE", "1", d) +} + +do_prep_locale_tree() { + treedir=${WORKDIR}/locale-tree + rm -rf $treedir + mkdir -p $treedir/bin $treedir/lib $treedir/${datadir} $treedir/${libdir}/locale + cp -a ${D}${datadir}/i18n $treedir/${datadir}/i18n + # unzip to avoid parsing errors + for i in $treedir/${datadir}/i18n/charmaps/*gz; do + gunzip $i + done + cp -a ${STAGING_LIBDIR}/* $treedir/lib + cp -a ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.* $treedir/lib + install -m 0755 ${D}${bindir}/localedef $treedir/bin +} + +do_collect_bins_from_locale_tree() { + treedir=${WORKDIR}/locale-tree + + mkdir -p ${D}${libdir} + cp -a $treedir/${libdir}/locale ${D}${libdir} +} python package_do_split_gconvs () { import os, re @@ -118,6 +156,7 @@ python package_do_split_gconvs () { gconv_libdir = os.path.join(libdir, "gconv") charmap_dir = os.path.join(datadir, "i18n", "charmaps") locales_dir = os.path.join(datadir, "i18n", "locales") + binary_locales_dir = os.path.join(libdir, "locale") do_split_packages(d, gconv_libdir, file_regex='^(.*)\.so$', output_pattern='glibc-gconv-%s', description='gconv module for character set %s', extra_depends='glibc-gconv') @@ -138,7 +177,11 @@ python package_do_split_gconvs () { if deps != []: bb.data.setVar('RDEPENDS_%s' % pkg, " ".join(deps), d) - do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern='glibc-localedata-%s', description='locale definition for %s', hook=calc_locale_deps, extra_depends='') + use_bin = bb.data.getVar("USE_BINARY_LOCALE", d, 1) + if use_bin: + do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern='glibc-localedata-%s', description='locale definition for %s', hook=calc_locale_deps, extra_depends='', aux_files_pattern_verbatim=binary_locales_dir + '/%s') + else: + do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern='glibc-localedata-%s', description='locale definition for %s', hook=calc_locale_deps, extra_depends='') bb.data.setVar('PACKAGES', bb.data.getVar('PACKAGES', d) + ' glibc-gconv', d) f = open(os.path.join(bb.data.getVar('WORKDIR', d, 1), "SUPPORTED"), "r") @@ -159,7 +202,7 @@ python package_do_split_gconvs () { encodings[locale] = [] encodings[locale].append(charset) - def output_locale(name, locale, encoding): + def output_locale_source(name, locale, encoding): pkgname = 'locale-base-' + legitimize_package_name(name) bb.data.setVar('RDEPENDS_%s' % pkgname, 'localedef glibc-localedata-%s glibc-charmap-%s' % (legitimize_package_name(locale), legitimize_package_name(encoding)), d) @@ -173,6 +216,42 @@ python package_do_split_gconvs () { bb.data.setVar('pkg_postinst_%s' % pkgname, bb.data.getVar('locale_base_postinst', d, 1) % (locale, encoding, locale), d) bb.data.setVar('pkg_postrm_%s' % pkgname, bb.data.getVar('locale_base_postrm', d, 1) % (locale, encoding, locale), d) + def output_locale_binary(name, locale, encoding): + target_arch = bb.data.getVar("TARGET_ARCH", d, 1) + qemu = "qemu-%s" % target_arch + pkgname = 'locale-base-' + legitimize_package_name(name) + + bb.data.setVar('RDEPENDS_%s' % pkgname, 'glibc-localedata-%s glibc-charmap-%s' % (legitimize_package_name(locale), legitimize_package_name(encoding)), d) + rprovides = 'virtual-locale-%s' % legitimize_package_name(name) + m = re.match("(.*)_(.*)", name) + if m: + rprovides += ' virtual-locale-%s' % m.group(1) + bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d) + bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d) + bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d) + + treedir = os.path.join(bb.data.getVar("WORKDIR", d, 1), "locale-tree") + path = bb.data.getVar("PATH", d, 1) + i18npath = os.path.join(treedir, datadir, "i18n") + + localedef_opts = "--force --old-style --no-archive --prefix=%s --inputfile=%s/i18n/locales/%s --charmap=%s %s" % (treedir, datadir, locale, encoding, locale) + cmd = "PATH=\"%s\" I18NPATH=\"%s\" %s -L %s %s/bin/localedef %s" % (path, i18npath, qemu, treedir, treedir, localedef_opts) + bb.note("generating locale %s (%s)" % (locale, encoding)) + if os.system(cmd): + raise bb.build.FuncFailed("localedef returned an error.") + + def output_locale(name, locale, encoding): + use_bin = bb.data.getVar("USE_BINARY_LOCALE", d, 1) + if use_bin: + output_locale_binary(name, locale, encoding) + else: + output_locale_source(name, locale, encoding) + + use_bin = bb.data.getVar("USE_BINARY_LOCALE", d, 1) + if use_bin: + bb.note("preparing tree for binary locale generation") + bb.build.exec_func("do_prep_locale_tree", d) + # Reshuffle names so that UTF-8 is preferred over other encodings for l in encodings.keys(): if len(encodings[l]) == 1: @@ -183,6 +262,11 @@ python package_do_split_gconvs () { encodings[l].remove("UTF-8") for e in encodings[l]: output_locale('%s-%s' % (l, e), l, e) + + use_bin = bb.data.getVar("USE_BINARY_LOCALE", d, 1) + if use_bin: + bb.note("collecting binary locales from locale tree") + bb.build.exec_func("do_collect_bins_from_locale_tree", d) } # We want to do this indirection so that we can safely 'return' -- cgit v1.2.3