Skip to content

Commit

Permalink
fix compatibility() over settings_target making it None (#14825)
Browse files Browse the repository at this point in the history
* fix compatibility() over settings_target making it None

* fix tests
  • Loading branch information
memsharded authored Sep 26, 2023
1 parent c55a690 commit 844f112
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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

0 comments on commit 844f112

Please sign in to comment.