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 cmake config file patching on Windows #3399

Merged
merged 15 commits into from Oct 8, 2018
@@ -301,12 +301,19 @@ def build(self):
cmake.install()
cmake.patch_config_paths()
"""

def _format_cmake_config_path(pathstr):
if platform.system() == "Windows":
drive,path = os.path.splitdrive(pathstr)
return drive.upper() + path.replace(os.path.sep,"/")
return pathstr

if not self._conanfile.should_install:
return
if not self._conanfile.name:
raise ConanException("cmake.patch_config_paths() can't work without package name. "
"Define name in your recipe")
pf = self.definitions.get(cmake_install_prefix_var_name)
pf = _format_cmake_config_path(self.definitions.get(cmake_install_prefix_var_name))
replstr = "${CONAN_%s_ROOT}" % self._conanfile.name.upper()
allwalk = chain(os.walk(self._conanfile.build_folder), os.walk(self._conanfile.package_folder))
for root, _, files in allwalk:
@@ -319,7 +326,7 @@ def build(self):
# current package
path_content = tools.load(path)
for dep in self._conanfile.deps_cpp_info.deps:
from_str = self._conanfile.deps_cpp_info[dep].rootpath
from_str = _format_cmake_config_path(self._conanfile.deps_cpp_info[dep].rootpath)
# try to replace only if from str is found
if path_content.find(from_str) != -1:
dep_str = "${CONAN_%s_ROOT}" % dep.upper()
@@ -22,6 +22,11 @@
from conans.model.options import Options, PackageOptions
from conans.errors import ConanException

def _format_cmake_config_path(pathstr):
if platform.system() == "Windows":
drive,path = os.path.splitdrive(pathstr)
return drive.upper() + path.replace(os.path.sep,"/")
return pathstr

class CMakeTest(unittest.TestCase):

@@ -30,10 +35,12 @@ def setUp(self):
self.tempdir2 = temp_folder(path_with_spaces=False)

def tearDown(self):
pass
This conversation was marked as resolved by weatherhead99

This comment has been minimized.

Copy link
@lasote

lasote Sep 27, 2018

Contributor

"pass" to be removed

shutil.rmtree(self.tempdir)
shutil.rmtree(self.tempdir2)

def config_patch_test(self):

conan_file = ConanFileMock()
conan_file.name = "MyPkg"
conan_file.settings = Settings()
@@ -42,7 +49,8 @@ def config_patch_test(self):
conan_file.package_folder = os.path.join(self.tempdir, "pkg")
conan_file.deps_cpp_info = DepsCppInfo()

msg = "FOLDER: " + conan_file.package_folder
msg = "FOLDER: " + _format_cmake_config_path(conan_file.package_folder)
print("msg: %s" % msg)
This conversation was marked as resolved by weatherhead99

This comment has been minimized.

Copy link
@lasote

lasote Sep 27, 2018

Contributor

"print" to be removed

This comment has been minimized.

Copy link
@weatherhead99

weatherhead99 Sep 27, 2018

Author Contributor

done

for folder in (conan_file.build_folder, conan_file.package_folder):
save(os.path.join(folder, "file1.cmake"), "Nothing")
save(os.path.join(folder, "file2"), msg)
@@ -79,7 +87,7 @@ def config_patch_deps_test(self):
self.assertEqual(conan_file.deps_cpp_info['MyPkg1'].rootpath,
self.tempdir2)

msg = "FOLDER: " + self.tempdir2
msg = "FOLDER: " + _format_cmake_config_path(self.tempdir2)
for folder in (conan_file.build_folder, conan_file.package_folder):
save(os.path.join(folder, "file1.cmake"), "Nothing")
save(os.path.join(folder, "file2"), msg)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.