Skip to content

Commit

Permalink
fixed graph_lock.py - lock_node(): consider context (#13788)
Browse files Browse the repository at this point in the history
* fixed graph_lock.py - lock_node(): consider context of build_require from lockfile

* using host context when build_require_context is not set

* add test

---------

Co-authored-by: memsharded <james@conan.io>
  • Loading branch information
SzBosch and memsharded authored May 3, 2023
1 parent c1b3978 commit 51c9364
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions conans/model/graph_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import OrderedDict

from conans import DEFAULT_REVISION_V1
from conans.client.graph.graph import RECIPE_VIRTUAL, RECIPE_CONSUMER
from conans.client.graph.graph import RECIPE_VIRTUAL, RECIPE_CONSUMER, CONTEXT_HOST
from conans.client.graph.python_requires import PyRequires
from conans.client.graph.range_resolver import satisfying
from conans.client.profile_loader import _load_profile
Expand Down Expand Up @@ -538,11 +538,12 @@ def lock_node(self, node, requires, build_requires=False):
else:
locked_requires = locked_node.requires or []

refs = {self._nodes[id_].ref.name: (self._nodes[id_].ref, id_) for id_ in locked_requires}
refs = {(self._nodes[id_].ref.name, self._nodes[id_].context): (self._nodes[id_].ref, id_) for id_ in locked_requires}

for require in requires:
try:
locked_ref, locked_id = refs[require.ref.name]
context = require.build_require_context if require.build_require_context is not None else CONTEXT_HOST
locked_ref, locked_id = refs[(require.ref.name, context)]
except KeyError:
t = "Build-require" if build_requires else "Require"
msg = "%s '%s' cannot be found in lockfile" % (t, require.ref.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import textwrap
import unittest

import pytest

from conans.client.tools.env import environment_append
from conans.test.utils.tools import TestClient, GenConanfile

Expand Down Expand Up @@ -266,3 +268,22 @@ def test_test_package_build_require():

client.run("create pkg/conanfile.py pkg/1.0@ --build=missing --lockfile=conan.lock")
assert "pkg/1.0 (test package): Applying build-requirement: cmake/1.0" in client.out


@pytest.mark.parametrize("test_requires", [True, False])
def test_duplicated_build_host_require(test_requires):
c = TestClient()
if test_requires:
pkg = GenConanfile("pkg", "0.1").with_build_requirement("tool/[^4.0]",
force_host_context=True)
else:
pkg = GenConanfile("pkg", "0.1").with_requirement("tool/[^4.0]")
c.save({"tool/conanfile.py": GenConanfile("tool"),
"pkg/conanfile.py": pkg,
"profile": "[tool_requires]\ntool/[^3.0]"})
c.run("create tool 3.0@")
c.run("create tool 4.0@")
c.run("install pkg -pr:b=default -pr:h=profile --build")
assert "tool/4.0 from local cache - Cache" in c.out
c.run("install pkg --lockfile=conan.lock")
assert "tool/4.0 from local cache - Cache" in c.out

0 comments on commit 51c9364

Please sign in to comment.