Skip to content
Snippets Groups Projects
Commit e69ce85e authored by Simon McVittie's avatar Simon McVittie
Browse files

locale-gen: Add --output-dir option


At the moment it writes to the current working directory, and we invoke
it via `bwrap ... --chdir DIRECTORY`; but we want to make it possible to
use this code from inside a Flatpak runtime (at least in the case where
we're using the host system's glibc), which means we won't be allowed
to run bwrap and must do this some other way.

Rather than using `env --chdir=...` (which isn't supported in scout
anyway), let's teach this script to output to an explicitly specified
directory.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 5de30633
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ me="$(readlink -f "$0")"
here="${me%/*}"
me="${me##*/}"
opt_output_dir=.
opt_verbose=
# Look for try-setlocale helper executable next to this script
......@@ -125,9 +126,10 @@ generate_locale () {
if [ "${codeset}" = 'utf8' ]; then
codeset="UTF-8"
locale="${language}${underscore_territory}.UTF-8${at_modifier}"
ln -fns "$locale" "${language}${underscore_territory}.utf8${at_modifier}"
ln -fns "$locale" \
"${opt_output_dir}/${language}${underscore_territory}.utf8${at_modifier}"
if [ -d "$locale" ]; then
if [ -d "$opt_output_dir/$locale" ]; then
return 0
fi
fi
......@@ -179,7 +181,7 @@ generate_locale () {
-c \
-f "$codeset" \
-i "$without_codeset" \
./"${locale}" \
"${opt_output_dir}/${locale}" \
; then
log "Generated locale $locale successfully"
else
......@@ -192,7 +194,7 @@ generate_locale () {
fi
fi
if ! LOCPATH="$(pwd)" pressure-vessel-try-setlocale "$locale"; then
if ! LOCPATH="${opt_output_dir}" pressure-vessel-try-setlocale "$locale"; then
log "Warning: $locale was generated but does not appear to work!"
fi
}
......@@ -212,6 +214,8 @@ usage () {
echo "in the current working directory."
echo
echo "Options:"
echo "--output-dir DIR, -o DIR"
echo " Create locales in the given directory [default: .]"
echo "--verbose Be more verbose"
echo
echo "Arguments:"
......@@ -221,14 +225,20 @@ usage () {
}
getopt_temp="help"
getopt_temp="${getopt_temp},output-dir:,output-directory:"
getopt_temp="${getopt_temp},verbose"
getopt_temp="$(getopt -o '' --long "$getopt_temp" -n "$me" -- "$@")"
getopt_temp="$(getopt -o 'o:' --long "$getopt_temp" -n "$me" -- "$@")"
eval "set -- $getopt_temp"
unset getopt_temp
while [ "$#" -gt 0 ]; do
case "$1" in
(-o | --output-dir | --output-directory)
opt_output_dir="$2"
shift 2
;;
(--help)
usage 0
# not reached
......
......@@ -89,6 +89,7 @@ locale_gen="pressure-vessel-locale-gen"
try_setlocale="pressure-vessel-try-setlocale"
mkdir "$tmpdir/1"
mkdir "$tmpdir/cwd"
one_missing=
......@@ -128,7 +129,7 @@ else
# Deliberately setting environment variables in subshell:
# shellcheck disable=SC2030
(
cd "$tmpdir/1"
cd "$tmpdir/cwd"
export LC_CTYPE=cy_GB.utf8
export LC_COLLATE=cs_CZ
export LC_IDENTIFICATION=it_IT@euro
......@@ -144,7 +145,7 @@ else
export HOST_LC_ALL=hu_HU.UTF-8
export LANG=en_DK
export LC_ALL=en_AU.UTF-8
"$locale_gen"
"$locale_gen" --output-dir "$tmpdir/1"
) || failed="$?"
if [ "$failed" = 72 ]; then
......@@ -179,6 +180,13 @@ else
not_ok "$tmpdir/1/$locale/LC_IDENTIFICATION not generated"
fi
done
for x in "$tmpdir/cwd"/*; do
if [ -e "$x" ]; then
not_ok "$locale_gen generated $x in current working directory"
failed=yes
fi
done
fi
mkdir "$tmpdir/2"
......@@ -189,7 +197,7 @@ if "$try_setlocale" "en_US.UTF-8" >/dev/null; then
# Deliberately setting environment variables in subshell:
# shellcheck disable=SC2031
(
cd "$tmpdir/2"
cd "$tmpdir/cwd"
unset LC_CTYPE
unset LC_COLLATE
unset LC_IDENTIFICATION
......@@ -205,7 +213,7 @@ if "$try_setlocale" "en_US.UTF-8" >/dev/null; then
export HOST_LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
"$locale_gen"
"$locale_gen" --output-dir "$tmpdir/2"
) || failed=yes
if [ -n "$failed" ]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment