Skip to content

Commit fac4b9b

Browse files
AbrilRBSmemsharded
andauthored
Fix 2 assert regressions for graph compatibility (#19148)
* Add tests for 2 asserts that are now triggering * fix regression --------- Co-authored-by: memsharded <james@conan.io>
1 parent 79d7454 commit fac4b9b

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

conan/internal/graph/graph_binaries.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ def _compatible_find_existing_binaries(self, node, compatibles, remotes, update)
164164
for package_id, compatible_package in compatibles.items():
165165
node._package_id = package_id # Modifying package id under the hood, FIXME
166166
node.binary = None # Invalidate it
167-
self._compatible_process_node_cache(node) # Doesn't check remotes
168-
if node.binary == BINARY_CACHE:
167+
cache_latest_prev = self._compatible_cache_latest_prev(node) # not check remotes
168+
if cache_latest_prev:
169+
self._binary_in_cache(node, cache_latest_prev)
169170
self._compatible_found(conanfile, package_id, compatible_package)
170171
return
171172
# If not found in the cache, then look first one in servers
@@ -185,9 +186,9 @@ def _compatible_find_existing_binaries(self, node, compatibles, remotes, update)
185186
f"{conanfile.info.dump_diff(compatible_package)}")
186187
node._package_id = package_id # Modifying package id under the hood, FIXME
187188
node.binary = None # Invalidate it
188-
self._compatible_process_node_cache(node) # Doesn't check remotes
189-
if node.binary == BINARY_CACHE:
190-
self._evaluate_cache_update(node.pref, node, remotes, update)
189+
cache_latest_prev = self._compatible_cache_latest_prev(node) # Not check remotes
190+
if cache_latest_prev:
191+
self._evaluate_cache_update(cache_latest_prev, node, remotes, update)
191192
else:
192193
self._evaluate_download(node, remotes, update)
193194
if node.binary in (BINARY_CACHE, BINARY_UPDATE, BINARY_DOWNLOAD):
@@ -198,7 +199,7 @@ def _compatible_find_existing_binaries(self, node, compatibles, remotes, update)
198199
node.binary = original_binary
199200
node._package_id = original_package_id
200201

201-
def _compatible_process_node_cache(self, node):
202+
def _compatible_cache_latest_prev(self, node):
202203
""" simplified checking of compatible_packages, that should be found existing, but
203204
will never be built, for example. They cannot be editable either at this point.
204205
"""
@@ -220,14 +221,16 @@ def _compatible_process_node_cache(self, node):
220221
if not self._evaluate_clean_pkg_folder_dirty(node, package_layout):
221222
break
222223

223-
if cache_latest_prev is not None:
224-
# This binary already exists in the cache, maybe can be updated
225-
assert cache_latest_prev.revision
226-
assert node.binary is None
227-
node.binary = BINARY_CACHE
228-
node.binary_remote = None
229-
node.prev = cache_latest_prev.revision
230-
node.pref_timestamp = cache_latest_prev.timestamp
224+
return cache_latest_prev
225+
226+
@staticmethod
227+
def _binary_in_cache(node, cache_latest_prev):
228+
assert cache_latest_prev.revision
229+
assert node.binary is None
230+
node.binary = BINARY_CACHE
231+
node.binary_remote = None
232+
node.prev = cache_latest_prev.revision
233+
node.pref_timestamp = cache_latest_prev.timestamp
231234

232235
def _compatible_find_build_binary(self, node, compatibles):
233236
original_binary = node.binary

test/integration/package_id/test_cache_compatibles.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ def compatibility(conanfile):
180180
c.assert_listed_binary({"dep/0.1": ("ce92fac7c26ace631e30875ddbb3a58a190eb601",
181181
"Download (default)")})
182182

183+
# Now what happens if we have it in cache already
184+
c.run(f"install consumer {base_settings} -s compiler.cppstd=17 --update")
185+
assert "dep/0.1: Checking 3 compatible configurations" in c.out
186+
assert "dep/0.1: Main binary package '6179018ccb6b15e6443829bf3640e25f2718b931' missing" in c.out
187+
assert "Found compatible package 'ce92fac7c26ace631e30875ddbb3a58a190eb601': " \
188+
"compiler.cppstd=14" in c.out
189+
c.assert_listed_binary({"dep/0.1": ("ce92fac7c26ace631e30875ddbb3a58a190eb601",
190+
"Cache")})
191+
183192

184193
class TestDefaultCompat:
185194

@@ -475,3 +484,14 @@ def test_remove_plugin_file(self):
475484
c.save({"conanfile.txt": ""})
476485
c.run("install .", assert_error=True)
477486
assert "ERROR: The 'compatibility.py' plugin file doesn't exist" in c.out
487+
488+
489+
def test_compatible_prev_from_cache():
490+
tc = TestClient()
491+
tc.save({"conanfile.py": GenConanfile("pkg", "0.1").with_settings("compiler")})
492+
settings = ("-s os=Linux -s arch=x86_64 -s compiler=gcc -s compiler.version=8 "
493+
"-s compiler.libcxx=libstdc++11")
494+
tc.run(f"create . {settings} -s=compiler.cppstd=17")
495+
tc.run(f"install --requires=pkg/0.1 {settings} -s=compiler.cppstd=14 -u")
496+
tc.assert_listed_binary({"pkg/0.1": ("6179018ccb6b15e6443829bf3640e25f2718b931",
497+
"Cache")})

0 commit comments

Comments
 (0)