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

possible fix for lock of compatible packages #9008

Merged
merged 4 commits into from
May 28, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions conans/client/graph/graph_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,27 @@ def _evaluate_node(self, node, build_mode, update, remotes):

# If it has lock
locked = node.graph_lock_node
if locked and locked.package_id: # if package_id = None, nothing to lock here
# First we update the package_id, just in case there are differences or something
if locked.package_id != node.package_id and locked.package_id != PACKAGE_ID_UNKNOWN:
raise ConanException("'%s' package-id '%s' doesn't match the locked one '%s'"
% (repr(locked.ref), node.package_id, locked.package_id))
locked.package_id = node.package_id # necessary for PACKAGE_ID_UNKNOWN
if locked and locked.package_id and locked.package_id != PACKAGE_ID_UNKNOWN:
pref = PackageReference(locked.ref, locked.package_id, locked.prev) # Keep locked PREV
self._process_node(node, pref, build_mode, update, remotes)
if node.binary == BINARY_MISSING and build_mode.allowed(node.conanfile):
node.binary = BINARY_BUILD
if node.binary == BINARY_BUILD:
locked.unlock_prev()

if node.package_id != locked.package_id: # It was a compatible package
# https://github.com/conan-io/conan/issues/9002
# We need to iterate to search the compatible combination
for compatible_package in node.conanfile.compatible_packages:
comp_package_id = compatible_package.package_id()
if comp_package_id == locked.package_id:
node._package_id = locked.package_id # FIXME: Ugly definition of private
node.conanfile.settings.values = compatible_package.settings
node.conanfile.options.values = compatible_package.options
break
else:
raise ConanException("'%s' package-id '%s' doesn't match the locked one '%s'"
% (repr(locked.ref), node.package_id, locked.package_id))
else:
assert node.prev is None, "Non locked node shouldn't have PREV in evaluate_node"
assert node.binary is None, "Node.binary should be None if not locked"
Expand Down
29 changes: 29 additions & 0 deletions conans/test/integration/package_id/compatible_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,35 @@ def package_id(self):
client.out)
self.assertIn("pkg/0.1@user/testing: Already installed!", client.out)

def test_compatible_lockfile(self):
# https://github.com/conan-io/conan/issues/9002
client = TestClient()
conanfile = textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
settings = "os"
def package_id(self):
if self.settings.os == "Windows":
compatible_pkg = self.info.clone()
compatible_pkg.settings.os = "Linux"
self.compatible_packages.append(compatible_pkg)
def package_info(self):
self.output.info("PackageInfo!: OS: %s!" % self.settings.os)
""")

client.save({"conanfile.py": conanfile})
client.run("create . pkg/0.1@user/stable -s os=Linux")
self.assertIn("pkg/0.1@user/stable: PackageInfo!: OS: Linux!", client.out)
self.assertIn("pkg/0.1@user/stable: Package 'cb054d0b3e1ca595dc66bc2339d40f1f8f04ab31'"
" created", client.out)

client.save({"conanfile.py": GenConanfile().with_require("pkg/0.1@user/stable")})
client.run("lock create conanfile.py -s os=Windows --lockfile-out=deps.lock")
client.run("install conanfile.py --lockfile=deps.lock")
self.assertIn("pkg/0.1@user/stable: PackageInfo!: OS: Linux!", client.out)
self.assertIn("pkg/0.1@user/stable:cb054d0b3e1ca595dc66bc2339d40f1f8f04ab31", client.out)
self.assertIn("pkg/0.1@user/stable: Already installed!", client.out)


def test_msvc_visual_incompatible():
conanfile = GenConanfile().with_settings("os", "compiler", "build_type", "arch")
Expand Down