tool: use local LC_ALL=C instead of LC_COLLATE=C

We used to export 'LC_COLLATE=C' for the environment of Genode tools. This was
meant to ensure that sorting is always done C-style and not dependent on the
users locale settings. This is required, for instance, to ensure that the same
archive always yields the same hash.

However, 'export LC_COLLATE=C' is not sufficient. It can be outruled by an
'LC_ALL' setting in the users environment. The manual of 'sort' recommends to
set 'LC_ALL=C' locally if you want reliable results and this is what this
commit does. Furthermore it removes the former 'export LC_COLLATE=C'
directives.

Note that I couldn't find a way to set 'LC_ALL' local to 'exec ... sort' in
TCL. This is why I set it global instead using TCLs 'env' array.

Note that the Make directive '$(sort ...)' and the TCL directive 'lsort',
unlike the Shell directive 'sort', are not affected by the users locale
settings.

Fixes #4144
This commit is contained in:
Martin Stein 2021-05-11 12:00:03 +02:00 committed by Christian Helmuth
parent 1c20ed12c1
commit 139a2cfae9
7 changed files with 6 additions and 12 deletions

View File

@ -11,7 +11,7 @@
# #
# normalize sort order across platforms # normalize sort order across platforms
set env(LC_COLLATE) C set env(LC_ALL) C
# obtain symbol information via 'nm' # obtain symbol information via 'nm'
set symbols [exec nm --format posix --dynamic $argv | sort] set symbols [exec nm --format posix --dynamic $argv | sort]

View File

@ -67,9 +67,6 @@ export ECHO ?= echo -e
export CONTRIB_DIR export CONTRIB_DIR
export BOARD export BOARD
# Force stable sorting order
export LC_COLLATE=C
# #
# Convert user-defined directories to absolute directories # Convert user-defined directories to absolute directories
# #

View File

@ -12,7 +12,7 @@
# #
# normalize sort order across platforms # normalize sort order across platforms
set env(LC_COLLATE) C set env(LC_ALL) C
set lib_path [lindex $argv 0] set lib_path [lindex $argv 0]
set abi_path [lindex $argv 1] set abi_path [lindex $argv 1]

View File

@ -32,4 +32,4 @@ EMPTY :=
file_content = $(if $(wildcard $1),$(shell cat $1),) file_content = $(if $(wildcard $1),$(shell cat $1),)
# Force stable sorting order # Force stable sorting order
export LC_COLLATE=C SORT := LC_ALL=C sort

View File

@ -214,8 +214,8 @@ _check_hash: $(DEPOT_ARCHIVE_DIR).hash checked_recipe_hash_value_exists
# command). # command).
# #
HASH_CMD := cd $(DEPOT_ARCHIVE_DIR); \ HASH_CMD := cd $(DEPOT_ARCHIVE_DIR); \
(find . -type f | sort; \ (find . -type f | $(SORT); \
find . -type f | sort | xargs -d '\n' cat) \ find . -type f | $(SORT) | xargs -d '\n' cat) \
| $(HASHSUM) | sed "s/ .*//" | $(HASHSUM) | sed "s/ .*//"
# #

View File

@ -34,7 +34,7 @@ endif
# #
# \param $1 absolute file path # \param $1 absolute file path
# #
sorted_file_content = $(if $(wildcard $1),$(shell cat $1 | sort -u),\ sorted_file_content = $(if $(wildcard $1),$(shell cat $1 | $(SORT) -u),\
$(error Failed to read file $1)) $(error Failed to read file $1))
# #

View File

@ -28,9 +28,6 @@ MSG_GENERATE := $(MSG_PREFIX)"generate "
MSG_EXTRACT := $(MSG_PREFIX)"extract " MSG_EXTRACT := $(MSG_PREFIX)"extract "
MSG_GIT := $(MSG_PREFIX_TXT)git MSG_GIT := $(MSG_PREFIX_TXT)git
# Force stable sorting order
export LC_COLLATE=C
# #
# Utility to check if a tool is installed # Utility to check if a tool is installed
# #