glibc, package.bbclass: generate old-style binary locales at build time using qemu...
authorRene Wagner <rw@handhelds.org>
Mon, 6 Mar 2006 21:11:18 +0000 (21:11 +0000)
committerOpenEmbedded Project <openembedded-devel@lists.openembedded.org>
Mon, 6 Mar 2006 21:11:18 +0000 (21:11 +0000)
  - running localedef (in qemu...) for every locale takes a while. set
    BINARY_LOCALE_ARCHES = "" to avoid the new behaviour.

classes/package.bbclass
packages/glibc/glibc-package.bbclass
packages/glibc/glibc_2.3.5+cvs20050627.bb

index ab1cea3..d32cf53 100644 (file)
@@ -68,7 +68,7 @@ python package_mapping_rename_hook () {
 }
 
 
-def do_split_packages(d, root, file_regex, output_pattern, description, postinst=None, recursive=False, hook=None, extra_depends=None, aux_files_pattern=None, postrm=None, allow_dirs=False, prepend=False, match_path=False):
+def do_split_packages(d, root, file_regex, output_pattern, description, postinst=None, recursive=False, hook=None, extra_depends=None, aux_files_pattern=None, postrm=None, allow_dirs=False, prepend=False, match_path=False, aux_files_pattern_verbatim=None):
        import os, os.path, bb
 
        dvar = bb.data.getVar('D', d, 1)
@@ -125,6 +125,12 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst
                                                the_files.append(fp % on)       
                                else:
                                        the_files.append(aux_files_pattern % on)
+                       if aux_files_pattern_verbatim:
+                               if type(aux_files_pattern_verbatim) is list:
+                                       for fp in aux_files_pattern_verbatim:
+                                               the_files.append(fp % m.group(1))       
+                               else:
+                                       the_files.append(aux_files_pattern_verbatim % m.group(1))
                        bb.data.setVar('FILES_' + pkg, " ".join(the_files), d)
                        if extra_depends != '':
                                the_depends = bb.data.getVar('RDEPENDS_' + pkg, d, 1)
index 9a91e3a..e03d99b 100644 (file)
@@ -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'
index 396d237..d192590 100644 (file)
@@ -7,11 +7,13 @@ MAINTAINER = "Phil Blundell <pb@handhelds.org>"
 
 FILESDIR = "${@os.path.dirname(bb.data.getVar('FILE',d,1))}/glibc-cvs-2.3.5"
 SRCDATE = "20050627"
-PR = "r2"
+PR = "r3"
 
 GLIBC_ADDONS ?= "ports,linuxthreads"
 GLIBC_EXTRA_OECONF ?= ""
 
+GLIBC_BROKEN_LOCALES = "sid_ET tr_TR mn_MN"
+
 #
 # For now, we will skip building of a gcc package if it is a uclibc one
 # and our build is not a uclibc one, and we skip a glibc one if our build