mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-23 14:48:19 -05:00
Merge topic 'compile-commands-collapse-whitespace'
e565053bceNinja: Remove unnecessary newlines in compile commands5d4bab500eAvoid consecutive whitespace in rulesd8622fbd0fModules: Collapse consecutive whitespace in strings Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4512
This commit is contained in:
@@ -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": ")"
|
||||
|
||||
@@ -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 += " ";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user