[3/4] fix(rootfs): only set custom locale in image recipe

Message ID 20260915093258.1818604-4-felix.moessbauer@siemens.com
State Under Review
Headers show
Series Rework locale generation | expand

Commit Message

Felix Moessbauer Sept. 15, 2026, 9:32 a.m. UTC
In a16ca927 it was discovered, that the package maintainer scripts
behave differently depending on the exported locale during package
installation. This was adressed by always setting the desired locale
during rootfs install. However, as this change was applied in the rootfs
class, it also affected all other chroots, reducing the sstate cache
hits and resulting in unintended side effects (like inconsistencies
between the exported locale and the available locales in that rootfs).

We fix this by only overwriting the locale settings if the
image-locale-extension class is inherited. By that, the locale
changes only affect the image rootfs.

Fixes: a16ca927 ("rootfs: use LOCALE_DEFAULT with default "C" ...")
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes-recipe/image-locales-extension.bbclass | 5 +++++
 meta/classes-recipe/rootfs.bbclass                  | 7 +++----
 2 files changed, 8 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/classes-recipe/image-locales-extension.bbclass b/meta/classes-recipe/image-locales-extension.bbclass
index c03f34c0..66f3ac8c 100644
--- a/meta/classes-recipe/image-locales-extension.bbclass
+++ b/meta/classes-recipe/image-locales-extension.bbclass
@@ -9,6 +9,11 @@ 
 LOCALE_GEN ?= "en_US.UTF-8 UTF-8\n\
                en_US ISO-8859-1\n"
 LOCALE_DEFAULT ?= "en_US.UTF-8"
+# set locale used during package installation, which is visible to
+# maintainer scripts (e.g. used in console-setup)
+export LANG = "${LOCALE_DEFAULT}"
+export LANGUAGE = "${LOCALE_DEFAULT}"
+export LC_ALL = "${LOCALE_DEFAULT}"
 
 def get_locale_gen(d, sep='\n'):
     locale_gen = d.getVar("LOCALE_GEN") or ""
diff --git a/meta/classes-recipe/rootfs.bbclass b/meta/classes-recipe/rootfs.bbclass
index d3b0d471..bbaafa01 100644
--- a/meta/classes-recipe/rootfs.bbclass
+++ b/meta/classes-recipe/rootfs.bbclass
@@ -93,10 +93,9 @@  def get_rootfs_distro(d):
 export E = "${@ isar_export_proxies(d)}"
 export DEBIAN_FRONTEND = "noninteractive"
 # To avoid Perl locale warnings:
-LOCALE_DEFAULT ??= "C"
-export LANG = "${LOCALE_DEFAULT}"
-export LANGUAGE = "${LOCALE_DEFAULT}"
-export LC_ALL = "${LOCALE_DEFAULT}"
+export LANG ??= "C"
+export LANGUAGE ??= "C"
+export LC_ALL ??= "C"
 
 # Execute a command against a rootfs and with isar-apt bind-mounted.
 # Additional mounts may be specified using --bind <source> <target> and a