Skip to content

Commit

Permalink
fix error with lock install when lockfile uses a path (#14836)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Oct 6, 2023
1 parent 067ed52 commit 0bc641a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conans/client/conan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,8 @@ def lock_install(self, lockfile, remote_name=None, build=None,
graph_lock = graph_info.graph_lock
root_id = graph_lock.root_node_id()
reference = graph_lock.nodes[root_id].ref
if reference is None:
reference = graph_lock.nodes[root_id].path
if recipes:
graph = self.app.graph_manager.load_graph(reference, create_reference=None,
graph_info=graph_info, build_mode=None,
Expand Down
25 changes: 25 additions & 0 deletions conans/test/functional/graph_lock/lock_install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,28 @@ def test_install_recipes():
assert "pkga/0.1@user/channel:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Download" in client.out
assert "pkgb/0.1@user/channel:cfd10f60aeaa00f5ca1f90b5fe97c3fe19e7ec23 - Download" in client.out


def test_install_txt():
""" lock install from a lockfile created from a conanfile path needs that conanfile to be
in the place it was to create the lockfile, otherwise it fails. So not really a great
use case
"""
client = TestClient()
client.save({"conanfile.py": GenConanfile("pkga", "0.1").with_package_file("file.h", "0.1")})
client.run("create . user/channel")

# Use a consumer with a version range
client.save({"conanfile.py":
GenConanfile("pkgb", "0.1").with_require("pkga/[>=0.1]@user/channel")})
client.run("create . user/channel")
client.save({"conanfile.txt": "[requires]\npkgb/0.1@user/channel"}, clean_first=True)
client.run("lock create conanfile.txt --lockfile-out=lock1.lock")

# We can create a pkga/0.2, but it will not be used
client.save({"conanfile.py": GenConanfile("pkga", "0.2").with_package_file("file.h", "0.2")})
client.run("create . user/channel")

client.run("lock install lock1.lock -g deploy")
assert "pkga/0.1@user/channel from local cache" in client.out
file_h = client.load("pkga/file.h")
assert file_h == "0.1"

0 comments on commit 0bc641a

Please sign in to comment.