file(CONFIGURE): Fix newlines in CONTENT

Fixes: #21749
This commit is contained in:
Cristian Adam
2021-01-29 11:57:03 +01:00
parent 59b5b6e11c
commit 6e225efd8c
2 changed files with 14 additions and 7 deletions

View File

@@ -3105,15 +3105,13 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
cmSystemTools::MakeDirectory(path);
}
std::string newLineCharacters;
bool open_with_binary_flag = false;
std::string newLineCharacters = "\n";
if (newLineStyle.IsValid()) {
open_with_binary_flag = true;
newLineCharacters = newLineStyle.GetCharacters();
}
cmGeneratedFileStream fout;
fout.Open(outputFile, false, open_with_binary_flag);
fout.Open(outputFile, false, true);
if (!fout) {
cmSystemTools::Error("Could not open file for write in copy operation " +
outputFile);
@@ -3126,11 +3124,15 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
std::stringstream sin(parsedArgs.Content, std::ios::in);
std::string inLine;
std::string outLine;
while (cmSystemTools::GetLineFromStream(sin, inLine)) {
bool hasNewLine = false;
while (cmSystemTools::GetLineFromStream(sin, inLine, &hasNewLine)) {
outLine.clear();
makeFile.ConfigureString(inLine, outLine, parsedArgs.AtOnly,
parsedArgs.EscapeQuotes);
fout << outLine << newLineCharacters;
fout << outLine;
if (hasNewLine || newLineStyle.IsValid()) {
fout << newLineCharacters;
}
}
// close file before attempting to copy

View File

@@ -1,10 +1,13 @@
set(file_name ${CMAKE_CURRENT_BINARY_DIR}/NewLineStyle.txt)
function(test_eol style in out)
if (style)
set(newline_stle NEWLINE_STYLE ${style})
endif()
file(CONFIGURE
OUTPUT ${file_name}
CONTENT "@in@"
NEWLINE_STYLE ${style}
${newline_stle}
)
file(READ ${file_name} new HEX)
if(NOT "${new}" STREQUAL "${out}")
@@ -18,3 +21,5 @@ test_eol(CRLF "c" "630d0a")
test_eol(UNIX "d" "640a")
test_eol(LF "e" "650a")
test_eol("" "a\nb" "610a62")