git: 934364da7fc8 - main - locale: tools: Make finalize idempotent
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 06 Dec 2025 12:21:21 UTC
The branch main has been updated by jlduran:
URL: https://cgit.FreeBSD.org/src/commit/?id=934364da7fc8cd3ba4d030d0478163b41dda1b37
commit 934364da7fc8cd3ba4d030d0478163b41dda1b37
Author: Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-12-06 12:20:19 +0000
Commit: Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-12-06 12:20:19 +0000
locale: tools: Make finalize idempotent
The finalize script renames source files with 3 components in their name
into names with two components with an @modifier, in the process.
Running the script for a second time without cleaning will strip the
@modifier from the files, producing invalid Makefiles and unusable
locales.
Prevent this by adding a guard at the beginning of the script.
Also, use a sub-shell for directory changes to avoid working directory
issues.
Reviewed by: bapt
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53981
---
tools/tools/locale/tools/finalize | 115 ++++++++++++++++++++------------------
1 file changed, 60 insertions(+), 55 deletions(-)
diff --git a/tools/tools/locale/tools/finalize b/tools/tools/locale/tools/finalize
index 23afaddafa9b..b4dc38360451 100755
--- a/tools/tools/locale/tools/finalize
+++ b/tools/tools/locale/tools/finalize
@@ -69,64 +69,69 @@ AWKCMD="/## PLACEHOLDER/ { \
while ( getline line < \"${TEMP4}\" ) {print line} } \
!/## / { print \$0 }"
-# Rename the sources with 3 components name into the POSIX version of the name using @modifier
-mkdir -p $old $new
-cd $old
-pwd
-for i in *_*_*.*.src; do
- if [ "$i" = "*_*_*.*.src" ]; then
- break
- fi
- oldname=${i%.*}
- nname=`echo $oldname | awk '{ split($0, a, "_"); print a[1]"_"a[3]"@"a[2];} '`
- mv -f ${oldname}.src ${nname}.src
- sed -i '' -e "s/${oldname}/${nname}/g" Makefile
-done
-
-# For variable without @modifier ambiguity do not keep the @modifier
-for i in *@*.src; do
- if [ "$i" = "*@*.src" ]; then
- break
- fi
- oldname=${i%.*}
- shortname=${oldname%@*}
- if [ $(ls ${shortname}@* | wc -l) -eq 1 ] ; then
- mv -f $i ${shortname}.src
- sed -i '' -e "s/${oldname}/${shortname}/g" Makefile
- fi
-done
-
-# Rename the modifiers into non abbreviated version
-for i in *@Latn.src; do
- if [ "$i" = "*@Latn.src" ]; then
- break
- fi
- mv -f ${i} ${i%@*}@latin.src
- sed -i '' -e "s/${i%.*}/${i%@*}@latin/g" Makefile
-done
-
-for i in *@Cyrl.src; do
- if [ "$i" = "*@Cyrl.src" ]; then
- break
- fi
- mv -f ${i} ${i%@*}@cyrillic.src
- sed -i '' -e "s/${i%.*}/${i%@*}@cyrillic/g" Makefile
-done
-
-# On locales with multiple modifiers rename the "default" version without the @modifier
-default_locales="sr_RS@cyrillic"
-for i in ${default_locales}; do
- localename=${i%@*}
- mod=${i#*@}
- for l in ${localename}.*@${mod}.src; do
- if [ "$l" = "${localename}.*@${mod}.src" ]; then
+if ! find "$old" -name "*_*_*.*.src" -type f -print -quit | grep -q .; then
+ exit
+fi
+
+mkdir -p $new
+(
+ cd $old
+
+ # Rename the sources with 3 components name into the POSIX version of the name using @modifier
+ for i in *_*_*.*.src; do
+ if [ "$i" = "*_*_*.*.src" ]; then
+ break
+ fi
+ oldname=${i%.*}
+ nname=`echo $oldname | awk '{ split($0, a, "_"); print a[1]"_"a[3]"@"a[2];} '`
+ mv -f ${oldname}.src ${nname}.src
+ sed -i '' -e "s/${oldname}/${nname}/g" Makefile
+ done
+
+ # For variable without @modifier ambiguity do not keep the @modifier
+ for i in *@*.src; do
+ if [ "$i" = "*@*.src" ]; then
+ break
+ fi
+ oldname=${i%.*}
+ shortname=${oldname%@*}
+ if [ $(ls ${shortname}@* | wc -l) -eq 1 ] ; then
+ mv -f $i ${shortname}.src
+ sed -i '' -e "s/${oldname}/${shortname}/g" Makefile
+ fi
+ done
+
+ # Rename the modifiers into non abbreviated version
+ for i in *@Latn.src; do
+ if [ "$i" = "*@Latn.src" ]; then
break
fi
- mv -f ${l} ${l%@*}.src
- sed -i '' -e "s/${l%.*}/${l%@*}/g" Makefile
+ mv -f ${i} ${i%@*}@latin.src
+ sed -i '' -e "s/${i%.*}/${i%@*}@latin/g" Makefile
+ done
+
+ for i in *@Cyrl.src; do
+ if [ "$i" = "*@Cyrl.src" ]; then
+ break
+ fi
+ mv -f ${i} ${i%@*}@cyrillic.src
+ sed -i '' -e "s/${i%.*}/${i%@*}@cyrillic/g" Makefile
+ done
+
+ # On locales with multiple modifiers rename the "default" version without the @modifier
+ default_locales="sr_RS@cyrillic"
+ for i in ${default_locales}; do
+ localename=${i%@*}
+ mod=${i#*@}
+ for l in ${localename}.*@${mod}.src; do
+ if [ "$l" = "${localename}.*@${mod}.src" ]; then
+ break
+ fi
+ mv -f ${l} ${l%@*}.src
+ sed -i '' -e "s/${l%.*}/${l%@*}/g" Makefile
+ done
done
-done
-cd -
+)
grep '^LOCALES+' ${old}/Makefile > ${TEMP}