summaryrefslogtreecommitdiffstats
path: root/Source/cmRulePlaceholderExpander.cxx
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2020-03-23 17:02:11 (GMT)
committerDaan De Meyer <daan.j.demeyer@gmail.com>2020-03-23 20:34:19 (GMT)
commit5d4bab500e93052630163577815695ac3f47ba7b (patch)
treece08a20d9e4a6cddf8f843c9f8e5c49eecb69781 /Source/cmRulePlaceholderExpander.cxx
parentd8622fbd0fe1ad7db1e22089464342f329426e9e (diff)
downloadCMake-5d4bab500e93052630163577815695ac3f47ba7b.zip
CMake-5d4bab500e93052630163577815695ac3f47ba7b.tar.gz
CMake-5d4bab500e93052630163577815695ac3f47ba7b.tar.bz2
Avoid consecutive whitespace in rules
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 5ab1b3a..99b0d5c 100644
--- a/Source/cmRulePlaceholderExpander.cxx
+++ b/Source/cmRulePlaceholderExpander.cxx
@@ -334,7 +334,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;