Normalize LANG / LC_* environment

This ensures that the current locale supports UTF-8, and that we're
getting a consistent (but still supported by the system) locale for
every configuration except user-facing messages. This should eliminate
any reproducibility problems around sorting, formatting, etc for all
built products, while still showing localized error messages where
available.

Bug: 71573630
Test: LANG=es_ES LANGUAGE=es: m   (check env in soong.log)
Change-Id: If33311899eaed8c44573113ee35c5a71cee503a0
This commit is contained in:
Dan Willemsen
2018-01-08 14:58:46 -08:00
parent c1fecc2dfa
commit ed86952403
2 changed files with 60 additions and 0 deletions

View File

@@ -63,6 +63,18 @@ func (e *Environment) Unset(keys ...string) {
*e = out
}
// UnsetWithPrefix removes all keys that start with prefix.
func (e *Environment) UnsetWithPrefix(prefix string) {
out := (*e)[:0]
for _, env := range *e {
if key, _, ok := decodeKeyValue(env); ok && strings.HasPrefix(key, prefix) {
continue
}
out = append(out, env)
}
*e = out
}
// Environ returns the []string required for exec.Cmd.Env
func (e *Environment) Environ() []string {
return []string(*e)