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 4/7] binpkg-multi-instance 4 of 7
Date: Wed, 18 Feb 2015 03:07:01
Message-Id: 1424228745-7794-5-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 0/7] Add FEATURES=binpkg-multi-instance (bug 150031) by Zac Medico
1 Add a test case to verify that emerge --rebuilt-binaries works with
2 binpkg-multi-instance. This relies on the fact that binary packages of
3 the same version are ordered by BUILD_TIME, so that the latest builds
4 are preferred when appropriate.
5 ---
6 pym/portage/tests/resolver/ResolverPlayground.py | 25 ++++-
7 .../resolver/binpkg_multi_instance/__init__.py | 2 +
8 .../resolver/binpkg_multi_instance/__test__.py | 2 +
9 .../binpkg_multi_instance/test_rebuilt_binaries.py | 101 +++++++++++++++++++++
10 4 files changed, 126 insertions(+), 4 deletions(-)
11 create mode 100644 pym/portage/tests/resolver/binpkg_multi_instance/__init__.py
12 create mode 100644 pym/portage/tests/resolver/binpkg_multi_instance/__test__.py
13 create mode 100644 pym/portage/tests/resolver/binpkg_multi_instance/test_rebuilt_binaries.py
14
15 diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py
16 index 84ad17c..6bdf2c7 100644
17 --- a/pym/portage/tests/resolver/ResolverPlayground.py
18 +++ b/pym/portage/tests/resolver/ResolverPlayground.py
19 @@ -39,6 +39,7 @@ class ResolverPlayground(object):
20
21 config_files = frozenset(("eapi", "layout.conf", "make.conf", "package.accept_keywords",
22 "package.keywords", "package.license", "package.mask", "package.properties",
23 + "package.provided", "packages",
24 "package.unmask", "package.use", "package.use.aliases", "package.use.stable.mask",
25 "soname.provided",
26 "unpack_dependencies", "use.aliases", "use.force", "use.mask", "layout.conf"))
27 @@ -208,12 +209,18 @@ class ResolverPlayground(object):
28 raise AssertionError('digest creation failed for %s' % ebuild_path)
29
30 def _create_binpkgs(self, binpkgs):
31 - for cpv, metadata in binpkgs.items():
32 + # When using BUILD_ID, there can be mutiple instances for the
33 + # same cpv. Therefore, binpkgs may be an iterable instead of
34 + # a dict.
35 + items = getattr(binpkgs, 'items', None)
36 + items = items() if items is not None else binpkgs
37 + for cpv, metadata in items:
38 a = Atom("=" + cpv, allow_repo=True)
39 repo = a.repo
40 if repo is None:
41 repo = "test_repo"
42
43 + pn = catsplit(a.cp)[1]
44 cat, pf = catsplit(a.cpv)
45 metadata = metadata.copy()
46 metadata.setdefault("SLOT", "0")
47 @@ -225,8 +232,13 @@ class ResolverPlayground(object):
48
49 repo_dir = self.pkgdir
50 category_dir = os.path.join(repo_dir, cat)
51 - binpkg_path = os.path.join(category_dir, pf + ".tbz2")
52 - ensure_dirs(category_dir)
53 + if "BUILD_ID" in metadata:
54 + binpkg_path = os.path.join(category_dir, pn,
55 + "%s-%s.xpak"% (pf, metadata["BUILD_ID"]))
56 + else:
57 + binpkg_path = os.path.join(category_dir, pf + ".tbz2")
58 +
59 + ensure_dirs(os.path.dirname(binpkg_path))
60 t = portage.xpak.tbz2(binpkg_path)
61 t.recompose_mem(portage.xpak.xpak_mem(metadata))
62
63 @@ -252,6 +264,7 @@ class ResolverPlayground(object):
64 unknown_keys = set(metadata).difference(
65 portage.dbapi.dbapi._known_keys)
66 unknown_keys.discard("BUILD_TIME")
67 + unknown_keys.discard("BUILD_ID")
68 unknown_keys.discard("COUNTER")
69 unknown_keys.discard("repository")
70 unknown_keys.discard("USE")
71 @@ -749,7 +762,11 @@ class ResolverPlaygroundResult(object):
72 repo_str = ""
73 if x.repo != "test_repo":
74 repo_str = _repo_separator + x.repo
75 - mergelist_str = x.cpv + repo_str
76 + build_id_str = ""
77 + if (x.type_name == "binary" and
78 + x.cpv.build_id is not None):
79 + build_id_str = "-%s" % x.cpv.build_id
80 + mergelist_str = x.cpv + build_id_str + repo_str
81 if x.built:
82 if x.operation == "merge":
83 desc = x.type_name
84 diff --git a/pym/portage/tests/resolver/binpkg_multi_instance/__init__.py b/pym/portage/tests/resolver/binpkg_multi_instance/__init__.py
85 new file mode 100644
86 index 0000000..4725d33
87 --- /dev/null
88 +++ b/pym/portage/tests/resolver/binpkg_multi_instance/__init__.py
89 @@ -0,0 +1,2 @@
90 +# Copyright 2015 Gentoo Foundation
91 +# Distributed under the terms of the GNU General Public License v2
92 diff --git a/pym/portage/tests/resolver/binpkg_multi_instance/__test__.py b/pym/portage/tests/resolver/binpkg_multi_instance/__test__.py
93 new file mode 100644
94 index 0000000..4725d33
95 --- /dev/null
96 +++ b/pym/portage/tests/resolver/binpkg_multi_instance/__test__.py
97 @@ -0,0 +1,2 @@
98 +# Copyright 2015 Gentoo Foundation
99 +# Distributed under the terms of the GNU General Public License v2
100 diff --git a/pym/portage/tests/resolver/binpkg_multi_instance/test_rebuilt_binaries.py b/pym/portage/tests/resolver/binpkg_multi_instance/test_rebuilt_binaries.py
101 new file mode 100644
102 index 0000000..5729df4
103 --- /dev/null
104 +++ b/pym/portage/tests/resolver/binpkg_multi_instance/test_rebuilt_binaries.py
105 @@ -0,0 +1,101 @@
106 +# Copyright 2015 Gentoo Foundation
107 +# Distributed under the terms of the GNU General Public License v2
108 +
109 +from portage.tests import TestCase
110 +from portage.tests.resolver.ResolverPlayground import (ResolverPlayground,
111 + ResolverPlaygroundTestCase)
112 +
113 +class RebuiltBinariesCase(TestCase):
114 +
115 + def testRebuiltBinaries(self):
116 +
117 + user_config = {
118 + "make.conf":
119 + (
120 + "FEATURES=\"binpkg-multi-instance\"",
121 + ),
122 + }
123 +
124 + binpkgs = (
125 + ("app-misc/A-1", {
126 + "EAPI": "5",
127 + "BUILD_ID": "1",
128 + "BUILD_TIME": "1",
129 + }),
130 + ("app-misc/A-1", {
131 + "EAPI": "5",
132 + "BUILD_ID": "2",
133 + "BUILD_TIME": "2",
134 + }),
135 + ("app-misc/A-1", {
136 + "EAPI": "5",
137 + "BUILD_ID": "3",
138 + "BUILD_TIME": "3",
139 + }),
140 + ("dev-libs/B-1", {
141 + "EAPI": "5",
142 + "BUILD_ID": "1",
143 + "BUILD_TIME": "1",
144 + }),
145 + ("dev-libs/B-1", {
146 + "EAPI": "5",
147 + "BUILD_ID": "2",
148 + "BUILD_TIME": "2",
149 + }),
150 + ("dev-libs/B-1", {
151 + "EAPI": "5",
152 + "BUILD_ID": "3",
153 + "BUILD_TIME": "3",
154 + }),
155 + )
156 +
157 + installed = {
158 + "app-misc/A-1" : {
159 + "EAPI": "5",
160 + "BUILD_ID": "1",
161 + "BUILD_TIME": "1",
162 + },
163 + "dev-libs/B-1" : {
164 + "EAPI": "5",
165 + "BUILD_ID": "2",
166 + "BUILD_TIME": "2",
167 + },
168 + }
169 +
170 + world = (
171 + "app-misc/A",
172 + "dev-libs/B",
173 + )
174 +
175 + test_cases = (
176 +
177 + ResolverPlaygroundTestCase(
178 + ["@world"],
179 + options = {
180 + "--deep": True,
181 + "--rebuilt-binaries": True,
182 + "--update": True,
183 + "--usepkgonly": True,
184 + },
185 + success = True,
186 + ignore_mergelist_order=True,
187 + mergelist = [
188 + "[binary]dev-libs/B-1-3",
189 + "[binary]app-misc/A-1-3"
190 + ]
191 + ),
192 +
193 + )
194 +
195 + playground = ResolverPlayground(debug=False,
196 + binpkgs=binpkgs, installed=installed,
197 + user_config=user_config, world=world)
198 + try:
199 + for test_case in test_cases:
200 + playground.run_TestCase(test_case)
201 + self.assertEqual(test_case.test_success, True,
202 + test_case.fail_msg)
203 + finally:
204 + # Disable debug so that cleanup works.
205 + #playground.debug = False
206 + playground.cleanup()
207 --
208 2.0.5