Skip to content

Commit

Permalink
New [platform_requires] similar to system-tools, but for all requires (
Browse files Browse the repository at this point in the history
…#14871)

* wip

* test passing

* wip

* wip

* wip

* wip

* wip

* renaming and review

* fixes

* add missing dumps

* Simplified if-else clauses. Keeping more prio for platform_tool_requires

* Renamed first naming proposal

* review test, new check

* fix test

* fix

---------

Co-authored-by: Francisco Ramirez de Anton <franchuti688@gmail.com>
  • Loading branch information
memsharded and franramirez688 authored Dec 1, 2023
1 parent 1f548d8 commit 412a027
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 87 deletions.
4 changes: 2 additions & 2 deletions conan/api/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fnmatch
import json

from conans.client.graph.graph import RECIPE_EDITABLE, RECIPE_CONSUMER, RECIPE_SYSTEM_TOOL, \
from conans.client.graph.graph import RECIPE_EDITABLE, RECIPE_CONSUMER, RECIPE_PLATFORM, \
RECIPE_VIRTUAL, BINARY_SKIP, BINARY_MISSING, BINARY_INVALID
from conans.errors import ConanException
from conans.model.package_ref import PkgReference
Expand Down Expand Up @@ -99,7 +99,7 @@ def load_graph(graphfile, graph_recipes=None, graph_binaries=None):
remote_list.add_refs([pyref])

recipe = node["recipe"]
if recipe in (RECIPE_EDITABLE, RECIPE_CONSUMER, RECIPE_VIRTUAL, RECIPE_SYSTEM_TOOL):
if recipe in (RECIPE_EDITABLE, RECIPE_CONSUMER, RECIPE_VIRTUAL, RECIPE_PLATFORM):
continue

ref = node["ref"]
Expand Down
4 changes: 2 additions & 2 deletions conan/cli/printers/graph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from conan.api.output import ConanOutput, Color, LEVEL_VERBOSE
from conans.client.graph.graph import RECIPE_CONSUMER, RECIPE_VIRTUAL, CONTEXT_BUILD, BINARY_SKIP,\
BINARY_SYSTEM_TOOL
BINARY_PLATFORM


def print_graph_basic(graph):
Expand Down Expand Up @@ -105,7 +105,7 @@ def _format_requires(title, reqs_to_print):
return
output.info(title, Color.BRIGHT_YELLOW)
for pref, (status, remote) in sorted(reqs_to_print.items(), key=repr):
name = pref.repr_notime() if status != BINARY_SYSTEM_TOOL else str(pref.ref)
name = pref.repr_notime() if status != BINARY_PLATFORM else str(pref.ref)
msg = f"{tab}{name} - {status}"
if remote is not None and status != BINARY_SKIP:
msg += f" ({remote.name})"
Expand Down
4 changes: 2 additions & 2 deletions conans/client/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
RECIPE_EDITABLE = "Editable"
RECIPE_CONSUMER = "Consumer" # A conanfile from the user
RECIPE_VIRTUAL = "Cli" # A virtual conanfile (dynamic in memory conanfile)
RECIPE_SYSTEM_TOOL = "System tool"
RECIPE_PLATFORM = "Platform"

BINARY_CACHE = "Cache"
BINARY_DOWNLOAD = "Download"
Expand All @@ -25,7 +25,7 @@
BINARY_EDITABLE = "Editable"
BINARY_EDITABLE_BUILD = "EditableBuild"
BINARY_INVALID = "Invalid"
BINARY_SYSTEM_TOOL = "System tool"
BINARY_PLATFORM = "Platform"

CONTEXT_HOST = "host"
CONTEXT_BUILD = "build"
Expand Down
8 changes: 4 additions & 4 deletions conans/client/graph/graph_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from conans.client.graph.graph import (BINARY_BUILD, BINARY_CACHE, BINARY_DOWNLOAD, BINARY_MISSING,
BINARY_UPDATE, RECIPE_EDITABLE, BINARY_EDITABLE,
RECIPE_CONSUMER, RECIPE_VIRTUAL, BINARY_SKIP,
BINARY_INVALID, BINARY_EDITABLE_BUILD, RECIPE_SYSTEM_TOOL,
BINARY_SYSTEM_TOOL)
BINARY_INVALID, BINARY_EDITABLE_BUILD, RECIPE_PLATFORM,
BINARY_PLATFORM)
from conans.errors import NoRemoteAvailable, NotFoundException, \
PackageNotFoundException, conanfile_exception_formatter

Expand Down Expand Up @@ -178,8 +178,8 @@ def _process_node(self, node, build_mode, remotes, update):
if node.conanfile.info.invalid:
node.binary = BINARY_INVALID
return
if node.recipe == RECIPE_SYSTEM_TOOL:
node.binary = BINARY_SYSTEM_TOOL
if node.recipe == RECIPE_PLATFORM:
node.binary = BINARY_PLATFORM
return

if node.recipe == RECIPE_EDITABLE:
Expand Down
26 changes: 12 additions & 14 deletions conans/client/graph/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conans.client.conanfile.configure import run_configure_method
from conans.client.graph.graph import DepsGraph, Node, CONTEXT_HOST, \
CONTEXT_BUILD, TransitiveRequirement, RECIPE_VIRTUAL, RECIPE_EDITABLE
from conans.client.graph.graph import RECIPE_SYSTEM_TOOL
from conans.client.graph.graph import RECIPE_PLATFORM
from conans.client.graph.graph_error import GraphLoopError, GraphConflictError, GraphMissingError, \
GraphRuntimeError, GraphError
from conans.client.graph.profile_node_definer import initialize_conanfile_profile
Expand Down Expand Up @@ -215,24 +215,23 @@ def _resolve_recipe(self, ref, graph_lock):
return new_ref, dep_conanfile, recipe_status, remote

@staticmethod
def _resolved_system_tool(node, require, profile_build, profile_host, resolve_prereleases):
if node.context == CONTEXT_HOST and not require.build: # Only for DIRECT tool_requires
return
system_tool = profile_build.system_tools if node.context == CONTEXT_BUILD \
else profile_host.system_tools
if system_tool:
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 system_reqs:
version_range = require.version_range
for d in system_tool:
for d in system_reqs:
if require.ref.name == d.name:
if version_range:
if version_range.contains(d.version, resolve_prereleases):
require.ref.version = d.version # resolved range is replaced by exact
return d, ConanFile(str(d)), RECIPE_SYSTEM_TOOL, None
return d, ConanFile(str(d)), RECIPE_PLATFORM, None
elif require.ref.version == d.version:
if d.revision is None or require.ref.revision is None or \
d.revision == require.ref.revision:
require.ref.revision = d.revision
return d, ConanFile(str(d)), RECIPE_SYSTEM_TOOL, None
return d, ConanFile(str(d)), RECIPE_PLATFORM, None

def _create_new_node(self, node, require, graph, profile_host, profile_build, graph_lock):
if require.ref.version == "<host_version>":
Expand All @@ -246,13 +245,12 @@ def _create_new_node(self, node, require, graph, profile_host, profile_build, gr
"host dependency")
require.ref.version = transitive.require.ref.version

resolved = self._resolved_system(node, require, profile_build, profile_host,
self._resolve_prereleases)
if graph_lock is not None:
# Here is when the ranges and revisions are resolved
graph_lock.resolve_locked(node, require, self._resolve_prereleases)

resolved = self._resolved_system_tool(node, require, profile_build, profile_host,
self._resolve_prereleases)

if resolved is None:
try:
# TODO: If it is locked not resolve range
Expand All @@ -269,7 +267,7 @@ def _create_new_node(self, node, require, graph, profile_host, profile_build, gr
if recipe_status == RECIPE_EDITABLE:
recipe_metadata = os.path.join(dep_conanfile.recipe_folder, "metadata")
dep_conanfile.folders.set_base_recipe_metadata(recipe_metadata)
elif recipe_status != RECIPE_SYSTEM_TOOL:
elif recipe_status != RECIPE_PLATFORM:
recipe_metadata = self._cache.recipe_layout(new_ref).metadata()
dep_conanfile.folders.set_base_recipe_metadata(recipe_metadata)
# If the node is virtual or a test package, the require is also "root"
Expand Down
4 changes: 2 additions & 2 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_SYSTEM_TOOL, BINARY_UPDATE, BINARY_EDITABLE_BUILD, BINARY_SKIP
BINARY_PLATFORM, 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 @@ -294,7 +294,7 @@ 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_SYSTEM_TOOL:
if package.binary == BINARY_PLATFORM:
return

if package.binary in (BINARY_EDITABLE, BINARY_EDITABLE_BUILD):
Expand Down
26 changes: 17 additions & 9 deletions conans/client/profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from jinja2 import Environment, FileSystemLoader

from conan import conan_version
from conan.api.output import ConanOutput
from conan.internal.api import detect_api
from conan.internal.cache.home_paths import HomePaths
from conan.tools.env.environment import ProfileEnvironment
Expand Down Expand Up @@ -218,20 +219,24 @@ class _ProfileValueParser(object):
@staticmethod
def get_profile(profile_text, base_profile=None):
# Trying to strip comments might be problematic if things contain #
doc = ConfigParser(profile_text, allowed_fields=["tool_requires", "system_tools",
"settings",
doc = ConfigParser(profile_text, allowed_fields=["tool_requires",
"system_tools", # DEPRECATED: platform_tool_requires
"platform_requires",
"platform_tool_requires", "settings",
"options", "conf", "buildenv", "runenv"])

# Parse doc sections into Conan model, Settings, Options, etc
settings, package_settings = _ProfileValueParser._parse_settings(doc)
options = Options.loads(doc.options) if doc.options else None
tool_requires = _ProfileValueParser._parse_tool_requires(doc)

doc_platform_requires = doc.platform_requires or ""
doc_platform_tool_requires = doc.platform_tool_requires or doc.system_tools or ""
if doc.system_tools:
system_tools = [RecipeReference.loads(r.strip())
for r in doc.system_tools.splitlines() if r.strip()]
else:
system_tools = []
ConanOutput().warning("Profile [system_tools] is deprecated,"
" please use [platform_tool_requires]")
platform_tool_requires = [RecipeReference.loads(r) for r in doc_platform_tool_requires.splitlines()]
platform_requires = [RecipeReference.loads(r) for r in doc_platform_requires.splitlines()]

if doc.conf:
conf = ConfDefinition()
Expand All @@ -243,9 +248,12 @@ def get_profile(profile_text, base_profile=None):

# Create or update the profile
base_profile = base_profile or Profile()
current_system_tools = {r.name: r for r in base_profile.system_tools}
current_system_tools.update({r.name: r for r in system_tools})
base_profile.system_tools = list(current_system_tools.values())
current_platform_tool_requires = {r.name: r for r in base_profile.platform_tool_requires}
current_platform_tool_requires.update({r.name: r for r in platform_tool_requires})
base_profile.platform_tool_requires = list(current_platform_tool_requires.values())
current_platform_requires = {r.name: r for r in base_profile.platform_requires}
current_platform_requires.update({r.name: r for r in platform_requires})
base_profile.platform_requires = list(current_platform_requires.values())

base_profile.settings.update(settings)
for pkg_name, values_dict in package_settings.items():
Expand Down
12 changes: 6 additions & 6 deletions conans/model/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import OrderedDict

from conans.client.graph.graph import RECIPE_SYSTEM_TOOL
from conans.client.graph.graph import RECIPE_PLATFORM
from conans.errors import ConanException
from conans.model.recipe_ref import RecipeReference
from conans.model.conanfile_interface import ConanFileInterface
Expand Down Expand Up @@ -82,7 +82,7 @@ def from_node(node):
for require, transitive in node.transitive_deps.items())
return ConanFileDependencies(d)

def filter(self, require_filter, remove_system_tools=False):
def filter(self, require_filter, remove_system=True):
# FIXME: Copy of hte above, to return ConanFileDependencies class object
def filter_fn(require):
for k, v in require_filter.items():
Expand All @@ -91,10 +91,10 @@ def filter_fn(require):
return True

data = OrderedDict((k, v) for k, v in self._data.items() if filter_fn(k))
if remove_system_tools:
if remove_system:
data = OrderedDict((k, v) for k, v in data.items()
# TODO: Make "recipe" part of ConanFileInterface model
if v._conanfile._conan_node.recipe != RECIPE_SYSTEM_TOOL)
if v._conanfile._conan_node.recipe != RECIPE_PLATFORM)
return ConanFileDependencies(data, require_filter)

def transitive_requires(self, other):
Expand Down Expand Up @@ -133,7 +133,7 @@ def direct_host(self):

@property
def direct_build(self):
return self.filter({"build": True, "direct": True}, remove_system_tools=True)
return self.filter({"build": True, "direct": True})

@property
def host(self):
Expand All @@ -147,7 +147,7 @@ def test(self):

@property
def build(self):
return self.filter({"build": True}, remove_system_tools=True)
return self.filter({"build": True})


def get_transitive_requires(consumer, dependency):
Expand Down
23 changes: 16 additions & 7 deletions conans/model/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def __init__(self):
self.package_settings = defaultdict(OrderedDict)
self.options = Options()
self.tool_requires = OrderedDict() # ref pattern: list of ref
self.system_tools = []
self.platform_tool_requires = []
self.platform_requires = []
self.conf = ConfDefinition()
self.buildenv = ProfileEnvironment()
self.runenv = ProfileEnvironment()
Expand Down Expand Up @@ -74,9 +75,13 @@ def dumps(self):
for pattern, req_list in self.tool_requires.items():
result.append("%s: %s" % (pattern, ", ".join(str(r) for r in req_list)))

if self.system_tools:
result.append("[system_tools]")
result.extend(str(t) for t in self.system_tools)
if self.platform_tool_requires:
result.append("[platform_tool_requires]")
result.extend(str(t) for t in self.platform_tool_requires)

if self.platform_requires:
result.append("[platform_requires]")
result.extend(str(t) for t in self.platform_requires)

if self.conf:
result.append("[conf]")
Expand Down Expand Up @@ -115,9 +120,13 @@ def compose_profile(self, other):
existing[r.name] = req
self.tool_requires[pattern] = list(existing.values())

current_system_tools = {r.name: r for r in self.system_tools}
current_system_tools.update({r.name: r for r in other.system_tools})
self.system_tools = list(current_system_tools.values())
current_platform_tool_requires = {r.name: r for r in self.platform_tool_requires}
current_platform_tool_requires.update({r.name: r for r in other.platform_tool_requires})
self.platform_tool_requires = list(current_platform_tool_requires.values())
current_platform_requires = {r.name: r for r in self.platform_requires}
current_platform_requires.update({r.name: r for r in other.platform_requires})
self.platform_requires = list(current_platform_requires.values())

self.conf.update_conf_definition(other.conf)
self.buildenv.update_profile_env(other.buildenv) # Profile composition, last has priority
self.runenv.update_profile_env(other.runenv)
Expand Down
Loading

0 comments on commit 412a027

Please sign in to comment.