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

@@ -32,4 +32,4 @@ EMPTY :=
file_content = $(if $(wildcard $1),$(shell cat $1),)
# 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).
#
HASH_CMD := cd $(DEPOT_ARCHIVE_DIR); \
(find . -type f | sort; \
find . -type f | sort | xargs -d '\n' cat) \
(find . -type f | $(SORT); \
find . -type f | $(SORT) | xargs -d '\n' cat) \
| $(HASHSUM) | sed "s/ .*//"
#

View File

@@ -34,7 +34,7 @@ endif
#
# \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))
#