Преглед изворни кода

Merge topic 'revert-get_filename_component-REALPATH-symlink-parent'

94d65a9535 get_filename_component: Restore lexical preprocessing of REALPATH for compat

Acked-by: Kitware Robot <[email protected]>
Merge-request: !10564
Brad King пре 10 месеци
родитељ
комит
4e8495bc11

+ 3 - 9
Source/cmGetFilenameComponentCommand.cxx

@@ -107,15 +107,9 @@ bool cmGetFilenameComponentCommand(std::vector<std::string> const& args,
         }
       }
     }
-    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);
-      }
+    // Collapse the path to its simplest form.
+    result = cmSystemTools::CollapseFullPath(filename, baseDir);
+    if (args[2] == "REALPATH") {
       // Resolve symlinks if possible
       result = cmSystemTools::GetRealPath(result);
     }

+ 16 - 0
Tests/CMakeTests/GetFilenameComponentRealpathTest.cmake.in

@@ -12,6 +12,22 @@ if(NOT nonexistent2 STREQUAL "${bindir}/THIS_IS_A_NONEXISTENT_FILE")
     message(FATAL_ERROR "ABSOLUTE is not preserving nonexistent files")
 endif()
 
+#
+# Test treatment of .. after file name
+#
+foreach(c REALPATH ABSOLUTE)
+  get_filename_component(dir "${CMAKE_CURRENT_LIST_DIR}" ${c})
+  get_filename_component(fileDotDot "${CMAKE_CURRENT_LIST_FILE}/.." ${c})
+  if(NOT "${fileDotDot}" STREQUAL "${dir}")
+    message(FATAL_ERROR
+      "${c} did not resolve\n"
+      "  ${CMAKE_CURRENT_LIST_FILE}/..\n"
+      "lexically:\n"
+      "  ${fileDotDot}"
+    )
+  endif()
+endforeach()
+
 #
 # Test treatment of relative paths
 #

+ 0 - 8
Tests/RunCMake/get_filename_component/KnownComponents.cmake

@@ -159,11 +159,3 @@ 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)