From 139a2cfae92e3749dbc957ab5fa5a2494a9a20b9 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Tue, 11 May 2021 12:00:03 +0200 Subject: [PATCH] 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 --- tool/abi_symbols | 2 +- tool/builddir/build.mk | 3 --- tool/check_abi | 2 +- tool/depot/mk/common.inc | 2 +- tool/depot/mk/extract.inc | 4 ++-- tool/depot/mk/extract_post_dependencies.inc | 2 +- tool/ports/mk/common.inc | 3 --- 7 files changed, 6 insertions(+), 12 deletions(-) diff --git a/tool/abi_symbols b/tool/abi_symbols index 5e6534755e..9867b70c06 100755 --- a/tool/abi_symbols +++ b/tool/abi_symbols @@ -11,7 +11,7 @@ # # normalize sort order across platforms -set env(LC_COLLATE) C +set env(LC_ALL) C # obtain symbol information via 'nm' set symbols [exec nm --format posix --dynamic $argv | sort] diff --git a/tool/builddir/build.mk b/tool/builddir/build.mk index 6b6f2e2e54..f8f00f3596 100644 --- a/tool/builddir/build.mk +++ b/tool/builddir/build.mk @@ -67,9 +67,6 @@ export ECHO ?= echo -e export CONTRIB_DIR export BOARD -# Force stable sorting order -export LC_COLLATE=C - # # Convert user-defined directories to absolute directories # diff --git a/tool/check_abi b/tool/check_abi index 8b14537783..3c25f523ca 100755 --- a/tool/check_abi +++ b/tool/check_abi @@ -12,7 +12,7 @@ # # normalize sort order across platforms -set env(LC_COLLATE) C +set env(LC_ALL) C set lib_path [lindex $argv 0] set abi_path [lindex $argv 1] diff --git a/tool/depot/mk/common.inc b/tool/depot/mk/common.inc index 71b3b41716..d77d89834a 100644 --- a/tool/depot/mk/common.inc +++ b/tool/depot/mk/common.inc @@ -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 diff --git a/tool/depot/mk/extract.inc b/tool/depot/mk/extract.inc index 66b0032465..e2390e0a89 100644 --- a/tool/depot/mk/extract.inc +++ b/tool/depot/mk/extract.inc @@ -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/ .*//" # diff --git a/tool/depot/mk/extract_post_dependencies.inc b/tool/depot/mk/extract_post_dependencies.inc index d1f06e8234..8c43918687 100644 --- a/tool/depot/mk/extract_post_dependencies.inc +++ b/tool/depot/mk/extract_post_dependencies.inc @@ -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)) # diff --git a/tool/ports/mk/common.inc b/tool/ports/mk/common.inc index b4e420d85d..9c0a431b71 100644 --- a/tool/ports/mk/common.inc +++ b/tool/ports/mk/common.inc @@ -28,9 +28,6 @@ MSG_GENERATE := $(MSG_PREFIX)"generate " MSG_EXTRACT := $(MSG_PREFIX)"extract " MSG_GIT := $(MSG_PREFIX_TXT)git -# Force stable sorting order -export LC_COLLATE=C - # # Utility to check if a tool is installed #