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

adding test_requires() for 2.0 migration of force_host_context #10027

Merged
merged 1 commit into from
Nov 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conans/client/graph/graph_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ def _resolve_graph(self, root_node, profile_host, profile_build, graph_lock, bui
@staticmethod
def _get_recipe_build_requires(conanfile, default_context):
conanfile.build_requires = _RecipeBuildRequires(conanfile, default_context)

class TestRequirements:
def __init__(self, build_requires):
self._build_requires = build_requires

def __call__(self, ref):
self._build_requires(ref, force_host_context=True)

conanfile.test_requires = TestRequirements(conanfile.build_requires)
if hasattr(conanfile, "build_requirements"):
with get_env_context_manager(conanfile):
with conanfile_exception_formatter(str(conanfile), "build_requirements"):
Expand Down
28 changes: 28 additions & 0 deletions conans/test/integration/graph/core/test_build_requires.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import textwrap

import six
from parameterized import parameterized

Expand Down Expand Up @@ -399,3 +401,29 @@ def test_build_require_link_order(self):
dependents=[], closure=[gazelle, grass])
self.assertListEqual(list(cheetah.conanfile.deps_cpp_info.libs),
['mylibgazelle0.1lib', 'mylibgrass0.1lib'])

def test_test_require(self):
# app -(tr)-> gtest/0.1
# This test should survive in 2.0
tool_ref = ConanFileReference.loads("gtest/0.1")
self._cache_recipe(tool_ref, GenConanfile("gtest", "0.1"))

conanfile = textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
name = "app"
version = "0.1"
def build_requirements(self):
self.test_requires("gtest/0.1")
""")
deps_graph = self.build_graph(conanfile)

# Build requires always apply to the consumer
self.assertEqual(2, len(deps_graph.nodes))
app = deps_graph.root
tool = app.dependencies[0].dst

self._check_node(app, "app/0.1@", deps=[], build_deps=[tool], dependents=[],
closure=[tool])
self._check_node(tool, "gtest/0.1#123", deps=[], build_deps=[],
dependents=[app], closure=[])