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
3 changes: 2 additions & 1 deletion conans/client/graph/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def compatibility(conanfile):

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

if not getattr(conanfile, "compatibility_cppstd", True):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets explore the conf mechanism instead of attributes:

  • With intermediate priorities, soft and hard overwritten by user profiles

return []
compiler = conanfile.settings.get_safe("compiler")
compiler_version = conanfile.settings.get_safe("compiler.version")
cppstd = conanfile.settings.get_safe("compiler.cppstd")
Expand Down
38 changes: 37 additions & 1 deletion conans/test/integration/package_id/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import textwrap
import unittest

import pytest

from conan.cli.exit_codes import ERROR_INVALID_CONFIGURATION, ERROR_GENERAL
from conans.client.graph.graph import BINARY_INVALID
Expand Down Expand Up @@ -661,6 +660,43 @@ def package_id(self):
assert_error=True)
assert 'pkg/0.1: Invalid: I need at least cppstd=14 to be used' in client.out

def test_exact_cppstd(self):
""" 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()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
settings = "compiler"

def compatibility(self):
# It also works as class attribute, but more explicit here
self.compatibility_cppstd = False
""")

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

settings = "-s compiler=gcc -s compiler.version=9 -s compiler.libcxx=libstdc++"
client.run(f"create . {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