1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 19:43:23 +08:00

Avoid consecutive whitespace in rules

This commit is contained in:
Daan De Meyer
2020-03-23 18:02:11 +01:00
parent d8622fbd0f
commit 5d4bab500e
2 changed files with 14 additions and 2 deletions

View File

@@ -877,7 +877,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
if ((sep[0] != ' ') && !flags.empty() && flags.back() == sep[0]) { if ((sep[0] != ' ') && !flags.empty() && flags.back() == sep[0]) {
flags.back() = ' '; flags.back() = ' ';
} }
return flags; return cmTrimWhitespace(flags);
} }
void cmLocalGenerator::AddCompileOptions(std::string& flags, void cmLocalGenerator::AddCompileOptions(std::string& flags,
@@ -2396,7 +2396,9 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
void cmLocalGenerator::AppendFlags(std::string& flags, void cmLocalGenerator::AppendFlags(std::string& flags,
const std::string& newFlags) const 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()) { if (!flags.empty()) {
flags += " "; flags += " ";
} }

View File

@@ -334,7 +334,17 @@ void cmRulePlaceholderExpander::ExpandRuleVariables(
std::string replace = std::string replace =
this->ExpandRuleVariable(outputConverter, var, replaceValues); this->ExpandRuleVariable(outputConverter, var, replaceValues);
expandedInput += s.substr(pos, start - pos); 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; expandedInput += replace;
// move to next one // move to next one
start = s.find('<', start + var.size() + 2); start = s.find('<', start + var.size() + 2);
pos = end + 1; pos = end + 1;