mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-10 07:40:03 -06:00
Merge topic 'get_filename_component-REALPATH-symlink-parent'
c554437733 get_filename_component: Fix REALPATH for .. after symlink
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10025
This commit is contained in:
@@ -107,9 +107,15 @@ bool cmGetFilenameComponentCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
}
|
||||
}
|
||||
// Collapse the path to its simplest form.
|
||||
result = cmSystemTools::CollapseFullPath(filename, baseDir);
|
||||
if (args[2] == "REALPATH") {
|
||||
if (args[2] == "ABSOLUTE") {
|
||||
// Collapse the path to its simplest form.
|
||||
result = cmSystemTools::CollapseFullPath(filename, baseDir);
|
||||
} else {
|
||||
// Convert relative paths to absolute paths
|
||||
result = filename;
|
||||
if (!cmSystemTools::FileIsFullPath(result)) {
|
||||
result = cmStrCat(baseDir, '/', result);
|
||||
}
|
||||
// Resolve symlinks if possible
|
||||
result = cmSystemTools::GetRealPath(result);
|
||||
}
|
||||
|
||||
@@ -159,3 +159,11 @@ foreach(thisVar ${non_cache_vars})
|
||||
message(SEND_ERROR "${thisVar} not found in regular variable list.")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(UNIX)
|
||||
file(MAKE_DIRECTORY . "${CMAKE_CURRENT_BINARY_DIR}/subdir")
|
||||
file(CREATE_LINK . "${CMAKE_CURRENT_BINARY_DIR}/subdir/symlink-to-dot" SYMBOLIC)
|
||||
get_filename_component(realpath_actual "${CMAKE_CURRENT_BINARY_DIR}/subdir/symlink-to-dot/.." REALPATH)
|
||||
get_filename_component(realpath_expect "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)
|
||||
check("symlink parent" "${realpath_actual}" "${realpath_expect}")
|
||||
endif(UNIX)
|
||||
|
||||
Reference in New Issue
Block a user