Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH v2] Add emerge --with-test-deps option for bug #520652
Date: Thu, 20 Nov 2014 10:06:08
Message-Id: 1416477956-26189-1-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] Add emerge --with-test-deps option for bug #520652 by Zac Medico
1 For packages matched by arguments, this option will pull in dependencies
2 that are conditional on the "test" USE flag, even if FEATURES=test is not
3 enabled for the matched packages. The state of the "test" USE flag is not
4 affected by this option. It only changes the effective dependencies
5 which are processed by the depgraph._add_pkg_deps method.
6
7 X-Gentoo-Bug: 520652
8 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=520652
9 ---
10 PATCH v2 fixes the code in _add_pkg_deps to use _pkg_use_enabled instead
11 of accessing pkg.use.unabled directly (we should not bypass
12 _pkg_use_enabled unless there is a very good reason for it).
13
14 man/emerge.1 | 8 ++++-
15 pym/_emerge/create_depgraph_params.py | 5 +++
16 pym/_emerge/depgraph.py | 24 +++++++++++--
17 pym/_emerge/main.py | 11 ++++++
18 pym/portage/tests/resolver/test_with_test_deps.py | 44 +++++++++++++++++++++++
19 5 files changed, 89 insertions(+), 3 deletions(-)
20 create mode 100644 pym/portage/tests/resolver/test_with_test_deps.py
21
22 diff --git a/man/emerge.1 b/man/emerge.1
23 index bbe71ac..a206e8e 100644
24 --- a/man/emerge.1
25 +++ b/man/emerge.1
26 @@ -1,4 +1,4 @@
27 -.TH "EMERGE" "1" "Oct 2014" "Portage VERSION" "Portage"
28 +.TH "EMERGE" "1" "Nov 2014" "Portage VERSION" "Portage"
29 .SH "NAME"
30 emerge \- Command\-line interface to the Portage system
31 .SH "SYNOPSIS"
32 @@ -894,6 +894,12 @@ installation actions, meaning they will not be installed, and
33 This setting can be added to
34 \fBEMERGE_DEFAULT_OPTS\fR (see make.conf(5)) and later overridden via the
35 command line.
36 +.TP
37 +.BR "\-\-with\-test\-deps [ y | n ]"
38 +For packages matched by arguments, this option will pull in dependencies
39 +that are conditional on the "test" USE flag, even if "test" is not
40 +enabled in \fBFEATURES\fR for the matched packages. (see \fBmake.conf\fR(5)
41 +for more information about \fBFEATURES\fR settings).
42 .SH "ENVIRONMENT OPTIONS"
43 .TP
44 \fBEPREFIX\fR = \fI[path]\fR
45 diff --git a/pym/_emerge/create_depgraph_params.py b/pym/_emerge/create_depgraph_params.py
46 index 225b792..6f74de7 100644
47 --- a/pym/_emerge/create_depgraph_params.py
48 +++ b/pym/_emerge/create_depgraph_params.py
49 @@ -21,6 +21,7 @@ def create_depgraph_params(myopts, myaction):
50 # removal by the --depclean action as soon as possible
51 # ignore_built_slot_operator_deps: ignore the slot/sub-slot := operator parts
52 # of dependencies that have been recorded when packages where built
53 + # with_test_deps: pull in test deps for packages matched by arguments
54 myparams = {"recurse" : True}
55
56 bdeps = myopts.get("--with-bdeps")
57 @@ -104,6 +105,10 @@ def create_depgraph_params(myopts, myaction):
58 # other option like --update.
59 myparams.pop("selective", None)
60
61 + with_test_deps = myopts.get("--with-test-deps")
62 + if with_test_deps is not None:
63 + myparams["with_test_deps"] = with_test_deps
64 +
65 if '--debug' in myopts:
66 writemsg_level('\n\nmyparams %s\n\n' % myparams,
67 noiselevel=-1, level=logging.DEBUG)
68 diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py
69 index 6f1910d..505d8a8 100644
70 --- a/pym/_emerge/depgraph.py
71 +++ b/pym/_emerge/depgraph.py
72 @@ -2699,6 +2699,20 @@ class depgraph(object):
73 for k in Package._dep_keys:
74 edepend[k] = metadata[k]
75
76 + use_enabled = self._pkg_use_enabled(pkg)
77 +
78 + with_test_deps = not removal_action and \
79 + "with_test_deps" in \
80 + self._dynamic_config.myparams and \
81 + pkg.depth == 0 and \
82 + "test" not in use_enabled and \
83 + pkg.iuse.is_valid_flag("test") and \
84 + self._is_argument(pkg)
85 +
86 + if with_test_deps:
87 + use_enabled = set(use_enabled)
88 + use_enabled.add("test")
89 +
90 if not pkg.built and \
91 "--buildpkgonly" in self._frozen_config.myopts and \
92 "deep" not in self._dynamic_config.myparams:
93 @@ -2782,7 +2796,7 @@ class depgraph(object):
94
95 try:
96 dep_string = portage.dep.use_reduce(dep_string,
97 - uselist=self._pkg_use_enabled(pkg),
98 + uselist=use_enabled,
99 is_valid_flag=pkg.iuse.is_valid_flag,
100 opconvert=True, token_class=Atom,
101 eapi=pkg.eapi)
102 @@ -2797,7 +2811,7 @@ class depgraph(object):
103 # practical to ignore this issue for installed packages.
104 try:
105 dep_string = portage.dep.use_reduce(dep_string,
106 - uselist=self._pkg_use_enabled(pkg),
107 + uselist=use_enabled,
108 opconvert=True, token_class=Atom,
109 eapi=pkg.eapi)
110 except portage.exception.InvalidDependString as e:
111 @@ -4969,6 +4983,12 @@ class depgraph(object):
112 self._dynamic_config._visible_pkgs[pkg.root].cpv_inject(pkg)
113 return ret
114
115 + def _is_argument(self, pkg):
116 + for arg, atom in self._iter_atoms_for_pkg(pkg):
117 + if isinstance(arg, (AtomArg, PackageArg)):
118 + return True
119 + return False
120 +
121 def _want_installed_pkg(self, pkg):
122 """
123 Given an installed package returned from select_pkg, return
124 diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py
125 index cf7966c..3f34102 100644
126 --- a/pym/_emerge/main.py
127 +++ b/pym/_emerge/main.py
128 @@ -160,6 +160,7 @@ def insert_optional_args(args):
129 '--usepkgonly' : y_or_n,
130 '--verbose' : y_or_n,
131 '--verbose-slot-rebuilds': y_or_n,
132 + '--with-test-deps' : y_or_n,
133 }
134
135 short_arg_opts = {
136 @@ -661,6 +662,11 @@ def parse_opts(tmpcmdline, silent=False):
137 "help" : "verbose slot rebuild output",
138 "choices" : true_y_or_n
139 },
140 + "--with-test-deps": {
141 + "help" : "pull in test deps for packages " + \
142 + "matched by arguments",
143 + "choices" : true_y_or_n
144 + },
145 }
146
147 parser = ArgumentParser(add_help=False)
148 @@ -956,6 +962,11 @@ def parse_opts(tmpcmdline, silent=False):
149 else:
150 myoptions.verbose = None
151
152 + if myoptions.with_test_deps in true_y:
153 + myoptions.with_test_deps = True
154 + else:
155 + myoptions.with_test_deps = None
156 +
157 for myopt in options:
158 v = getattr(myoptions, myopt.lstrip("--").replace("-", "_"))
159 if v:
160 diff --git a/pym/portage/tests/resolver/test_with_test_deps.py b/pym/portage/tests/resolver/test_with_test_deps.py
161 new file mode 100644
162 index 0000000..5bfc6a8
163 --- /dev/null
164 +++ b/pym/portage/tests/resolver/test_with_test_deps.py
165 @@ -0,0 +1,44 @@
166 +# Copyright 2014 Gentoo Foundation
167 +# Distributed under the terms of the GNU General Public License v2
168 +
169 +from portage.tests import TestCase
170 +from portage.tests.resolver.ResolverPlayground import \
171 + ResolverPlayground, ResolverPlaygroundTestCase
172 +
173 +class WithTestDepsTestCase(TestCase):
174 +
175 + def testWithTestDeps(self):
176 + ebuilds = {
177 + "app-misc/A-0": {
178 + "EAPI": "5",
179 + "IUSE": "test",
180 + "DEPEND": "test? ( app-misc/B )"
181 + },
182 + "app-misc/B-0": {
183 + "EAPI": "5",
184 + "IUSE": "test",
185 + "DEPEND": "test? ( app-misc/C )"
186 + },
187 + "app-misc/C-0": {
188 + "EAPI": "5",
189 + }
190 + }
191 +
192 + test_cases = (
193 + # Test that --with-test-deps only pulls in direct
194 + # test deps of packages matched by arguments.
195 + ResolverPlaygroundTestCase(
196 + ["app-misc/A"],
197 + success = True,
198 + options = { "--onlydeps": True, "--with-test-deps": True },
199 + mergelist = ["app-misc/B-0"]),
200 + )
201 +
202 + playground = ResolverPlayground(ebuilds=ebuilds, debug=False)
203 + try:
204 + for test_case in test_cases:
205 + playground.run_TestCase(test_case)
206 + self.assertEqual(test_case.test_success,
207 + True, test_case.fail_msg)
208 + finally:
209 + playground.cleanup()
210 --
211 2.0.4

Replies