Commit 0692eaf0 authored by Craig Scott's avatar Craig Scott

ForceToRelativePath: Fix spurious assertion when local path is root dir

Fixes: #19909
parent c1d5d5eb
......@@ -1120,8 +1120,13 @@ std::string cmSystemTools::ForceToRelativePath(std::string const& local_path,
assert(local_path.front() != '\"');
assert(remote_path.front() != '\"');
// The local path should never have a trailing slash.
assert(local_path.empty() || local_path.back() != '/');
// The local path should never have a trailing slash except if it is just the
// bare root directory
assert(local_path.empty() || local_path.back() != '/' ||
local_path.size() == 1 ||
(local_path.size() == 3 && local_path[1] == ':' &&
((local_path[0] >= 'A' && local_path[0] <= 'Z') ||
(local_path[0] >= 'a' && local_path[0] <= 'z'))));
// If the path is already relative then just return the path.
if (!cmSystemTools::FileIsFullPath(remote_path)) {
......
......@@ -5,6 +5,15 @@ run_cmake(nomessage)
run_cmake(message-internal-warning)
run_cmake(nomessage-internal-warning)
run_cmake(warnmessage)
# Have to explicitly give the command for the working dir to be honoured
set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY /)
run_cmake_command(
warnmessage-rootdir
${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/warnmessage-rootdir.cmake
)
unset(RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
# message command sets fatal occurred flag, so check each type of error
# separately
......
We expect to see this warning message
cmake_minimum_required(VERSION 3.15)
# Generating the backtrace for this warning message used to trigger a
# spurious assertion when the current directory is the root directory
message(WARNING "We expect to see this warning message")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment