commit:     4177dab14cfee01f5b9b29f3cbbb38635bba41c5
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Aug  5 00:45:31 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Tue Aug  5 10:24:46 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=4177dab1

Render compatible with the compile-locales USE flag of sys-libs/glibc

Version 3.0 of locale-gen(1) fails in the case that it is invoked by the
sys-libs/glibc ebuild, provided that the "compile-locales" USE flag is
in effect. It was developed under the understanding that the flag might
eventually be removed and unexpectedly committed to the repo before any
meaningful testing had been performed with the flag enabled.

The particulars of the two modes of failure are described herewith.

Firstly, the ebuild executes locale-gen(1) with "${ED}" as a prefix.

  locale-gen --prefix /var/tmp/portage/sys-libs/glibc-2.41-r4/image

Secondly, the program declares the $prefix, $locale_dir and
$gentoo_prefix variables. Given the above value of the --prefix option,
the values of these variables shall be as follows.

  $prefix = "var/tmp/portage/sys-libs/glibc-2.41-r4/image"
  $locale_dir = "/usr/lib/locale"
  $gentoo_prefix = ""

Thirdly, having compiled the requested locales, the program calls the
generate_archive() subroutine, passing the values of the $prefix and
$locale_dir variables (but not the $gentoo_prefix variable).

Fourthly, the generate_archive() subroutine declares the $output_dir
variable.

  # Assigns "./var/tmp/portage/sys-libs/glibc-2.41-r4/image/usr/lib/locale"
  my $output_dir = catdir('.', $prefix, $locale_dir)

Fifthly, the generate_archive subroutine executes mkdir(1), so as to
create the directory specified by $output_dir.

  mkdir -p ./var/tmp/portage/sys-libs/glibc-2.41-r4/image/usr/lib/locale

Sixthly, the localedef(1) utility is executed with "." as its first
argument. Internally, it joins "." to "/usr/lib/locale" and attempts to
write a new archive there. This is the point at which a failure occurs,
for the "./usr/lib/locale" directory doesn't exist. In turn, that is
because the wrong value was assigned to the $output_dir variable.

Address this issue by also passing the value of the $gentoo_prefix
variable to the generate_archive() subroutine, and using that to form
the value of $output_dir, like so.

  # Correctly assigns "./usr/lib/locale"
  my $output_dir = catdir('.', $gentoo_prefix, $locale_dir)

This works as intended in Gentoo Prefix environments. Imagine that such
an environment is situated at "/home/gentoo/gentoo". The values of the
$prefix, $locale_dir and $gentoo_prefix variables shall be as follows.

  $prefix = 
"/home/gentoo/gentoo/var/tmp/portage/sys-libs/glibc-2.41-r4/image/home/gentoo/gentoo"
  $locale_dir = "/usr/lib/locale"
  $gentoo_prefix = "/home/gentoo/gentoo"

Consequently, $output_dir shall be formed in the following way.

  # Correctly assigns "./home/gentoo/gentoo/usr/lib/locale"
  my $output_dir = catdir('.', $gentoo_prefix, $locale_dir)

Such is correct because the location of the Gentoo Prefix environment is
integrated into the localedef(1) binary. That is, one cannot simply
specify the desired output directory to localedef(1) in full.

Additionally, the parse_opts() subroutine checks whether the value of
the --prefix option is equal to the path of the automatically detected
Gentoo Prefix, if any. This causes a failure in its own right since the
value of $prefix cannot possibly be equal to $gentoo_prefix in the case
that the "compile-locales" flag is in effect. Jettison this check.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/locale-gen b/locale-gen
index 7df6be1..45026ab 100755
--- a/locale-gen
+++ b/locale-gen
@@ -113,7 +113,7 @@ delete @ENV{'BASH_ENV', 'CDPATH'};
        generate_locales($opt{'jobs'}, @locales);
 
        # Integrate the newly compiled locales into the system's locale archive.
-       generate_archive($prefix, $locale_dir, $opt{'update'}, map +( $_->[2] 
), @locales);
+       generate_archive($prefix, $gentoo_prefix, $locale_dir, $opt{'update'}, 
map +( $_->[2] ), @locales);
 
        my $total = scalar @locales;
        printf "Successfully installed %d locale%s.\n", $total, plural($total);
@@ -173,8 +173,6 @@ sub parse_opts ($known_prefix, @args) {
        # Validate the options and option-arguments.
        if ($opt{'all'} && exists $opt{'config'}) {
                die "$PROGRAM: The --all and --config options are mutually 
exclusive\n";
-       } elsif (exists $opt{'prefix'} && length $known_prefix && ! 
is_eq_file($known_prefix, $opt{'prefix'})) {
-               die "$PROGRAM: The --prefix option specifies a path contrary to 
a detected Gentoo Prefix\n";
        }
 
        # Assign values for unspecified options that need them.
@@ -429,9 +427,9 @@ sub compile_locale ($locale, $charmap, $canonical) {
        run_localedef(undef, @args);
 }
 
-sub generate_archive ($prefix, $locale_dir, $do_update, @canonicals) {
+sub generate_archive ($prefix, $gentoo_prefix, $locale_dir, $do_update, 
@canonicals) {
        # Create the temporary subdir that will contain the new locale archive.
-       my $output_dir = catdir('.', $prefix, $locale_dir);
+       my $output_dir = catdir('.', $gentoo_prefix, $locale_dir);
        run('mkdir', '-p', '--', $output_dir);
 
        # Determine the eventual destination path of the archive.

Reply via email to