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/2] EAPI 6: Enforce LC_COLLATE=C in ebuild environment
Date: Sat, 14 Nov 2015 22:57:08
Message-Id: 1447541806-16108-2-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 1/2] 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/doebuild.py | 8 +++++++-
4 pym/portage/util/locale.py | 21 +++++++++++++++++++++
5 3 files changed, 35 insertions(+), 3 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/doebuild.py b/pym/portage/package/ebuild/doebuild.py
46 index ff8958e..67704cc 100644
47 --- a/pym/portage/package/ebuild/doebuild.py
48 +++ b/pym/portage/package/ebuild/doebuild.py
49 @@ -33,6 +33,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
50 'portage.package.ebuild.fetch:fetch',
51 'portage.package.ebuild._ipc.QueryCommand:QueryCommand',
52 'portage.dep._slot_operator:evaluate_slot_operator_equal_deps',
53 + 'portage.eapi:eapi_requires_posixish_locale',
54 'portage.package.ebuild._spawn_nofetch:spawn_nofetch',
55 'portage.util.elf.header:ELFHeader',
56 'portage.dep.soname.multilib_category:compute_multilib_category',
57 @@ -42,7 +43,8 @@ portage.proxy.lazyimport.lazyimport(globals(),
58 'portage.util._async.SchedulerInterface:SchedulerInterface',
59 'portage.util._eventloop.EventLoop:EventLoop',
60 'portage.util._eventloop.global_event_loop:global_event_loop',
61 - 'portage.util.ExtractKernelVersion:ExtractKernelVersion'
62 + 'portage.util.ExtractKernelVersion:ExtractKernelVersion',
63 + 'portage.util.locale:split_LC_ALL',
64 )
65
66 from portage import bsd_chflags, \
67 @@ -433,6 +435,10 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
68 if not eapi_is_supported(eapi):
69 raise UnsupportedAPIException(mycpv, eapi)
70
71 + if eapi_requires_posixish_locale(eapi):
72 + split_LC_ALL(mysettings)
73 + mysettings["LC_COLLATE"] = "C"
74 +
75 if eapi_exports_REPOSITORY(eapi) and "PORTAGE_REPO_NAME" in mysettings.configdict["pkg"]:
76 mysettings.configdict["pkg"]["REPOSITORY"] = mysettings.configdict["pkg"]["PORTAGE_REPO_NAME"]
77
78 diff --git a/pym/portage/util/locale.py b/pym/portage/util/locale.py
79 index 6919ceb..570f6f0 100644
80 --- a/pym/portage/util/locale.py
81 +++ b/pym/portage/util/locale.py
82 @@ -16,6 +16,15 @@ from portage.util import writemsg_level
83 from portage.util._ctypes import find_library, LoadLibrary
84
85
86 +locale_categories = (
87 + 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_MESSAGES',
88 + 'LC_NUMERIC', 'LC_TIME',
89 + # GNU extensions
90 + 'LC_ADDRESS', 'LC_IDENTIFICATION', 'LC_MEASUREMENT', 'LC_NAME',
91 + 'LC_PAPER', 'LC_TELEPHONE',
92 +)
93 +
94 +
95 def check_locale():
96 """
97 Check whether the locale is sane. Returns True if it is, prints
98 @@ -61,3 +70,15 @@ def check_locale():
99 return False
100
101 return True
102 +
103 +
104 +def split_LC_ALL(env):
105 + """
106 + Replace LC_ALL with split-up LC_* variables if it is defined.
107 + Works on the passed environment (or settings instance).
108 + """
109 + lc_all = env.get("LC_ALL")
110 + if lc_all is not None:
111 + for c in locale_categories:
112 + env[c] = lc_all
113 + del env["LC_ALL"]
114 --
115 2.6.3

Replies