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

fix compatibility() over settings_target making it None #14825

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions conans/client/graph/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def compatibles(self, conanfile):
result = OrderedDict()
original_info = conanfile.info
original_settings = conanfile.settings
original_settings_target = conanfile.settings_target
original_options = conanfile.options
for c in compat_infos:
# we replace the conanfile, so ``validate()`` and ``package_id()`` can
Expand All @@ -105,6 +106,7 @@ def compatibles(self, conanfile):
# Restore the original state
conanfile.info = original_info
conanfile.settings = original_settings
conanfile.settings_target = original_settings_target
conanfile.options = original_options
return result

Expand Down
26 changes: 26 additions & 0 deletions conans/test/integration/package_id/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,29 @@ def requirements(self):
client.run("create . --name=app --version=0.1 -s os=Linux -s:h arch=armv7 -s:b arch=x86_64")
assert f"Using compatible package '{package_id_tool_a}'" in client.out
assert package_id_tool_b in client.out

def test_settings_target_in_compatibility_method_within_recipe_package_info(self):
# https://github.com/conan-io/conan/issues/14823
client = TestClient()
tool_conanfile = textwrap.dedent("""
from conan import ConanFile

class Pkg(ConanFile):
settings = "arch"

def compatibility(self):
return [{'settings': [('arch', 'armv6')]}]

def package_info(self):
# This used to crash
self.settings_target.get_safe('compiler.link_time_optimization')
""")

client.save({"conanfile.py": tool_conanfile})
client.run("create . --name=tool --version=0.1 -s os=Linux -s:b arch=armv6 --build-require")
package_id = client.created_package_id("tool/0.1")
assert f"tool/0.1: Package '{package_id}' created" in client.out

client.run("install --tool-requires=tool/0.1 -s os=Linux -s:b arch=armv7")
# This used to crash, not anymore
assert f"Using compatible package '{package_id}'" in client.out