Merge topic 'compile-commands-collapse-whitespace'

e565053bce Ninja: Remove unnecessary newlines in compile commands
5d4bab500e Avoid consecutive whitespace in rules
d8622fbd0f Modules: Collapse consecutive whitespace in strings

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4512
This commit is contained in:
Brad King
2020-03-26 13:13:37 +00:00
committed by Kitware Robot
26 changed files with 61 additions and 49 deletions
+2 -2
View File
@@ -1009,7 +1009,7 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand(
// Get a stream where to generate things.
this->CompileCommandsStream =
cm::make_unique<cmGeneratedFileStream>(buildFilePath);
*this->CompileCommandsStream << "[";
*this->CompileCommandsStream << "[\n";
} else {
*this->CompileCommandsStream << "," << std::endl;
}
@@ -1021,7 +1021,7 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand(
}
/* clang-format off */
*this->CompileCommandsStream << "\n{\n"
*this->CompileCommandsStream << "{\n"
<< R"( "directory": ")"
<< cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
<< R"( "command": ")"
+4 -2
View File
@@ -877,7 +877,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
if ((sep[0] != ' ') && !flags.empty() && flags.back() == sep[0]) {
flags.back() = ' ';
}
return flags;
return cmTrimWhitespace(flags);
}
void cmLocalGenerator::AddCompileOptions(std::string& flags,
@@ -2396,7 +2396,9 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
void cmLocalGenerator::AppendFlags(std::string& flags,
const std::string& newFlags) const
{
if (!newFlags.empty()) {
bool allSpaces = std::all_of(newFlags.begin(), newFlags.end(), cmIsSpace);
if (!newFlags.empty() && !allSpaces) {
if (!flags.empty()) {
flags += " ";
}
+10
View File
@@ -333,7 +333,17 @@ void cmRulePlaceholderExpander::ExpandRuleVariables(
std::string replace =
this->ExpandRuleVariable(outputConverter, var, replaceValues);
expandedInput += s.substr(pos, start - pos);
// Prevent consecutive whitespace in the output if the rule variable
// expands to an empty string.
bool consecutive = replace.empty() && start > 0 && s[start - 1] == ' ' &&
end + 1 < s.size() && s[end + 1] == ' ';
if (consecutive) {
expandedInput.pop_back();
}
expandedInput += replace;
// move to next one
start = s.find('<', start + var.size() + 2);
pos = end + 1;