From 8f093007041aa7c49d32134cd1d9148ca2d28c96 Mon Sep 17 00:00:00 2001 From: Takahiro Ueda Date: Tue, 4 Jun 2024 22:16:07 +0900 Subject: [PATCH] fix(build): update git-version-gen script to use LC_ALL Replace LANG with LC_ALL as the locale setting to ensure consistent date formatting, because LANG can be overridden by LC_TIME or LC_ALL. Also add --date-locale and --date-timezone command line options. --- scripts/git-version-gen.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/git-version-gen.sh b/scripts/git-version-gen.sh index 61837b7d..132d937a 100755 --- a/scripts/git-version-gen.sh +++ b/scripts/git-version-gen.sh @@ -25,7 +25,9 @@ Options: -s, --shell shell script output -v, --only-version only-version output -o , --output output to - --date-format date format (default: '%b %e %Y') + --date-format date format (default: '%b %e %Y' as __DATE__) + --date-locale date locale (default: C) + --date-timezone date timezone (default: GMT0) END } @@ -33,7 +35,7 @@ END # fmt_isodate fmt_isodate() { # dash (0.5.5.1) needs the following exports. - export LANG + export LC_ALL export TZ # BSD date date -j -f '%Y-%m-%d %H:%M:%S %z' "$1" +"$2" 2>/dev/null || @@ -56,6 +58,8 @@ refdir=$rootdir mode=raw output_file= date_format='%b %e %Y' +date_locale=C +date_timezone=GMT0 # for better compatibility than UTC0 next= for a in "$@"; do @@ -93,6 +97,12 @@ for a in "$@"; do --date-format) next=date_format ;; + --date-locale) + next=date_locale + ;; + --date-timezone) + next=date_timezone + ;; *) echo "$prog: error: unknown option $a" >&2 exit 1 @@ -140,12 +150,12 @@ if [ "$mode" != "only-version" ]; then if git_C diff-index --quiet HEAD .; then # If the working tree is not dirty, use the latest commit date. isodate=$(git_C log -1 --pretty=%ci .) - date=$(LANG=C TZ=UTC fmt_isodate "$isodate" "$date_format") + date=$(LC_ALL="$date_locale" TZ="$date_timezone" fmt_isodate "$isodate" "$date_format") else # If the working tree is dirty, suffix "-dirty" to the revision identifier # and use the current date time. revision="$revision-dirty" - date=$(LANG=C TZ=UTC date +"$date_format") + date=$(LC_ALL="$date_locale" TZ="$date_timezone" date +"$date_format") fi # Version description. # Examples: "4.3.0", "v4.3.0-1-g7c9706c"