Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion conan/internal/graph/graph_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,16 @@ def _find_build_compatible_binary(self, node, compatibles):
if not compatible.cant_build:
node._package_id = pkg_id # Modifying package id under the hood, FIXME
self._compatible_found(node.conanfile, pkg_id, compatible)
node.binary = BINARY_BUILD
# We might have the compatible package in the cache,
# check for it before, and then build it if not found
cache_latest_prev = self._cache.get_latest_package_reference(node.pref)
if cache_latest_prev is None:
node.binary = BINARY_BUILD
else:
node.binary = BINARY_CACHE
node.binary_remote = None
node.prev = cache_latest_prev.revision
node.pref_timestamp = cache_latest_prev.timestamp
return
node.binary = original_binary
node._package_id = original_package_id
Expand Down
33 changes: 33 additions & 0 deletions test/integration/package_id/compatible_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,39 @@ def validate_build(self):
assert pkga["info"]["compatibility_delta"] == {"settings": [["compiler.cppstd", "14"]]}
assert pkga["build_args"] == "--requires=liba/0.1 --build=compatible:liba/0.1"

def test_compatible_build_test_package(self):
tc = TestClient()
tc.save({"conanfile.py": textwrap.dedent("""
from conan import ConanFile
from conan.tools.build import check_min_cppstd

class Pkg(ConanFile):
name = "pkg"
version = "0.1"
settings = "compiler"

def validate(self):
check_min_cppstd(self, 17)
"""),
"test_package/conanfile.py": textwrap.dedent("""
from conan import ConanFile

class TestPkg(ConanFile):
settings = "compiler"
def requirements(self):
self.requires(self.tested_reference_str)
def test(self):
pass
""")})

tc.run("create . -s compiler.cppstd=14 --build=compatible")
# Without checking if the compatibles are already in the cache, it will build twice,
# once for the package and once for the test_package
assert tc.out.count("pkg/0.1#2e52358a1684ca0bd32277b2630f0080:0b26ee249577d4b7c1e52c7ce646c0b5eb611dfb - Build") == 1
tc.run("create . -s compiler.cppstd=17 --build=compatible")
# This would fail because the package revision is now also included
#assert tc.out.count("pkg/0.1#2e52358a1684ca0bd32277b2630f0080:0b26ee249577d4b7c1e52c7ce646c0b5eb611dfb - Cache") == 2


def test_compatibility_new_setting_forwards_compat():
""" This test tries to reflect the following scenario:
Expand Down
Loading