diff options
author | Brad King <brad.king@kitware.com> | 2022-10-06 16:48:15 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-10-06 19:08:06 (GMT) |
commit | 85f01a1ec2203187d4cd99c74136774059b89b35 (patch) | |
tree | d7089498349f0b70c66f6ca5ce2b7c0f504ee850 | |
parent | aba48bd6acbf564dcb5b831b26cc01743b5b5f71 (diff) | |
download | CMake-85f01a1ec2203187d4cd99c74136774059b89b35.zip CMake-85f01a1ec2203187d4cd99c74136774059b89b35.tar.gz CMake-85f01a1ec2203187d4cd99c74136774059b89b35.tar.bz2 |
file(INSTALL): Improve formatting of symlink creation error
Avoid printing two error messages. Format paths without wrapping.
6 files changed, 53 insertions, 11 deletions
diff --git a/Source/cmFileCopier.cxx b/Source/cmFileCopier.cxx index 1667807..6ad7706 100644 --- a/Source/cmFileCopier.cxx +++ b/Source/cmFileCopier.cxx @@ -504,11 +504,12 @@ bool cmFileCopier::InstallSymlinkChain(std::string& fromFile, cmSystemTools::RemoveFile(toFile); cmSystemTools::MakeDirectory(toFilePath); - if (!cmSystemTools::CreateSymlink(symlinkTarget, toFile)) { - std::ostringstream e; - e << this->Name << " cannot create symlink \"" << toFile - << "\": " << cmSystemTools::GetLastSystemError() << "."; - this->Status.SetError(e.str()); + cmsys::Status status = + cmSystemTools::CreateSymlinkQuietly(symlinkTarget, toFile); + if (!status) { + std::string e = cmStrCat(this->Name, " cannot create symlink\n ", + toFile, "\nbecause: ", status.GetString()); + this->Status.SetError(e); return false; } } @@ -557,12 +558,13 @@ bool cmFileCopier::InstallSymlink(const std::string& fromFile, cmSystemTools::MakeDirectory(cmSystemTools::GetFilenamePath(toFile)); // Create the symlink. - if (!cmSystemTools::CreateSymlink(symlinkTarget, toFile)) { - std::ostringstream e; - e << this->Name << " cannot duplicate symlink \"" << fromFile - << "\" at \"" << toFile - << "\": " << cmSystemTools::GetLastSystemError() << "."; - this->Status.SetError(e.str()); + cmsys::Status status = + cmSystemTools::CreateSymlinkQuietly(symlinkTarget, toFile); + if (!status) { + std::string e = + cmStrCat(this->Name, " cannot duplicate symlink\n ", fromFile, + "\nat\n ", toFile, "\nbecause: ", status.GetString()); + this->Status.SetError(e); return false; } } diff --git a/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-result.txt b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stderr.txt b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stderr.txt new file mode 100644 index 0000000..cdde3e0 --- /dev/null +++ b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stderr.txt @@ -0,0 +1,12 @@ +^CMake Error at cmake_install.cmake:[0-9]+ \(file\): + file INSTALL cannot duplicate symlink + + [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/new/dir + + at + + [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/dir + + because: diff --git a/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stdout.txt b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stdout.txt new file mode 100644 index 0000000..e69ef02 --- /dev/null +++ b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stdout.txt @@ -0,0 +1,12 @@ +-- Installing: [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/dir +-- Installing: [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/dir/file +-- Installing: [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/lnk +-- Up-to-date: [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/lnk +-- Up-to-date: [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/lnk/file +-- Installing: [^ +]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/dir diff --git a/Tests/RunCMake/install/DIRECTORY-symlink-clobber.cmake b/Tests/RunCMake/install/DIRECTORY-symlink-clobber.cmake new file mode 100644 index 0000000..ac7a2cf --- /dev/null +++ b/Tests/RunCMake/install/DIRECTORY-symlink-clobber.cmake @@ -0,0 +1,11 @@ +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/old/dir) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/old/dir/file "") +file(CREATE_LINK dir ${CMAKE_CURRENT_BINARY_DIR}/old/lnk SYMBOLIC) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/old/dir DESTINATION dest) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/old/lnk DESTINATION dest) + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/new/lnk) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/new/lnk/file "") +file(CREATE_LINK lnk ${CMAKE_CURRENT_BINARY_DIR}/new/dir SYMBOLIC) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/new/lnk DESTINATION dest) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/new/dir DESTINATION dest) diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake index 7c12d4a..477ffe0 100644 --- a/Tests/RunCMake/install/RunCMakeTest.cmake +++ b/Tests/RunCMake/install/RunCMakeTest.cmake @@ -175,6 +175,10 @@ run_install_test(FILES-PERMISSIONS) run_install_test(TARGETS-RPATH) run_install_test(InstallRequiredSystemLibraries) +if(UNIX) + run_install_test(DIRECTORY-symlink-clobber) +endif() + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") run_cmake(TARGETS-RUNTIME_DEPENDENCIES-macos-two-bundle) run_cmake(TARGETS-RUNTIME_DEPENDENCIES-macos-no-framework) |