mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
Restore handling of build directory inside a symlinked path
In commit dd8365b3f1
(Merge branch 'upstream-KWSys' into update-kwsys,
2020-04-06, v3.18.0-rc1~397^2) we imported KWSys commit `019afb6ea`
(SystemTools: Drop GetCurrentWorkingDirectory 'collapse' argument,
2020-04-03). That caused `GetCurrentWorkingDirectory` to no longer send
paths through the KWSys translation map and broke CMake's detection of
the absolute path to a build directory containing a symbolic link.
Add our own `cmSystemTools::GetCurrentWorkingDirectory` wrapper around
the KWSys method in order to restore that mapping.
Test-case-by: Ben Boeckel <ben.boeckel@kitware.com>
Issue: #16228
Fixes: #20900
This commit is contained in:
@@ -312,7 +312,7 @@ int main(int argc, char const* const* argv)
|
|||||||
// The value has not been set on the command line
|
// The value has not been set on the command line
|
||||||
else {
|
else {
|
||||||
// get a default value (current working directory)
|
// get a default value (current working directory)
|
||||||
cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory();
|
cpackProjectDirectory = cmSystemTools::GetCurrentWorkingDirectory();
|
||||||
// use default value if no value has been provided by the config file
|
// use default value if no value has been provided by the config file
|
||||||
if (!globalMF.IsSet("CPACK_PACKAGE_DIRECTORY")) {
|
if (!globalMF.IsSet("CPACK_PACKAGE_DIRECTORY")) {
|
||||||
globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY",
|
globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY",
|
||||||
|
@@ -2080,6 +2080,12 @@ std::string const& cmSystemTools::GetCMakeRoot()
|
|||||||
return cmSystemToolsCMakeRoot;
|
return cmSystemToolsCMakeRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string cmSystemTools::GetCurrentWorkingDirectory()
|
||||||
|
{
|
||||||
|
return cmSystemTools::CollapseFullPath(
|
||||||
|
cmsys::SystemTools::GetCurrentWorkingDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
void cmSystemTools::MakefileColorEcho(int color, const char* message,
|
void cmSystemTools::MakefileColorEcho(int color, const char* message,
|
||||||
bool newline, bool enabled)
|
bool newline, bool enabled)
|
||||||
{
|
{
|
||||||
|
@@ -390,6 +390,9 @@ public:
|
|||||||
static std::string const& GetCMClDepsCommand();
|
static std::string const& GetCMClDepsCommand();
|
||||||
static std::string const& GetCMakeRoot();
|
static std::string const& GetCMakeRoot();
|
||||||
|
|
||||||
|
/** Get the CWD mapped through the KWSys translation map. */
|
||||||
|
static std::string GetCurrentWorkingDirectory();
|
||||||
|
|
||||||
/** Echo a message in color using KWSys's Terminal cprintf. */
|
/** Echo a message in color using KWSys's Terminal cprintf. */
|
||||||
static void MakefileColorEcho(int color, const char* message, bool newLine,
|
static void MakefileColorEcho(int color, const char* message, bool newLine,
|
||||||
bool enabled);
|
bool enabled);
|
||||||
|
@@ -436,6 +436,10 @@ else()
|
|||||||
message(STATUS "Could not find ctresalloc")
|
message(STATUS "Could not find ctresalloc")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT WIN32)
|
||||||
|
add_RunCMake_test(SymlinkTrees)
|
||||||
|
endif ()
|
||||||
|
|
||||||
find_package(Qt4 QUIET)
|
find_package(Qt4 QUIET)
|
||||||
find_package(Qt5Core QUIET)
|
find_package(Qt5Core QUIET)
|
||||||
if (QT4_FOUND AND Qt5Core_FOUND AND NOT Qt5Core_VERSION VERSION_LESS 5.1.0)
|
if (QT4_FOUND AND Qt5Core_FOUND AND NOT Qt5Core_VERSION VERSION_LESS 5.1.0)
|
||||||
|
3
Tests/RunCMake/SymlinkTrees/CMakeLists.txt
Normal file
3
Tests/RunCMake/SymlinkTrees/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
project(${RunCMake_TEST} NONE)
|
||||||
|
include("${include_dir}/${RunCMake_TEST}.cmake")
|
6
Tests/RunCMake/SymlinkTrees/PrintTrees.cmake
Normal file
6
Tests/RunCMake/SymlinkTrees/PrintTrees.cmake
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
message(STATUS "source: '${CMAKE_SOURCE_DIR}'")
|
||||||
|
message(STATUS "binary: '${CMAKE_BINARY_DIR}'")
|
||||||
|
get_filename_component(real_source "${CMAKE_SOURCE_DIR}" REALPATH)
|
||||||
|
get_filename_component(real_binary "${CMAKE_BINARY_DIR}" REALPATH)
|
||||||
|
message(STATUS "real source: '${real_source}'")
|
||||||
|
message(STATUS "real binary: '${real_binary}'")
|
34
Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake
Normal file
34
Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
# This function assumes that ``${RunCMake_BINARY_DIR}/${name}/source`` and
|
||||||
|
# ``${RunCMake_BINARY_DIR}/${name}/binary`` are set up properly prior to
|
||||||
|
# calling it.
|
||||||
|
function (run_symlink_test name)
|
||||||
|
set(RunCMake_TEST_NO_CLEAN TRUE)
|
||||||
|
configure_file(
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt"
|
||||||
|
"${RunCMake_BINARY_DIR}/${name}/source/CMakeLists.txt"
|
||||||
|
COPYONLY)
|
||||||
|
set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/${name}/source")
|
||||||
|
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${name}/binary")
|
||||||
|
# Emulate a shell using this directory.
|
||||||
|
set(ENV{PWD} "${RunCMake_TEST_BINARY_DIR}")
|
||||||
|
set(RunCMake_TEST_OPTIONS
|
||||||
|
"-Dinclude_dir:PATH=${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
run_cmake("${name}_symlinks")
|
||||||
|
endfunction ()
|
||||||
|
|
||||||
|
# Create the following structure:
|
||||||
|
#
|
||||||
|
# .../common_real/source
|
||||||
|
# .../common_real/binary
|
||||||
|
# .../common -> common_real
|
||||||
|
#
|
||||||
|
# In this case, CMake should act as if .../common *is* .../common_real for all
|
||||||
|
# computations except ``REALPATH``. This supports the case where a system has
|
||||||
|
# a stable *symlink*, but not a stable target for that symlink.
|
||||||
|
file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/common_real")
|
||||||
|
file(REMOVE "${RunCMake_BINARY_DIR}/common")
|
||||||
|
file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/common_real/source")
|
||||||
|
file(CREATE_LINK "common_real" "${RunCMake_BINARY_DIR}/common" SYMBOLIC)
|
||||||
|
run_symlink_test(common)
|
4
Tests/RunCMake/SymlinkTrees/common_symlinks-stdout.txt
Normal file
4
Tests/RunCMake/SymlinkTrees/common_symlinks-stdout.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
-- source: '[^']*/Tests/RunCMake/SymlinkTrees/common/source'
|
||||||
|
-- binary: '[^']*/Tests/RunCMake/SymlinkTrees/common/binary'
|
||||||
|
-- real source: '[^']*/Tests/RunCMake/SymlinkTrees/common_real/source'
|
||||||
|
-- real binary: '[^']*/Tests/RunCMake/SymlinkTrees/common_real/binary'
|
1
Tests/RunCMake/SymlinkTrees/common_symlinks.cmake
Normal file
1
Tests/RunCMake/SymlinkTrees/common_symlinks.cmake
Normal file
@@ -0,0 +1 @@
|
|||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/PrintTrees.cmake")
|
Reference in New Issue
Block a user