Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # This class knows how to package up [e]glibc. Its shared since prebuild binary toolchains |
| 3 | # may need packaging and its pointless to duplicate this code. |
| 4 | # |
| 5 | # Caller should set GLIBC_INTERNAL_USE_BINARY_LOCALE to one of: |
| 6 | # "compile" - Use QEMU to generate the binary locale files |
| 7 | # "precompiled" - The binary locale files are pregenerated and already present |
| 8 | # "ondevice" - The device will build the locale files upon first boot through the postinst |
| 9 | |
| 10 | GLIBC_INTERNAL_USE_BINARY_LOCALE ?= "ondevice" |
| 11 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | GLIBC_SPLIT_LC_PACKAGES ?= "0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | python __anonymous () { |
| 15 | enabled = d.getVar("ENABLE_BINARY_LOCALE_GENERATION") |
| 16 | |
| 17 | pn = d.getVar("PN") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | if pn.endswith("-initial"): |
| 19 | enabled = False |
| 20 | |
| 21 | if enabled and int(enabled): |
| 22 | import re |
| 23 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | target_arch = d.getVar("TARGET_ARCH") |
| 25 | binary_arches = d.getVar("BINARY_LOCALE_ARCHES") or "" |
| 26 | use_cross_localedef = d.getVar("LOCALE_GENERATION_WITH_CROSS-LOCALEDEF") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | |
| 28 | for regexp in binary_arches.split(" "): |
| 29 | r = re.compile(regexp) |
| 30 | |
| 31 | if r.match(target_arch): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 32 | depends = d.getVar("DEPENDS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | if use_cross_localedef == "1" : |
| 34 | depends = "%s cross-localedef-native" % depends |
| 35 | else: |
| 36 | depends = "%s qemu-native" % depends |
| 37 | d.setVar("DEPENDS", depends) |
| 38 | d.setVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", "compile") |
| 39 | break |
| 40 | |
| 41 | # try to fix disable charsets/locales/locale-code compile fail |
| 42 | if bb.utils.contains('DISTRO_FEATURES', 'libc-charsets', True, False, d) and \ |
| 43 | bb.utils.contains('DISTRO_FEATURES', 'libc-locales', True, False, d) and \ |
| 44 | bb.utils.contains('DISTRO_FEATURES', 'libc-locale-code', True, False, d): |
| 45 | d.setVar('PACKAGE_NO_GCONV', '0') |
| 46 | else: |
| 47 | d.setVar('PACKAGE_NO_GCONV', '1') |
| 48 | } |
| 49 | |
| 50 | OVERRIDES_append = ":${TARGET_ARCH}-${TARGET_OS}" |
| 51 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 52 | locale_base_postinst_ontarget() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 53 | localedef --inputfile=${datadir}/i18n/locales/%s --charmap=%s %s |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | locale_base_postrm() { |
| 57 | #!/bin/sh |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 58 | localedef --delete-from-archive --inputfile=${datadir}/locales/%s --charmap=%s %s |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | LOCALETREESRC ?= "${PKGD}" |
| 62 | |
| 63 | do_prep_locale_tree() { |
| 64 | treedir=${WORKDIR}/locale-tree |
| 65 | rm -rf $treedir |
| 66 | mkdir -p $treedir/${base_bindir} $treedir/${base_libdir} $treedir/${datadir} $treedir/${localedir} |
| 67 | tar -cf - -C ${LOCALETREESRC}${datadir} -p i18n | tar -xf - -C $treedir/${datadir} |
| 68 | # unzip to avoid parsing errors |
| 69 | for i in $treedir/${datadir}/i18n/charmaps/*gz; do |
| 70 | gunzip $i |
| 71 | done |
| 72 | tar -cf - -C ${LOCALETREESRC}${base_libdir} -p . | tar -xf - -C $treedir/${base_libdir} |
| 73 | if [ -f ${STAGING_DIR_NATIVE}${prefix_native}/lib/libgcc_s.* ]; then |
| 74 | tar -cf - -C ${STAGING_DIR_NATIVE}/${prefix_native}/${base_libdir} -p libgcc_s.* | tar -xf - -C $treedir/${base_libdir} |
| 75 | fi |
| 76 | install -m 0755 ${LOCALETREESRC}${bindir}/localedef $treedir/${base_bindir} |
| 77 | } |
| 78 | |
| 79 | do_collect_bins_from_locale_tree() { |
| 80 | treedir=${WORKDIR}/locale-tree |
| 81 | |
| 82 | parent=$(dirname ${localedir}) |
| 83 | mkdir -p ${PKGD}/$parent |
| 84 | tar -cf - -C $treedir/$parent -p $(basename ${localedir}) | tar -xf - -C ${PKGD}$parent |
| 85 | } |
| 86 | |
| 87 | inherit qemu |
| 88 | |
| 89 | python package_do_split_gconvs () { |
| 90 | import re |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 91 | if (d.getVar('PACKAGE_NO_GCONV') == '1'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | bb.note("package requested not splitting gconvs") |
| 93 | return |
| 94 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 95 | if not d.getVar('PACKAGES'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | return |
| 97 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | mlprefix = d.getVar("MLPREFIX") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 100 | bpn = d.getVar('BPN') |
| 101 | libdir = d.getVar('libdir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | if not libdir: |
| 103 | bb.error("libdir not defined") |
| 104 | return |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 105 | datadir = d.getVar('datadir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | if not datadir: |
| 107 | bb.error("datadir not defined") |
| 108 | return |
| 109 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 110 | gconv_libdir = oe.path.join(libdir, "gconv") |
| 111 | charmap_dir = oe.path.join(datadir, "i18n", "charmaps") |
| 112 | locales_dir = oe.path.join(datadir, "i18n", "locales") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 113 | binary_locales_dir = d.getVar('localedir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | |
| 115 | def calc_gconv_deps(fn, pkg, file_regex, output_pattern, group): |
| 116 | deps = [] |
| 117 | f = open(fn, "rb") |
| 118 | c_re = re.compile('^copy "(.*)"') |
| 119 | i_re = re.compile('^include "(\w+)".*') |
| 120 | for l in f.readlines(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 121 | l = l.decode("latin-1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | m = c_re.match(l) or i_re.match(l) |
| 123 | if m: |
| 124 | dp = legitimize_package_name('%s%s-gconv-%s' % (mlprefix, bpn, m.group(1))) |
| 125 | if not dp in deps: |
| 126 | deps.append(dp) |
| 127 | f.close() |
| 128 | if deps != []: |
| 129 | d.setVar('RDEPENDS_%s' % pkg, " ".join(deps)) |
| 130 | if bpn != 'glibc': |
| 131 | d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc')) |
| 132 | |
| 133 | do_split_packages(d, gconv_libdir, file_regex='^(.*)\.so$', output_pattern=bpn+'-gconv-%s', \ |
| 134 | description='gconv module for character set %s', hook=calc_gconv_deps, \ |
| 135 | extra_depends=bpn+'-gconv') |
| 136 | |
| 137 | def calc_charmap_deps(fn, pkg, file_regex, output_pattern, group): |
| 138 | deps = [] |
| 139 | f = open(fn, "rb") |
| 140 | c_re = re.compile('^copy "(.*)"') |
| 141 | i_re = re.compile('^include "(\w+)".*') |
| 142 | for l in f.readlines(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 143 | l = l.decode("latin-1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | m = c_re.match(l) or i_re.match(l) |
| 145 | if m: |
| 146 | dp = legitimize_package_name('%s%s-charmap-%s' % (mlprefix, bpn, m.group(1))) |
| 147 | if not dp in deps: |
| 148 | deps.append(dp) |
| 149 | f.close() |
| 150 | if deps != []: |
| 151 | d.setVar('RDEPENDS_%s' % pkg, " ".join(deps)) |
| 152 | if bpn != 'glibc': |
| 153 | d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc')) |
| 154 | |
| 155 | do_split_packages(d, charmap_dir, file_regex='^(.*)\.gz$', output_pattern=bpn+'-charmap-%s', \ |
| 156 | description='character map for %s encoding', hook=calc_charmap_deps, extra_depends='') |
| 157 | |
| 158 | def calc_locale_deps(fn, pkg, file_regex, output_pattern, group): |
| 159 | deps = [] |
| 160 | f = open(fn, "rb") |
| 161 | c_re = re.compile('^copy "(.*)"') |
| 162 | i_re = re.compile('^include "(\w+)".*') |
| 163 | for l in f.readlines(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 164 | l = l.decode("latin-1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | m = c_re.match(l) or i_re.match(l) |
| 166 | if m: |
| 167 | dp = legitimize_package_name(mlprefix+bpn+'-localedata-%s' % m.group(1)) |
| 168 | if not dp in deps: |
| 169 | deps.append(dp) |
| 170 | f.close() |
| 171 | if deps != []: |
| 172 | d.setVar('RDEPENDS_%s' % pkg, " ".join(deps)) |
| 173 | if bpn != 'glibc': |
| 174 | d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc')) |
| 175 | |
| 176 | do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern=bpn+'-localedata-%s', \ |
| 177 | description='locale definition for %s', hook=calc_locale_deps, extra_depends='') |
| 178 | d.setVar('PACKAGES', d.getVar('PACKAGES', False) + ' ' + d.getVar('MLPREFIX', False) + bpn + '-gconv') |
| 179 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 180 | use_bin = d.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | |
| 182 | dot_re = re.compile("(.*)\.(.*)") |
| 183 | |
| 184 | # Read in supported locales and associated encodings |
| 185 | supported = {} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 186 | with open(oe.path.join(d.getVar('WORKDIR'), "SUPPORTED")) as f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | for line in f.readlines(): |
| 188 | try: |
| 189 | locale, charset = line.rstrip().split() |
| 190 | except ValueError: |
| 191 | continue |
| 192 | supported[locale] = charset |
| 193 | |
| 194 | # GLIBC_GENERATE_LOCALES var specifies which locales to be generated. empty or "all" means all locales |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 195 | to_generate = d.getVar('GLIBC_GENERATE_LOCALES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | if not to_generate or to_generate == 'all': |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 197 | to_generate = sorted(supported.keys()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 198 | else: |
| 199 | to_generate = to_generate.split() |
| 200 | for locale in to_generate: |
| 201 | if locale not in supported: |
| 202 | if '.' in locale: |
| 203 | charset = locale.split('.')[1] |
| 204 | else: |
| 205 | charset = 'UTF-8' |
| 206 | bb.warn("Unsupported locale '%s', assuming encoding '%s'" % (locale, charset)) |
| 207 | supported[locale] = charset |
| 208 | |
| 209 | def output_locale_source(name, pkgname, locale, encoding): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 210 | d.setVar('RDEPENDS_%s' % pkgname, '%slocaledef %s-localedata-%s %s-charmap-%s' % \ |
| 211 | (mlprefix, mlprefix+bpn, legitimize_package_name(locale), mlprefix+bpn, legitimize_package_name(encoding))) |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 212 | d.setVar('pkg_postinst_ontarget_%s' % pkgname, d.getVar('locale_base_postinst_ontarget') \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 213 | % (locale, encoding, locale)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 214 | d.setVar('pkg_postrm_%s' % pkgname, d.getVar('locale_base_postrm') % \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 215 | (locale, encoding, locale)) |
| 216 | |
| 217 | def output_locale_binary_rdepends(name, pkgname, locale, encoding): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 218 | dep = legitimize_package_name('%s-binary-localedata-%s' % (bpn, name)) |
| 219 | lcsplit = d.getVar('GLIBC_SPLIT_LC_PACKAGES') |
| 220 | if lcsplit and int(lcsplit): |
| 221 | d.appendVar('PACKAGES', ' ' + dep) |
| 222 | d.setVar('ALLOW_EMPTY_%s' % dep, '1') |
| 223 | d.setVar('RDEPENDS_%s' % pkgname, mlprefix + dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | |
| 225 | commands = {} |
| 226 | |
| 227 | def output_locale_binary(name, pkgname, locale, encoding): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 228 | treedir = oe.path.join(d.getVar("WORKDIR"), "locale-tree") |
| 229 | ldlibdir = oe.path.join(treedir, d.getVar("base_libdir")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 230 | path = d.getVar("PATH") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 231 | i18npath = oe.path.join(treedir, datadir, "i18n") |
| 232 | gconvpath = oe.path.join(treedir, "iconvdata") |
| 233 | outputpath = oe.path.join(treedir, binary_locales_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 235 | use_cross_localedef = d.getVar("LOCALE_GENERATION_WITH_CROSS-LOCALEDEF") or "0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 236 | if use_cross_localedef == "1": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 237 | target_arch = d.getVar('TARGET_ARCH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | locale_arch_options = { \ |
| 239 | "arm": " --uint32-align=4 --little-endian ", \ |
| 240 | "armeb": " --uint32-align=4 --big-endian ", \ |
| 241 | "aarch64": " --uint32-align=4 --little-endian ", \ |
| 242 | "aarch64_be": " --uint32-align=4 --big-endian ", \ |
| 243 | "sh4": " --uint32-align=4 --big-endian ", \ |
| 244 | "powerpc": " --uint32-align=4 --big-endian ", \ |
| 245 | "powerpc64": " --uint32-align=4 --big-endian ", \ |
| 246 | "mips": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 247 | "mipsisa32r6": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 248 | "mips64": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 249 | "mipsisa64r6": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 250 | "mipsel": " --uint32-align=4 --little-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 251 | "mipsisa32r6el": " --uint32-align=4 --little-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | "mips64el":" --uint32-align=4 --little-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 253 | "mipsisa64r6el":" --uint32-align=4 --little-endian ", \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 254 | "riscv64": " --uint32-align=4 --little-endian ", \ |
| 255 | "riscv32": " --uint32-align=4 --little-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 256 | "i586": " --uint32-align=4 --little-endian ", \ |
| 257 | "i686": " --uint32-align=4 --little-endian ", \ |
| 258 | "x86_64": " --uint32-align=4 --little-endian " } |
| 259 | |
| 260 | if target_arch in locale_arch_options: |
| 261 | localedef_opts = locale_arch_options[target_arch] |
| 262 | else: |
| 263 | bb.error("locale_arch_options not found for target_arch=" + target_arch) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 264 | bb.fatal("unknown arch:" + target_arch + " for locale_arch_options") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 266 | localedef_opts += " --force --no-archive --prefix=%s \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | --inputfile=%s/%s/i18n/locales/%s --charmap=%s %s/%s" \ |
| 268 | % (treedir, treedir, datadir, locale, encoding, outputpath, name) |
| 269 | |
| 270 | cmd = "PATH=\"%s\" I18NPATH=\"%s\" GCONV_PATH=\"%s\" cross-localedef %s" % \ |
| 271 | (path, i18npath, gconvpath, localedef_opts) |
| 272 | else: # earlier slower qemu way |
| 273 | qemu = qemu_target_binary(d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 274 | localedef_opts = "--force --no-archive --prefix=%s \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | --inputfile=%s/i18n/locales/%s --charmap=%s %s" \ |
| 276 | % (treedir, datadir, locale, encoding, name) |
| 277 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 278 | qemu_options = d.getVar('QEMU_OPTIONS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 | |
| 280 | cmd = "PSEUDO_RELOADED=YES PATH=\"%s\" I18NPATH=\"%s\" %s -L %s \ |
| 281 | -E LD_LIBRARY_PATH=%s %s %s/bin/localedef %s" % \ |
| 282 | (path, i18npath, qemu, treedir, ldlibdir, qemu_options, treedir, localedef_opts) |
| 283 | |
| 284 | commands["%s/%s" % (outputpath, name)] = cmd |
| 285 | |
| 286 | bb.note("generating locale %s (%s)" % (locale, encoding)) |
| 287 | |
| 288 | def output_locale(name, locale, encoding): |
| 289 | pkgname = d.getVar('MLPREFIX', False) + 'locale-base-' + legitimize_package_name(name) |
| 290 | d.setVar('ALLOW_EMPTY_%s' % pkgname, '1') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 291 | d.setVar('PACKAGES', '%s %s' % (pkgname, d.getVar('PACKAGES'))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | rprovides = ' %svirtual-locale-%s' % (mlprefix, legitimize_package_name(name)) |
| 293 | m = re.match("(.*)_(.*)", name) |
| 294 | if m: |
| 295 | rprovides += ' %svirtual-locale-%s' % (mlprefix, m.group(1)) |
| 296 | d.setVar('RPROVIDES_%s' % pkgname, rprovides) |
| 297 | |
| 298 | if use_bin == "compile": |
| 299 | output_locale_binary_rdepends(name, pkgname, locale, encoding) |
| 300 | output_locale_binary(name, pkgname, locale, encoding) |
| 301 | elif use_bin == "precompiled": |
| 302 | output_locale_binary_rdepends(name, pkgname, locale, encoding) |
| 303 | else: |
| 304 | output_locale_source(name, pkgname, locale, encoding) |
| 305 | |
| 306 | if use_bin == "compile": |
| 307 | bb.note("preparing tree for binary locale generation") |
| 308 | bb.build.exec_func("do_prep_locale_tree", d) |
| 309 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 310 | utf8_only = int(d.getVar('LOCALE_UTF8_ONLY') or 0) |
| 311 | utf8_is_default = int(d.getVar('LOCALE_UTF8_IS_DEFAULT') or 0) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 312 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | encodings = {} |
| 314 | for locale in to_generate: |
| 315 | charset = supported[locale] |
| 316 | if utf8_only and charset != 'UTF-8': |
| 317 | continue |
| 318 | |
| 319 | m = dot_re.match(locale) |
| 320 | if m: |
| 321 | base = m.group(1) |
| 322 | else: |
| 323 | base = locale |
| 324 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 325 | # Non-precompiled locales may be renamed so that the default |
| 326 | # (non-suffixed) encoding is always UTF-8, i.e., instead of en_US and |
| 327 | # en_US.UTF-8, we have en_US and en_US.ISO-8859-1. This implicitly |
| 328 | # contradicts SUPPORTED. |
| 329 | if use_bin == "precompiled" or not utf8_is_default: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 330 | output_locale(locale, base, charset) |
| 331 | else: |
| 332 | if charset == 'UTF-8': |
| 333 | output_locale(base, base, charset) |
| 334 | else: |
| 335 | output_locale('%s.%s' % (base, charset), base, charset) |
| 336 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 337 | def metapkg_hook(file, pkg, pattern, format, basename): |
| 338 | name = basename.split('/', 1)[0] |
| 339 | metapkg = legitimize_package_name('%s-binary-localedata-%s' % (mlprefix+bpn, name)) |
| 340 | d.appendVar('RDEPENDS_%s' % metapkg, ' ' + pkg) |
| 341 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 342 | if use_bin == "compile": |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 343 | makefile = oe.path.join(d.getVar("WORKDIR"), "locale-tree", "Makefile") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 344 | m = open(makefile, "w") |
| 345 | m.write("all: %s\n\n" % " ".join(commands.keys())) |
| 346 | for cmd in commands: |
| 347 | m.write(cmd + ":\n") |
| 348 | m.write("\t" + commands[cmd] + "\n\n") |
| 349 | m.close() |
| 350 | d.setVar("EXTRA_OEMAKE", "-C %s ${PARALLEL_MAKE}" % (os.path.dirname(makefile))) |
| 351 | bb.note("Executing binary locale generation makefile") |
| 352 | bb.build.exec_func("oe_runmake", d) |
| 353 | bb.note("collecting binary locales from locale tree") |
| 354 | bb.build.exec_func("do_collect_bins_from_locale_tree", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 355 | |
| 356 | if use_bin in ('compile', 'precompiled'): |
| 357 | lcsplit = d.getVar('GLIBC_SPLIT_LC_PACKAGES') |
| 358 | if lcsplit and int(lcsplit): |
| 359 | do_split_packages(d, binary_locales_dir, file_regex='^(.*/LC_\w+)', \ |
| 360 | output_pattern=bpn+'-binary-localedata-%s', \ |
| 361 | description='binary locale definition for %s', recursive=True, |
| 362 | hook=metapkg_hook, extra_depends='', allow_dirs=True, match_path=True) |
| 363 | else: |
| 364 | do_split_packages(d, binary_locales_dir, file_regex='(.*)', \ |
| 365 | output_pattern=bpn+'-binary-localedata-%s', \ |
| 366 | description='binary locale definition for %s', extra_depends='', allow_dirs=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | else: |
| 368 | bb.note("generation of binary locales disabled. this may break i18n!") |
| 369 | |
| 370 | } |
| 371 | |
| 372 | # We want to do this indirection so that we can safely 'return' |
| 373 | # from the called function even though we're prepending |
| 374 | python populate_packages_prepend () { |
| 375 | bb.build.exec_func('package_do_split_gconvs', d) |
| 376 | } |