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

Add example test for forwards compat of custom setting #17524

Merged
merged 8 commits into from
Jan 21, 2025
Merged
Changes from 3 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
75 changes: 75 additions & 0 deletions test/integration/package_id/compatible_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,78 @@ def validate_build(self):
pkga = liba["packages"][0][pkg_index]
assert pkga["info"]["compatibility_delta"] == {"settings": [["compiler.cppstd", "14"]]}
assert pkga["build_args"] == "--requires=liba/0.1 --build=compatible:liba/0.1"


def test_compatibility_new_setting_forwards_compat():
""" This test tries to reflect the following scenario:
- User adds a new setting (libc.version in this case)
- This setting is forward compatible
How is it solved with compatibility.py? Like this:
"""
settings_user_file = "libc_version: [1, 2, 3]"
tc = TestClient()
tc.save_home({"settings_user.yml": settings_user_file})
tc.save({"conanfile.py": GenConanfile("dep", "1.0")
.with_settings("libc_version", "compiler")})
tc.run("create . -s=libc_version=2 -s=compiler.cppstd=17")
dep_package_id = tc.created_package_id("dep/1.0")
tc.run("install --requires=dep/1.0 -s=libc_version=3 -s=compiler.cppstd=17", assert_error=True)
# We can't compile, because the dep is not compatible
assert "Missing prebuilt package for 'dep/1.0'" in tc.out

# Let's create a compatibility extensions
libc_compat = textwrap.dedent("""
from conan.tools.scm import Version
def libc_compat(conanfile):
# Do we have the setting?
libc_version = conanfile.settings.get_safe("libc_version")
if libc_version is None:
return []
available_libc_versions = conanfile.settings.libc_version.possible_values()
ret = []
for possible_libc_version in available_libc_versions:
if Version(possible_libc_version) <= Version(libc_version):
ret.append({"settings": [("libc_version", possible_libc_version)]})
return ret
""")

# And add it to the compatibility.py plugin
compatibility_plugin = textwrap.dedent("""
from cppstd_compat import cppstd_compat
from libc_compat import libc_compat
def compatibility(conanfile):
configs = cppstd_compat(conanfile)
libc_configs = libc_compat(conanfile)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
results = []
# First only the cppstd settings
for config in configs:
results.append(config)
# Now the libc settings by themselves
for libc_config in libc_configs:
results.append(libc_config)
# And now the combination of both
for config in configs:
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
for libc_config in libc_configs:
results.append({"settings": config["settings"] + libc_config["settings"]})
# Note that this generates a large number of results,
# And checking the servers might be slow until improvements are made in the API
return results
""")

tc.save_home({"extensions/plugins/compatibility/libc_compat.py": libc_compat,
"extensions/plugins/compatibility/compatibility.py": compatibility_plugin})

# Now we try again, this time app will find the compatible dep with libc_version 2
tc.run("install --requires=dep/1.0 -s=libc_version=3 -s=compiler.cppstd=17")
assert f"dep/1.0: Found compatible package '{dep_package_id}'" in tc.out

# And now we try to create the app with libc_version 1, which is still not compatible
tc.run("install --requires=dep/1.0 -s=libc_version=1 -s=compiler.cppstd=17", assert_error=True)
assert "Missing prebuilt package for 'dep/1.0'" in tc.out

# Now we try again, this time app will find the compatible dep with libc_version 2
# And see how we're also compatible over a different cppstd
tc.run("install --requires=dep/1.0 -s=libc_version=3 -s=compiler.cppstd=14")
assert f"dep/1.0: Found compatible package '{dep_package_id}': compiler.cppstd=17, libc_version=2" in tc.out
Loading