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 copying symlink to directories (2) #7655

Merged
merged 8 commits into from Oct 20, 2020
6 changes: 4 additions & 2 deletions conans/client/generators/deploy.py
Expand Up @@ -33,7 +33,8 @@ def content(self):

for dep_name in self.conanfile.deps_cpp_info.deps:
rootpath = self.conanfile.deps_cpp_info[dep_name].rootpath
for root, _, files in os.walk(os.path.normpath(rootpath)):
for root, dirs, files in os.walk(os.path.normpath(rootpath)):
files += [d for d in dirs if os.path.islink(os.path.join(root, d))]
for f in files:
if f in FILTERED_FILES:
continue
Expand All @@ -52,5 +53,6 @@ def content(self):
os.symlink(linkto, dst)
else:
shutil.copy(src, dst)
copied_files.append(dst)
if f not in dirs:
copied_files.append(dst)
return self.deploy_manifest_content(copied_files)
35 changes: 35 additions & 0 deletions conans/test/functional/generators/deploy_test.py
@@ -1,6 +1,7 @@
import os
import platform
import stat
import textwrap
import unittest

from conans import load
Expand Down Expand Up @@ -217,3 +218,37 @@ def test_existing_file_symbolic_links(self):
self.assertFalse(os.path.islink(header_path))
linkto = os.path.join(os.path.dirname(link_path), os.readlink(link_path))
self.assertEqual(linkto, header_path)


@unittest.skipIf(platform.system() == "Windows", "Symlinks in NIX systems only")
class DeployGeneratorSymbolicLinkFolderTest(unittest.TestCase):

def setUp(self):
conanfile = textwrap.dedent("""
Copy link
Contributor

Choose a reason for hiding this comment

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

We typically indent the content inside the textwrap.dedent

Copy link
Member

Choose a reason for hiding this comment

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

done!

import os
from conans import ConanFile, tools

class TestConan(ConanFile):

def package(self):
folder_path = os.path.join(self.package_folder, "one_folder")
tools.mkdir(folder_path)
link_folder_path = os.path.join(self.package_folder, "other_folder")
with tools.chdir(os.path.dirname(folder_path)):
os.symlink(os.path.basename(folder_path), link_folder_path)
""")
self.ref = ConanFileReference("name", "version", "user", "channel")
self.client = TurboTestClient()
self.client.create(self.ref, conanfile)

def test_symbolic_links(self):
self.client.current_folder = temp_folder()
self.client.run("install %s -g deploy" % self.ref.full_str())
base_path = os.path.join(self.client.current_folder, "name")
folder_path = os.path.join(base_path, "one_folder")
link_folder_path = os.path.join(base_path, "other_folder")
self.assertTrue(os.path.islink(link_folder_path))
self.assertFalse(os.path.islink(folder_path))
linkto_folder = os.path.join(os.path.dirname(link_folder_path),
os.readlink(link_folder_path))
self.assertEqual(linkto_folder, folder_path)