rootfs: use LOCALE_DEFAULT with default "C" for locale exports

Message ID 20250910092250.179144-1-badrikesh.prusty@siemens.com
State New
Headers show
Series rootfs: use LOCALE_DEFAULT with default "C" for locale exports | expand

Commit Message

Badrikesh Prusty Sept. 10, 2025, 9:22 a.m. UTC
Some packages, such as console-setup, fail to set a valid CHARMAP according
to the locale. For example, image-locales-extension.bbclass sets the default
locale to "en_US.UTF-8".

However, rootfs.bbclass was exporting hardcoded locale values as "C".
Because of this, when console-setup is installed in non-interactive mode
during image creation, it sets the CHARMAP based on the "C" locale, causing
a configuration mismatch.

Set LOCALE_DEFAULT to "C" by default in rootfs.bbclass so it can be overridden
by image-locales-extension.bbclass with "en_US.UTF-8", enabling proper CHARMAP
setup in console-setup.

Signed-off-by: Badrikesh Prusty <badrikesh.prusty@siemens.com>
---
 RECIPE-API-CHANGELOG.md     | 20 ++++++++++++++++++++
 meta/classes/rootfs.bbclass |  7 ++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

Patch

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 8468717d..c6b5a997 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -727,3 +727,23 @@  Changes in next
 
 This was never documented and never had practical relevance. `oci-archive` is
 the useful OCI image format that can be imported, e.g., by podman.
+
+### Configure Locale Exports Using LOCALE_DEFAULT
+
+The LOCALE_DEFAULT variable is now used to export LANG, LANGUAGE, and LC_ALL
+in the rootfs.bbclass, replacing the previous hardcoded "C" values. It is
+weakly assigned a default value of "C". This value can be overridden by image
+recipes via the image-locales-extension class (inherited by the image class),
+for example, to set it to "en_US.UTF-8".
+
+This enables configuring the default locale and keyboard layout at build time.
+Additionally, if console-setup is installed in the rootfs during the build, it
+will be configured based on the locale exports.
+
+To set a locale other than "C" or "en_US.UTF-8" (generated by default), define
+the following variables in your image recipe. For example, to use German, add:
+
+```
+LOCALE_GEN = "de_DE.UTF-8 UTF-8\n"
+LOCALE_DEFAULT = "de_DE.UTF-8"
+```
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index 7b7859b9..9eb09012 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -30,9 +30,10 @@  ROOTFS_STUBS_DIR = "/usr/local/isar-sbin"
 export E = "${@ isar_export_proxies(d)}"
 export DEBIAN_FRONTEND = "noninteractive"
 # To avoid Perl locale warnings:
-export LANG = "C"
-export LANGUAGE = "C"
-export LC_ALL = "C"
+LOCALE_DEFAULT ??= "C"
+export LANG = "${LOCALE_DEFAULT}"
+export LANGUAGE = "${LOCALE_DEFAULT}"
+export LC_ALL = "${LOCALE_DEFAULT}"
 
 rootfs_do_mounts[weight] = "3"
 rootfs_do_mounts() {