mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 06:31:18 +02:00
enter_chroot: speed up entering by backgrounding locale generation
Half of the current time is spent on calling locale-gen even when there is nothing to be done (all locales already generated). Throw it into the bg to unblock the main thread. BUG=None TEST=`cros_sdk` still works TEST=`LANG=et_EE.UTF-8 cros_sdk` generates the new locale in the background Change-Id: Ibe9a07bec60a59cab1cf4230358f7f8ff5b21c2e Reviewed-on: https://gerrit.chromium.org/gerrit/58041 Reviewed-by: David James <davidjames@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
7f30c14bdc
commit
4bdab9f7fe
@ -197,6 +197,38 @@ promote_api_keys() {
|
||||
fi
|
||||
}
|
||||
|
||||
generate_locales() {
|
||||
# Make sure user's requested locales are available
|
||||
# http://crosbug.com/19139
|
||||
# And make sure en_US{,.UTF-8} are always available as
|
||||
# that what buildbot forces internally
|
||||
local l locales gen_locales=()
|
||||
|
||||
locales=$(printf '%s\n' en_US en_US.UTF-8 ${LANG} \
|
||||
$LC_{ADDRESS,ALL,COLLATE,CTYPE,IDENTIFICATION,MEASUREMENT,MESSAGES} \
|
||||
$LC_{MONETARY,NAME,NUMERIC,PAPER,TELEPHONE,TIME} | \
|
||||
sort -u | sed '/^C$/d')
|
||||
for l in ${locales}; do
|
||||
if [[ ${l} == *.* ]]; then
|
||||
enc=${l#*.}
|
||||
else
|
||||
enc="ISO-8859-1"
|
||||
fi
|
||||
case $(echo ${enc//-} | tr '[:upper:]' '[:lower:]') in
|
||||
utf8) enc="UTF-8";;
|
||||
esac
|
||||
gen_locales+=("${l} ${enc}")
|
||||
done
|
||||
if [[ ${#gen_locales[@]} -gt 0 ]] ; then
|
||||
# Force LC_ALL=C to workaround slow string parsing in bash
|
||||
# with long multibyte strings. Newer setups have this fixed,
|
||||
# but locale-gen doesn't need to be run in any locale in the
|
||||
# first place, so just go with C to keep it fast.
|
||||
chroot "${FLAGS_chroot}" env LC_ALL=C locale-gen -q -u \
|
||||
-G "$(printf '%s\n' "${gen_locales[@]}")"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_env() {
|
||||
(
|
||||
flock 200
|
||||
@ -221,6 +253,9 @@ setup_env() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# Do this early as it's slow and only needs basic mounts (above).
|
||||
generate_locales &
|
||||
|
||||
setup_mount "${FLAGS_trunk}" "--rbind" "${CHROOT_TRUNK_DIR}"
|
||||
|
||||
debug "Setting up referenced repositories if required."
|
||||
@ -402,35 +437,6 @@ setup_env() {
|
||||
done
|
||||
promote_api_keys
|
||||
|
||||
# Make sure user's requested locales are available
|
||||
# http://crosbug.com/19139
|
||||
# And make sure en_US{,.UTF-8} are always available as
|
||||
# that what buildbot forces internally
|
||||
locales=$(printf '%s\n' en_US en_US.UTF-8 ${LANG} \
|
||||
$LC_{ADDRESS,ALL,COLLATE,CTYPE,IDENTIFICATION,MEASUREMENT,MESSAGES} \
|
||||
$LC_{MONETARY,NAME,NUMERIC,PAPER,TELEPHONE,TIME} | \
|
||||
sort -u | sed '/^C$/d')
|
||||
gen_locales=()
|
||||
for l in ${locales}; do
|
||||
if [[ ${l} == *.* ]]; then
|
||||
enc=${l#*.}
|
||||
else
|
||||
enc="ISO-8859-1"
|
||||
fi
|
||||
case $(echo ${enc//-} | tr '[:upper:]' '[:lower:]') in
|
||||
utf8) enc="UTF-8";;
|
||||
esac
|
||||
gen_locales=("${gen_locales[@]}" "${l} ${enc}")
|
||||
done
|
||||
if [[ ${#gen_locales[@]} -gt 0 ]] ; then
|
||||
# Force LC_ALL=C to workaround slow string parsing in bash
|
||||
# with long multibyte strings. Newer setups have this fixed,
|
||||
# but locale-gen doesn't need to be run in any locale in the
|
||||
# first place, so just go with C to keep it fast.
|
||||
chroot "$FLAGS_chroot" env LC_ALL=C locale-gen -q -u \
|
||||
-G "$(printf '%s\n' "${gen_locales[@]}")"
|
||||
fi
|
||||
|
||||
# Fix permissions on shared memory to allow non-root users access to POSIX
|
||||
# semaphores.
|
||||
chmod -R 777 "${FLAGS_chroot}/dev/shm"
|
||||
|
Loading…
x
Reference in New Issue
Block a user