|
5 | 5 | from conan.internal.cache.conan_reference_layout import BasicLayout
|
6 | 6 | from conan.internal.methods import run_configure_method
|
7 | 7 | from conans.client.graph.graph import DepsGraph, Node, CONTEXT_HOST, \
|
8 |
| - CONTEXT_BUILD, TransitiveRequirement, RECIPE_VIRTUAL, RECIPE_EDITABLE |
| 8 | + CONTEXT_BUILD, TransitiveRequirement, RECIPE_VIRTUAL, RECIPE_EDITABLE, RECIPE_CONSUMER |
9 | 9 | from conans.client.graph.graph import RECIPE_PLATFORM
|
10 | 10 | from conans.client.graph.graph_error import GraphLoopError, GraphConflictError, GraphMissingError, \
|
11 | 11 | GraphRuntimeError, GraphError
|
@@ -39,7 +39,9 @@ def load_graph(self, root_node, profile_host, profile_build, graph_lock=None):
|
39 | 39 | # print("Loading graph")
|
40 | 40 | dep_graph = DepsGraph()
|
41 | 41 |
|
42 |
| - self._prepare_node(root_node, profile_host, profile_build, Options()) |
| 42 | + is_test_package = getattr(root_node.conanfile, "tested_reference_str", None) |
| 43 | + define_consumers = root_node.recipe == RECIPE_VIRTUAL or is_test_package |
| 44 | + self._prepare_node(root_node, profile_host, profile_build, Options(), define_consumers) |
43 | 45 | rs = self._initialize_requires(root_node, dep_graph, graph_lock, profile_build, profile_host)
|
44 | 46 | dep_graph.add_node(root_node)
|
45 | 47 |
|
@@ -171,19 +173,25 @@ def _conflicting_refs(ref1, ref2):
|
171 | 173 | raise GraphConflictError(node, require, prev_node, prev_require, base_previous)
|
172 | 174 |
|
173 | 175 | @staticmethod
|
174 |
| - def _prepare_node(node, profile_host, profile_build, down_options): |
175 |
| - |
| 176 | + def _prepare_node(node, profile_host, profile_build, down_options, define_consumers=False): |
176 | 177 | # basic node configuration: calling configure() and requirements()
|
177 | 178 | conanfile, ref = node.conanfile, node.ref
|
178 | 179 |
|
179 | 180 | profile_options = profile_host.options if node.context == CONTEXT_HOST else profile_build.options
|
180 | 181 | assert isinstance(profile_options, Options), type(profile_options)
|
181 | 182 | run_configure_method(conanfile, down_options, profile_options, ref)
|
182 | 183 |
|
| 184 | + if define_consumers: # Mark this requirements as the "consumers" nodes |
| 185 | + tested_ref = getattr(conanfile, "tested_reference_str", None) |
| 186 | + tested_ref = RecipeReference.loads(tested_ref) if tested_ref else None |
| 187 | + for r in conanfile.requires.values(): |
| 188 | + if tested_ref is None or r.ref == tested_ref: |
| 189 | + r.is_consumer = True |
| 190 | + |
183 | 191 | # Apply build_tools_requires from profile, overriding the declared ones
|
184 | 192 | profile = profile_host if node.context == CONTEXT_HOST else profile_build
|
185 | 193 | for pattern, tool_requires in profile.tool_requires.items():
|
186 |
| - if ref_matches(ref, pattern, is_consumer=conanfile._conan_is_consumer): |
| 194 | + if ref_matches(ref, pattern, is_consumer=conanfile._conan_is_consumer): # noqa |
187 | 195 | for tool_require in tool_requires: # Do the override
|
188 | 196 | if str(tool_require) == str(ref): # FIXME: Ugly str comparison
|
189 | 197 | continue # avoid self-loop of build-requires in build context
|
@@ -364,9 +372,7 @@ def _create_new_node(self, node, require, graph, profile_host, profile_build, gr
|
364 | 372 |
|
365 | 373 | new_ref = layout.reference
|
366 | 374 | dep_conanfile.folders.set_base_recipe_metadata(layout.metadata()) # None for platform_xxx
|
367 |
| - # If the node is virtual or a test package, the require is also "root" |
368 |
| - is_test_package = getattr(node.conanfile, "tested_reference_str", False) |
369 |
| - if node.conanfile._conan_is_consumer and (node.recipe == RECIPE_VIRTUAL or is_test_package): |
| 375 | + if getattr(require, "is_consumer", None): |
370 | 376 | dep_conanfile._conan_is_consumer = True
|
371 | 377 | initialize_conanfile_profile(dep_conanfile, profile_build, profile_host, node.context,
|
372 | 378 | require.build, new_ref, parent=node.conanfile)
|
|
0 commit comments