Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 2/4] EAPI 6: Enforce LC_COLLATE=C in ebuild environment
Date: Sun, 15 Nov 2015 21:17:50
Message-Id: 1447622247-9347-2-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 1/4] Warn if LC_CTYPE does not transform ASCII chars like POSIX by "Michał Górny"
1 ---
2 pym/portage/eapi.py | 9 +++++++--
3 pym/portage/package/ebuild/config.py | 5 +++++
4 pym/portage/util/locale.py | 21 +++++++++++++++++++++
5 3 files changed, 33 insertions(+), 2 deletions(-)
6
7 diff --git a/pym/portage/eapi.py b/pym/portage/eapi.py
8 index 4f77910..1709026 100644
9 --- a/pym/portage/eapi.py
10 +++ b/pym/portage/eapi.py
11 @@ -1,4 +1,4 @@
12 -# Copyright 2010-2012 Gentoo Foundation
13 +# Copyright 2010-2015 Gentoo Foundation
14 # Distributed under the terms of the GNU General Public License v2
15
16 import collections
17 @@ -68,6 +68,10 @@ def eapi_has_required_use_at_most_one_of(eapi):
18 def eapi_has_use_dep_defaults(eapi):
19 return eapi not in ("0", "1", "2", "3")
20
21 +def eapi_requires_posixish_locale(eapi):
22 + return eapi not in ("0", "1", "2", "3", "4", "4-python", "4-slot-abi",
23 + "5", "5-progress", "5-hdepend")
24 +
25 def eapi_has_repo_deps(eapi):
26 return eapi in ("4-python", "5-progress")
27
28 @@ -98,7 +102,7 @@ def eapi_has_targetroot(eapi):
29 _eapi_attrs = collections.namedtuple('_eapi_attrs',
30 'dots_in_PN dots_in_use_flags exports_EBUILD_PHASE_FUNC '
31 'feature_flag_test feature_flag_targetroot '
32 - 'hdepend iuse_defaults iuse_effective '
33 + 'hdepend iuse_defaults iuse_effective posixish_locale '
34 'repo_deps required_use required_use_at_most_one_of slot_operator slot_deps '
35 'src_uri_arrows strong_blocks use_deps use_dep_defaults')
36
37 @@ -129,6 +133,7 @@ def _get_eapi_attrs(eapi):
38 hdepend = (eapi is not None and eapi_has_hdepend(eapi)),
39 iuse_defaults = (eapi is None or eapi_has_iuse_defaults(eapi)),
40 iuse_effective = (eapi is not None and eapi_has_iuse_effective(eapi)),
41 + posixish_locale = (eapi is not None and eapi_requires_posixish_locale(eapi)),
42 repo_deps = (eapi is None or eapi_has_repo_deps(eapi)),
43 required_use = (eapi is None or eapi_has_required_use(eapi)),
44 required_use_at_most_one_of = (eapi is None or eapi_has_required_use_at_most_one_of(eapi)),
45 diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
46 index 40aa99d..095de37 100644
47 --- a/pym/portage/package/ebuild/config.py
48 +++ b/pym/portage/package/ebuild/config.py
49 @@ -24,6 +24,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
50 'portage.dep.soname.SonameAtom:SonameAtom',
51 'portage.dbapi.vartree:vartree',
52 'portage.package.ebuild.doebuild:_phase_func_map',
53 + 'portage.util.locale:split_LC_ALL',
54 )
55 from portage import bsd_chflags, \
56 load_mod, os, selinux, _unicode_decode
57 @@ -2769,6 +2770,10 @@ class config(object):
58 if phase_func is not None:
59 mydict["EBUILD_PHASE_FUNC"] = phase_func
60
61 + if eapi_attrs.posixish_locale:
62 + split_LC_ALL(mydict)
63 + mydict["LC_COLLATE"] = "C"
64 +
65 return mydict
66
67 def thirdpartymirrors(self):
68 diff --git a/pym/portage/util/locale.py b/pym/portage/util/locale.py
69 index 529db35..7b13ec7 100644
70 --- a/pym/portage/util/locale.py
71 +++ b/pym/portage/util/locale.py
72 @@ -18,6 +18,15 @@ from portage.util import writemsg_level
73 from portage.util._ctypes import find_library, LoadLibrary
74
75
76 +locale_categories = (
77 + 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_MESSAGES',
78 + 'LC_NUMERIC', 'LC_TIME',
79 + # GNU extensions
80 + 'LC_ADDRESS', 'LC_IDENTIFICATION', 'LC_MEASUREMENT', 'LC_NAME',
81 + 'LC_PAPER', 'LC_TELEPHONE',
82 +)
83 +
84 +
85 def _check_locale():
86 """
87 The inner locale check function.
88 @@ -89,3 +98,15 @@ def check_locale():
89 if ret != 2:
90 return ret == 0
91 return None
92 +
93 +
94 +def split_LC_ALL(env):
95 + """
96 + Replace LC_ALL with split-up LC_* variables if it is defined.
97 + Works on the passed environment (or settings instance).
98 + """
99 + lc_all = env.get("LC_ALL")
100 + if lc_all is not None:
101 + for c in locale_categories:
102 + env[c] = lc_all
103 + del env["LC_ALL"]
104 --
105 2.6.3