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

#16427. Make MSBuildDeps generation with deployer relocatable #16441

Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion conan/tools/microsoft/msbuilddeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from conan.internal import check_duplicated_generator
from conan.errors import ConanException
from conans.client.generators import relativize_path
from conans.model.dependencies import get_transitive_requires
from conans.util.files import load, save

Expand Down Expand Up @@ -178,6 +179,9 @@ def join_paths(paths):

root_folder = dep.recipe_folder if dep.package_folder is None else dep.package_folder
root_folder = escape_path(root_folder)
# Make the root_folder relative to the generated conan_vars_xxx.props file
relative_root_folder = relativize_path(root_folder, self._conanfile,
"$(MSBuildThisFileDirectory)")

bin_dirs = join_paths(cpp_info.bindirs)
res_dirs = join_paths(cpp_info.resdirs)
Expand Down Expand Up @@ -205,7 +209,7 @@ def join_paths(paths):

fields = {
'name': name,
'root_folder': root_folder,
'root_folder': relative_root_folder,
'bin_dirs': bin_dirs,
'res_dirs': res_dirs,
'include_dirs': include_dirs,
Expand Down
50 changes: 50 additions & 0 deletions test/integration/toolchains/microsoft/test_msbuilddeps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import os
import platform
import textwrap
Expand Down Expand Up @@ -122,3 +123,52 @@ def package_info(self):
assert "conan_liba" not in libb
libb = c.load("app/conan_libb_mycomp_vars_release_x64.props")
assert "conan_liba" not in libb


def test_msbuilddeps_relocatable():
memsharded marked this conversation as resolved.
Show resolved Hide resolved
for withdepl in [False, True]:
c = TestClient()
c.save({
"libh/conanfile.py": GenConanfile("libh", "0.1")
.with_package_type("header-library"),
"libs/conanfile.py": GenConanfile("libs", "0.2")
.with_package_type("static-library")
.with_requires("libh/0.1"),
"libd/conanfile.py": GenConanfile("libd", "0.3")
.with_package_type("shared-library"),
"app/conanfile.py": GenConanfile()
.with_requires("libh/0.1")
.with_requires("libs/0.2")
.with_requires("libd/0.3")
.with_settings("arch", "build_type"),
})

c.run("create libh")
c.run("create libs")
c.run("create libd")
c.run("install app -g MSBuildDeps" + (" -d full_deploy" if withdepl else ""))

for dep in ["libh", "libs", "libd"]:
text = c.load(f"app/conan_{dep}_vars_release_x64.props")
marker = f"Conan{dep}RootFolder"
value = text.split(f"<{marker}>")[1].split(f"</{marker}>")[0]
if withdepl:
# path should be relative, since artifacts are moved along with project
prefix = '$(MSBuildThisFileDirectory)/'
assert value.startswith(prefix)
tail = value[len(prefix):]
assert not os.path.isabs(tail)
else:
# path should be absolute, since conan cache does not move with project
assert os.path.isabs(value)
assert '$(' not in value

if withdepl:
# extra checks: no absolute paths allowed anywhere in props
propsfiles = glob.glob(os.path.join(c.current_folder, "app/*.props"))
assert len(propsfiles) > 0
for fn in propsfiles:
text = c.load(fn)
text = text.replace('\\', '/')
dir = c.current_folder.replace('\\', '/')
assert dir not in text