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

adding checks for [replace_requires] with MSBuildDeps #17967

Merged
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: 8 additions & 3 deletions conan/tools/microsoft/msbuilddeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,14 @@ def _package_props_files(self, require, dep, build=False):
public_deps = [] # To store the xml dependencies/file names
for required_pkg, required_comp in comp_info.parsed_requires():
if required_pkg is not None: # Points to a component of a different package
if required_pkg in pkg_deps: # The transitive dep might have been skipped
public_deps.append(required_pkg if required_pkg == required_comp
else "{}_{}".format(required_pkg, required_comp))
try:
required = pkg_deps[required_pkg]
except KeyError: # The transitive dep might have been skipped
required = None
if required: # The transitive dep might have been skipped
required_name = required.ref.name
public_deps.append(required_name if required_pkg == required_comp
else "{}_{}".format(required_name, required_comp))
else: # Points to a component of same package
public_deps.append("{}_{}".format(dep_name, required_comp))
public_deps = [self._get_valid_xml_format(d) for d in public_deps]
Expand Down
57 changes: 49 additions & 8 deletions test/integration/graph/test_replace_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,15 @@ def package_info(self):
class App(ConanFile):
name = "app"
version = "0.1"
settings = "build_type"
settings = "build_type", "arch"
requires = "openssl/0.1", {zlib}
package_type = "application"
generators = "CMakeDeps", "PkgConfigDeps"
generators = "CMakeDeps", "PkgConfigDeps", "MSBuildDeps"
""")
profile = textwrap.dedent("""
[settings]
build_type = Release
arch=x86_64

[replace_requires]
zlib/0.1: zlib-ng/0.1
Expand Down Expand Up @@ -454,6 +455,13 @@ class App(ConanFile):
assert "set_property(TARGET openssl::openssl APPEND PROPERTY INTERFACE_LINK_LIBRARIES\n" \
' "$<$<CONFIG:RELEASE>:ZLIB::ZLIB>")' in cmake

# checking MSBuildDeps
zlib_ng_props = c.load("app/conan_zlib-ng.props")
assert 'Project="conan_zlib-ng_release_x64.props"' in zlib_ng_props
props = c.load("app/conan_openssl_release_x64.props")
assert "<Import Condition=\"'$(conan_zlib-ng_props_imported)' != 'True'\"" \
" Project=\"conan_zlib-ng.props\"/>" in props

@pytest.mark.parametrize("diamond", [True, False])
def test_openssl_components(self, diamond):
c = TestClient()
Expand Down Expand Up @@ -490,14 +498,15 @@ def package_info(self):
class App(ConanFile):
name = "app"
version = "0.1"
settings = "build_type"
settings = "build_type", "arch"
requires = "openssl/0.1", {zlib}
package_type = "application"
generators = "CMakeDeps", "PkgConfigDeps"
generators = "CMakeDeps", "PkgConfigDeps", "MSBuildDeps"
""")
profile = textwrap.dedent("""
[settings]
build_type = Release
arch=x86_64

[replace_requires]
zlib/0.1: zlib-ng/0.1
Expand Down Expand Up @@ -526,6 +535,14 @@ class App(ConanFile):
assert "set_property(TARGET openssl::crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES\n" \
' "$<$<CONFIG:RELEASE>:ZLIB::ZLIB>")' in cmake

# checking MSBuildDeps
zlib_ng_props = c.load("app/conan_zlib-ng.props")
assert 'Project="conan_zlib-ng_release_x64.props"' in zlib_ng_props

props = c.load("app/conan_openssl_crypto_release_x64.props")
assert "<Import Condition=\"'$(conan_zlib-ng_props_imported)' != 'True'\"" \
" Project=\"conan_zlib-ng.props\"/>" in props

@pytest.mark.parametrize("diamond", [True, False])
@pytest.mark.parametrize("explicit_requires", [True, False])
def test_zlib_components(self, diamond, explicit_requires):
Expand Down Expand Up @@ -565,14 +582,15 @@ def package_info(self):
class App(ConanFile):
name = "app"
version = "0.1"
settings = "build_type"
settings = "build_type", "arch"
requires = "openssl/0.1", {zlib}
package_type = "application"
generators = "CMakeDeps", "PkgConfigDeps"
generators = "CMakeDeps", "PkgConfigDeps", "MSBuildDeps"
""")
profile = textwrap.dedent("""
[settings]
build_type = Release
arch = x86_64

[replace_requires]
zlib/0.1: zlib-ng/0.1
Expand Down Expand Up @@ -604,6 +622,15 @@ class App(ConanFile):
assert "set_property(TARGET openssl::openssl APPEND PROPERTY INTERFACE_LINK_LIBRARIES\n" \
' "$<$<CONFIG:RELEASE>:zlib-ng::zlib-ng>")' in cmake

# checking MSBuildDeps
zlib_ng_props = c.load("app/conan_zlib-ng.props")
assert "<Import Condition=\"'$(conan_zlib-ng_myzlib_props_imported)' != 'True'\" " \
"Project=\"conan_zlib-ng_myzlib.props\"/" in zlib_ng_props

props = c.load("app/conan_openssl_release_x64.props")
assert "<Import Condition=\"'$(conan_zlib-ng_props_imported)' != 'True'\"" \
" Project=\"conan_zlib-ng.props\"/>" in props

@pytest.mark.parametrize("diamond", [True, False])
@pytest.mark.parametrize("package_requires", [False, True])
def test_both_components(self, diamond, package_requires):
Expand Down Expand Up @@ -645,14 +672,15 @@ def package_info(self):
class App(ConanFile):
name = "app"
version = "0.1"
settings = "build_type"
settings = "build_type", "arch"
requires = "openssl/0.1", {zlib}
package_type = "application"
generators = "CMakeDeps", "PkgConfigDeps"
generators = "CMakeDeps", "PkgConfigDeps", "MSBuildDeps"
""")
profile = textwrap.dedent("""
[settings]
build_type = Release
arch = x86_64

[replace_requires]
zlib/0.1: zlib-ng/0.1
Expand Down Expand Up @@ -687,3 +715,16 @@ class App(ConanFile):
else:
assert "set_property(TARGET openssl::crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES\n" \
' "$<$<CONFIG:RELEASE>:ZLIB::ZLIB>")' in cmake

# checking MSBuildDeps
zlib_ng_props = c.load("app/conan_zlib-ng.props")
assert "<Import Condition=\"'$(conan_zlib-ng_myzlib_props_imported)' != 'True'\" " \
"Project=\"conan_zlib-ng_myzlib.props\"/" in zlib_ng_props

props = c.load("app/conan_openssl_crypto_release_x64.props")
if package_requires:
assert "<Import Condition=\"'$(conan_zlib-ng_props_imported)' != 'True'\"" \
" Project=\"conan_zlib-ng.props\"/>" in props
else:
assert "<Import Condition=\"'$(conan_zlib-ng_myzlib_props_imported)' != 'True'\"" \
" Project=\"conan_zlib-ng_myzlib.props\"/>" in props