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 MSBuildDeps xml component names #12365

Merged
merged 2 commits into from
Oct 24, 2022
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
11 changes: 5 additions & 6 deletions conan/tools/microsoft/msbuilddeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class MSBuildDeps(object):
<PropertyGroup Label="ConanVariables">
<Conan{{name}}RootFolder>{{root_folder}}</Conan{{name}}RootFolder>
<Conan{{name}}BinaryDirectories>{{bin_dirs}}</Conan{{name}}BinaryDirectories>
<Conan{{name}}Dependencies>{{dependencies}}</Conan{{name}}Dependencies>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being removed, as it is not used at all by Conan, and it was flawed, as it contained a mix of xml-replaced names, components names, etc. This information is already encoded in the <Imports> sections of the .props files explicitly.

{% if host_context %}
<Conan{{name}}CompilerFlags>{{compiler_flags}}</Conan{{name}}CompilerFlags>
<Conan{{name}}LinkerFlags>{{linker_flags}}</Conan{{name}}LinkerFlags>
Expand Down Expand Up @@ -134,7 +133,7 @@ def _dep_name(dep, build):
def _get_valid_xml_format(name):
return re.compile(r"[.+]").sub("_", name)

def _vars_props_file(self, dep, name, cpp_info, deps, build):
def _vars_props_file(self, dep, name, cpp_info, build):
"""
content for conan_vars_poco_x86_release.props, containing the variables for 1 config
This will be for 1 package or for one component of a package
Expand Down Expand Up @@ -180,7 +179,6 @@ def join_paths(paths):
'definitions': "".join("%s;" % d for d in cpp_info.defines),
'compiler_flags': " ".join(cpp_info.cxxflags + cpp_info.cflags),
'linker_flags': " ".join(cpp_info.sharedlinkflags + cpp_info.exelinkflags),
'dependencies': ";".join(deps),
'host_context': not build
}
formatted_template = Template(self._vars_props, trim_blocks=True,
Expand Down Expand Up @@ -291,15 +289,16 @@ def _package_props_files(self, dep, build=False):
comp_filename = "conan_%s.props" % full_comp_name
pkg_filename = "conan_%s.props" % dep_name

public_deps = []
public_deps = [] # To store the xml dependencies/file names
for r in comp_info.requires:
if "::" in r: # Points to a component of a different package
pkg, cmp_name = r.split("::")
public_deps.append(pkg if pkg == cmp_name else "{}_{}".format(pkg, cmp_name))
else: # Points to a component of same package
public_deps.append("{}_{}".format(dep_name, r))
public_deps = [self._get_valid_xml_format(d) for d in public_deps]
result[vars_filename] = self._vars_props_file(dep, full_comp_name, comp_info,
public_deps, build=build)
build=build)
result[activate_filename] = self._activate_props_file(full_comp_name, vars_filename,
public_deps, build=build)
result[comp_filename] = self._dep_props_file(full_comp_name, comp_filename,
Expand All @@ -317,7 +316,7 @@ def _package_props_files(self, dep, build=False):
public_deps = [self._dep_name(d, build)
for r, d in dep.dependencies.direct_host.items() if r.visible]
result[vars_filename] = self._vars_props_file(dep, dep_name, cpp_info,
public_deps, build=build)
build=build)
result[activate_filename] = self._activate_props_file(dep_name, vars_filename,
public_deps, build=build)
result[pkg_filename] = self._dep_props_file(dep_name, pkg_filename, activate_filename,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,4 +1008,4 @@ def test_build_requires_transitives():
assert "conan_dep_build.props" in tool
assert "conan_dep.props" not in tool
tool_vars = c.load("conan_tool_build_vars_release_x64.props")
assert "<Conantool_buildDependencies>dep_build</Conantool_buildDependencies>" in tool_vars
assert "<Conantool_buildRootFolder>" in tool_vars
13 changes: 13 additions & 0 deletions conans/test/integration/toolchains/microsoft/test_msbuilddeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ def package_info(self):
c.run("install pkg.name-more+/1.0@ -g MSBuildDeps -s build_type=Release -s arch=x86_64")
# Checking that MSBuildDeps builds correctly the XML file
# loading all .props and xml parse them to check no errors
pkg_more = c.load("conan_pkg_name-more_.props")
assert "$(conan_pkg_name-more__libmpdecimal___props_imported)" in pkg_more
assert "$(conan_pkg_name-more__mycomp_some-comp__props_imported)" in pkg_more

some_comp = c.load("conan_pkg_name-more__mycomp_some-comp_.props")
assert "<conan_pkg_name-more__mycomp_some-comp__props_imported>" in some_comp

libmpdecimal = c.load("conan_pkg_name-more__libmpdecimal__.props")
assert "<conan_pkg_name-more__libmpdecimal___props_imported>" in libmpdecimal

libmpdecimal_release = c.load("conan_pkg_name-more__libmpdecimal___release_x64.props")
assert "$(conan_pkg_name-more__mycomp_some-comp__props_imported)" in libmpdecimal_release

counter = 0
for f in os.listdir(c.current_folder):
if f.endswith(".props"):
Expand Down