Skip to content

Commit

Permalink
Start using ConanFileDependencies in msbuilddeps (#8706)
Browse files Browse the repository at this point in the history
* start using ConanFileDependencies in MSBuildDeps generator

* full usage of ConanFileDependencies

* fix intel imports
  • Loading branch information
memsharded committed Mar 26, 2021
1 parent 306cfea commit deabdd3
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
18 changes: 10 additions & 8 deletions conan/tools/microsoft/msbuilddeps.py
Expand Up @@ -4,6 +4,7 @@


from conans.errors import ConanException
from conans.model.build_info import DepCppInfo
from conans.util.files import load, save

VALID_LIB_EXTENSIONS = (".so", ".lib", ".a", ".dylib", ".bc")
Expand Down Expand Up @@ -128,15 +129,15 @@ def _deps_props(self, name_general, deps):
import_group = dom.getElementsByTagName('ImportGroup')[0]
children = import_group.getElementsByTagName("Import")
for dep in deps:
conf_props_name = "conan_%s.props" % dep
conf_props_name = "conan_%s.props" % dep.name
for node in children:
if conf_props_name == node.getAttribute("Project"):
# the import statement already exists
break
else:
# create a new import statement
import_node = dom.createElement('Import')
dep_imported = "'$(conan_%s_props_imported)' != 'True'" % dep
dep_imported = "'$(conan_%s_props_imported)' != 'True'" % dep.name
import_node.setAttribute('Project', conf_props_name)
import_node.setAttribute('Condition', dep_imported)
# add it to the import group
Expand Down Expand Up @@ -224,17 +225,18 @@ def _content(self):
conf_name = self._config_filename()
condition = self._condition()
# Include all direct build_requires for host context. This might change
direct_deps = self._conanfile.deps_cpp_info.direct_host_deps
direct_deps = self._conanfile.dependencies.direct_host_requires
result[general_name] = self._deps_props(general_name, direct_deps)
for dep_name, cpp_info in self._conanfile.deps_cpp_info.dependencies:
for dep in self._conanfile.dependencies.host_requires:
cpp_info = DepCppInfo(dep.cpp_info) # To account for automatic component aggregation
# One file per configuration, with just the variables
vars_props_name = "conan_%s%s.props" % (dep_name, conf_name)
vars_conf_content = self._pkg_config_props(dep_name, cpp_info)
vars_props_name = "conan_%s%s.props" % (dep.name, conf_name)
vars_conf_content = self._pkg_config_props(dep.name, cpp_info)
result[vars_props_name] = vars_conf_content

# The entry point for each package, it will have conditionals to the others
props_name = "conan_%s.props" % dep_name
dep_content = self._pkg_props(props_name, dep_name, vars_props_name, condition, cpp_info)
props_name = "conan_%s.props" % dep.name
dep_content = self._pkg_props(props_name, dep.name, vars_props_name, condition, cpp_info)
result[props_name] = dep_content

return result
20 changes: 20 additions & 0 deletions conans/client/graph/conanfile_dependencies.py
@@ -1,3 +1,4 @@
from conans.client.graph.graph import CONTEXT_HOST
from conans.model.conanfile_interface import ConanFileInterface


Expand All @@ -16,3 +17,22 @@ def requires(self):
# public direct requires
return [ConanFileInterface(edge.dst.conanfile) for edge in self._node.dependencies
if not edge.build_require and not edge.private]

@property
def direct_host_requires(self):
return self.requires + [br for br in self.build_requires if br.context == CONTEXT_HOST]

@property
def host_requires(self):
result = []
next_requires = self.direct_host_requires
while next_requires:
new_requires = []
for require in next_requires:
if require not in new_requires and require not in result:
result.append(require)
for transitive in require.dependencies.requires:
if transitive not in new_requires:
new_requires.append(transitive)
next_requires = new_requires
return result
2 changes: 0 additions & 2 deletions conans/client/installer.py
Expand Up @@ -599,8 +599,6 @@ def _propagate_info(self, node, using_build_profile):
env_info.PATH.extend(dep_cpp_info.bin_paths)
conan_file.deps_env_info.update(env_info, n.ref.name)

conan_file.deps_cpp_info.direct_host_deps = [n.name for n in node.neighbors()
if n.context == CONTEXT_HOST]
# Update the info but filtering the package values that not apply to the subtree
# of this current node and its dependencies.
subtree_libnames = [node.ref.name for node in node_order]
Expand Down
4 changes: 4 additions & 0 deletions conans/model/conanfile_interface.py
Expand Up @@ -21,6 +21,10 @@ def __eq__(self, other):
def __ne__(self, other):
return not self.__eq__(other)

@property
def name(self):
return self._conanfile.name

@property
def buildenv_info(self):
return self._conanfile.buildenv_info
Expand Down
Expand Up @@ -2,14 +2,12 @@
import platform
import pytest
import textwrap
import unittest

from conan.tools.microsoft.visual import vcvars_command
from ._base import BaseIntelTestCase
from ..test_msbuild import myapp_vcxproj, sln_file

from conans.test.assets.sources import gen_function_cpp

from ..microsoft.test_msbuild import sln_file, myapp_vcxproj

conanfile_py = textwrap.dedent("""
from conans import ConanFile, MSBuild, MSBuildToolchain
Expand Down
Empty file.

0 comments on commit deabdd3

Please sign in to comment.