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

fix for [platform_tool_requires] in build context #15665

Merged
merged 2 commits into from
Feb 14, 2024
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
12 changes: 10 additions & 2 deletions conans/client/graph/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,16 @@ def _resolve_recipe(self, ref, graph_lock):
@staticmethod
def _resolved_system(node, require, profile_build, profile_host, resolve_prereleases):
profile = profile_build if node.context == CONTEXT_BUILD else profile_host
dep_type = "platform_tool_requires" if require.build else "platform_requires"
system_reqs = getattr(profile, dep_type)
if node.context == CONTEXT_BUILD:
# If we are in the build context, the platform_tool_requires ALSO applies to the
# regular requires. It is not possible in the build context to have tool-requires
# and regular requires to the same package from Conan and from Platform
system_reqs = profile.platform_tool_requires
if not require.build:
system_reqs = system_reqs + profile.platform_requires
else:
system_reqs = profile.platform_tool_requires if require.build \
else profile.platform_requires
if system_reqs:
version_range = require.version_range
for d in system_reqs:
Expand Down
5 changes: 3 additions & 2 deletions conans/client/graph/install_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from conan.api.output import ConanOutput
from conans.client.graph.graph import RECIPE_CONSUMER, RECIPE_VIRTUAL, BINARY_SKIP, \
BINARY_MISSING, BINARY_INVALID, Overrides, BINARY_BUILD, BINARY_EDITABLE_BUILD
BINARY_MISSING, BINARY_INVALID, Overrides, BINARY_BUILD, BINARY_EDITABLE_BUILD, BINARY_PLATFORM
from conans.errors import ConanInvalidConfiguration, ConanException
from conans.model.package_ref import PkgReference
from conans.model.recipe_ref import RecipeReference
Expand Down Expand Up @@ -370,7 +370,8 @@ def deserialize(data, filename):

def _initialize_deps_graph(self, deps_graph):
for node in deps_graph.ordered_iterate():
if node.recipe in (RECIPE_CONSUMER, RECIPE_VIRTUAL) or node.binary == BINARY_SKIP:
if node.recipe in (RECIPE_CONSUMER, RECIPE_VIRTUAL) \
or node.binary in (BINARY_SKIP, BINARY_PLATFORM):
continue

key = node.ref if self._order == "recipe" else node.pref
Expand Down
5 changes: 1 addition & 4 deletions conans/client/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from conans.client.conanfile.package import run_package_method
from conans.client.generators import write_generators
from conans.client.graph.graph import BINARY_BUILD, BINARY_CACHE, BINARY_DOWNLOAD, BINARY_EDITABLE, \
BINARY_PLATFORM, BINARY_UPDATE, BINARY_EDITABLE_BUILD, BINARY_SKIP
BINARY_UPDATE, BINARY_EDITABLE_BUILD, BINARY_SKIP
from conans.client.graph.install_graph import InstallGraph
from conans.client.source import retrieve_exports_sources, config_source
from conans.errors import (ConanException, conanfile_exception_formatter, conanfile_remove_attr)
Expand Down Expand Up @@ -295,9 +295,6 @@ def _download_pkg(self, package):
self._remote_manager.get_package(node.pref, node.binary_remote)

def _handle_package(self, package, install_reference, handled_count, total_count):
if package.binary == BINARY_PLATFORM:
return

if package.binary in (BINARY_EDITABLE, BINARY_EDITABLE_BUILD):
self._handle_node_editable(package)
return
Expand Down
22 changes: 22 additions & 0 deletions conans/test/integration/graph/test_platform_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ def test_platform_requires_no_host(self):
client.run("create . -pr=profile", assert_error=True)
assert "ERROR: Package 'dep/1.0' not resolved: No remote defined" in client.out

def test_platform_requires_build_context(self):
"""
platform_requires must work in the build context too
"""
client = TestClient(light=True)
client.save({"tool/conanfile.py": GenConanfile("tool", "1.0").with_requires("dep/1.0"),
"pkg/conanfile.py": GenConanfile("pkg", "1.0").with_tool_requires("tool/1.0"),
"profile": "[settings]\nos=Linux\n[platform_requires]\ndep/1.0"})
client.run("create tool -pr:b=profile --build-require")
assert "dep/1.0 - Platform" in client.out
client.run("create pkg -pr:b=profile")
assert "dep/1.0 - Platform" in client.out

def test_graph_info_platform_requires_range(self):
"""
graph info doesn't crash
Expand Down Expand Up @@ -136,6 +149,15 @@ def generate(self):
assert "ERROR: Package 'dep/1.1' not resolved" in client.out


class TestPlatformTestRequires:
def test_platform_requires(self):
client = TestClient()
client.save({"conanfile.py": GenConanfile("pkg", "1.0").with_test_requires("dep/1.0"),
"profile": "[platform_requires]\ndep/1.0"})
client.run("create . -pr=profile")
assert "dep/1.0 - Platform" in client.out


class TestPlatformRequiresLock:

def test_platform_requires_range(self):
Expand Down
20 changes: 20 additions & 0 deletions conans/test/integration/graph/test_system_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ def generate(self):
client.run("install . -pr=profile", assert_error=True)
assert "ERROR: Package 'tool/1.1' not resolved" in client.out

def test_require_build_context(self):
""" https://github.com/conan-io/conan/issues/15659
app -> libcurl --(tool-require)--> libtool -> automake -> autoconf
\\--(br)-> automake -> autoconf
"""
c = TestClient()
c.save({"autoconf/conanfile.py": GenConanfile("autoconf", "0.1"),
"automake/conanfile.py": GenConanfile("automake", "0.1").with_requires("autoconf/0.1"),
"libtool/conanfile.py": GenConanfile("libtool", "0.1").with_requires("automake/0.1")
.with_tool_requires("automake/0.1"),
"libcurl/conanfile.py": GenConanfile("libcurl", "0.1").with_tool_requires("libtool/0.1"),
"app/conanfile.py": GenConanfile().with_requires("libcurl/0.1"),
"profile_build": "[settings]\nos=Linux\n[platform_tool_requires]\nautomake/0.1"})
c.run("create autoconf")
c.run("create automake")
c.run("export libtool")
c.run("export libcurl")
c.run("install app -pr:b=profile_build --build=missing")
assert "Install finished successfully" in c.out


class TestToolRequiresLock:

Expand Down