summaryrefslogtreecommitdiffstats
path: root/Source/cmRulePlaceholderExpander.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-03-26 13:13:37 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-03-26 13:13:45 (GMT)
commit6257d43ffd18544a75596a2e21c2accc809d61c3 (patch)
tree6d507203b7b2340160fdafe0de2ff6c196521ac5 /Source/cmRulePlaceholderExpander.cxx
parent4e74a59ab55cf0c1332a61a379b79b9c6f1cf1d5 (diff)
parente565053bced999a90b95693c21dbe368990e01eb (diff)
downloadCMake-6257d43ffd18544a75596a2e21c2accc809d61c3.zip
CMake-6257d43ffd18544a75596a2e21c2accc809d61c3.tar.gz
CMake-6257d43ffd18544a75596a2e21c2accc809d61c3.tar.bz2
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
Diffstat (limited to 'Source/cmRulePlaceholderExpander.cxx')
-rw-r--r--Source/cmRulePlaceholderExpander.cxx10
1 files changed, 10 insertions, 0 deletions
diff --git a/Source/cmRulePlaceholderExpander.cxx b/Source/cmRulePlaceholderExpander.cxx
index 05086f0..254131b 100644
--- a/Source/cmRulePlaceholderExpander.cxx
+++ b/Source/cmRulePlaceholderExpander.cxx
@@ -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;