Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-poc for cppstd compatibility exact #15348

Merged
4 changes: 3 additions & 1 deletion conans/client/graph/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def compatibility(conanfile):

def cppstd_compat(conanfile):
# It will try to find packages with all the cppstd versions

extension_properties = getattr(conanfile, "extension_properties", {})
if extension_properties.get("compatibility_cppstd") is False:
return []
compiler = conanfile.settings.get_safe("compiler")
compiler_version = conanfile.settings.get_safe("compiler.version")
cppstd = conanfile.settings.get_safe("compiler.cppstd")
Expand Down
41 changes: 41 additions & 0 deletions conans/test/integration/package_id/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,47 @@ def package_id(self):
assert_error=True)
assert 'pkg/0.1: Invalid: I need at least cppstd=14 to be used' in client.out

@pytest.mark.parametrize("use_attribute", [True, False])
def test_exact_cppstd(self, use_attribute):
""" Using the default cppstd_compat sometimes is not desired, and a recipe can
explicitly opt-out this default cppstd_compat behavior, if it knows its binaries
won't be binary compatible among them for different cppstd values
"""
client = TestClient()
if use_attribute:
conanfile = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
settings = "compiler"
extension_properties = {"compatibility_cppstd": False}
""")
else:
conanfile = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
settings = "compiler"
def compatibility(self):
self.extension_properties = {"compatibility_cppstd": False}
""")

client.save({"conanfile.py": conanfile})

settings = "-s compiler=gcc -s compiler.version=9 -s compiler.libcxx=libstdc++"
client.run(f"create . --name=pkg --version=0.1 {settings} -s compiler.cppstd=17")
client.assert_listed_binary({"pkg/0.1": ("91faf062eb94767a31ff62a46767d3d5b41d1eff",
"Build")})

# Install with cppstd=14 can NOT fallback to the previous one
client.run(f"install --requires=pkg/0.1 {settings} -s compiler.cppstd=14", assert_error=True)
assert "ERROR: Missing prebuilt package for 'pkg/0.1'" in client.out
assert "compiler.cppstd=14" in client.out
assert "compiler.cppstd=17" not in client.out
client.run(f"install --requires=pkg/0.1 {settings} -s compiler.cppstd=14 --build=missing")
client.assert_listed_binary({"pkg/0.1": ("36d978cbb4dc35906d0fd438732d5e17cd1e388d",
"Build")})
assert "compiler.cppstd=14" in client.out
assert "compiler.cppstd=17" not in client.out


class TestCompatibleSettingsTarget(unittest.TestCase):
""" aims to be a very close to real use case of tool being used across different settings_target
Expand Down