mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Merge topic 'ninja-trailing-newline-comment' into release-4.1
12a225d56d
Ninja: handle trailing newlines in variable stanzas
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11286
This commit is contained in:
@@ -521,6 +521,13 @@ void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
|
||||
if (variablesShouldNotBeTrimmed.find(name) ==
|
||||
variablesShouldNotBeTrimmed.end()) {
|
||||
val = cmTrimWhitespace(value);
|
||||
// If the value ends with `\n` and a `$` was left at the end of the trimmed
|
||||
// value, put the newline back. Otherwise the next stanza is hidden by the
|
||||
// trailing `$` escaping the newline.
|
||||
if (cmSystemTools::StringEndsWith(value, "\n") &&
|
||||
cmSystemTools::StringEndsWith(val, "$")) {
|
||||
val += '\n';
|
||||
}
|
||||
} else {
|
||||
val = value;
|
||||
}
|
||||
|
11
Tests/RunCMake/Ninja/CommentsWithTrailingNewlines.cmake
Normal file
11
Tests/RunCMake/Ninja/CommentsWithTrailingNewlines.cmake
Normal file
@@ -0,0 +1,11 @@
|
||||
enable_language(C)
|
||||
|
||||
add_executable(comments_with_newlines hello.c)
|
||||
add_custom_command(TARGET comments_with_newlines PRE_LINK
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo prelink
|
||||
COMMENT "prelink with trailing newline
|
||||
")
|
||||
add_custom_command(TARGET comments_with_newlines POST_BUILD
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo postbuild
|
||||
COMMENT "postbuild with trailing newline
|
||||
")
|
@@ -81,6 +81,7 @@ function(run_WithBuild name)
|
||||
endfunction()
|
||||
run_WithBuild(CommentsWithDollars)
|
||||
run_WithBuild(CommentsWithNewlines)
|
||||
run_WithBuild(CommentsWithTrailingNewlines)
|
||||
|
||||
function(run_VerboseBuild)
|
||||
run_cmake(VerboseBuild)
|
||||
|
Reference in New Issue
Block a user