Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Dec 2025 04:15:22 +0000
From:      Jose Luis Duran <jlduran@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 438c3249fb61 - stable/15 - locale: tools: Make finalize idempotent
Message-ID:  <693ce85a.3983c.412f43a3@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help

The branch stable/15 has been updated by jlduran:

URL: https://cgit.FreeBSD.org/src/commit/?id=438c3249fb612d1d264bb122ec70b5a66b462acd

commit 438c3249fb612d1d264bb122ec70b5a66b462acd
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-13 04:14:07 +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
    
    (cherry picked from commit 934364da7fc8cd3ba4d030d0478163b41dda1b37)
---
 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}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?693ce85a.3983c.412f43a3>