diff options
Diffstat (limited to 'ninja/misc/ninja_syntax.py')
-rw-r--r-- | ninja/misc/ninja_syntax.py | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/ninja/misc/ninja_syntax.py b/ninja/misc/ninja_syntax.py index d69e3e49e2d..14b932ff4c8 100644 --- a/ninja/misc/ninja_syntax.py +++ b/ninja/misc/ninja_syntax.py @@ -8,10 +8,9 @@ use Python. """ import textwrap -import re def escape_path(word): - return word.replace('$ ','$$ ').replace(' ','$ ').replace(':', '$:') + return word.replace('$ ', '$$ ').replace(' ', '$ ').replace(':', '$:') class Writer(object): def __init__(self, output, width=78): @@ -61,21 +60,20 @@ class Writer(object): def build(self, outputs, rule, inputs=None, implicit=None, order_only=None, variables=None): outputs = self._as_list(outputs) - all_inputs = self._as_list(inputs)[:] - out_outputs = list(map(escape_path, outputs)) - all_inputs = list(map(escape_path, all_inputs)) + out_outputs = [escape_path(x) for x in outputs] + all_inputs = [escape_path(x) for x in self._as_list(inputs)] if implicit: - implicit = map(escape_path, self._as_list(implicit)) + implicit = [escape_path(x) for x in self._as_list(implicit)] all_inputs.append('|') all_inputs.extend(implicit) if order_only: - order_only = map(escape_path, self._as_list(order_only)) + order_only = [escape_path(x) for x in self._as_list(order_only)] all_inputs.append('||') all_inputs.extend(order_only) self._line('build %s: %s' % (' '.join(out_outputs), - ' '.join([rule] + all_inputs))) + ' '.join([rule] + all_inputs))) if variables: if isinstance(variables, dict): @@ -98,13 +96,13 @@ class Writer(object): self._line('default %s' % ' '.join(self._as_list(paths))) def _count_dollars_before_index(self, s, i): - """Returns the number of '$' characters right in front of s[i].""" - dollar_count = 0 - dollar_index = i - 1 - while dollar_index > 0 and s[dollar_index] == '$': - dollar_count += 1 - dollar_index -= 1 - return dollar_count + """Returns the number of '$' characters right in front of s[i].""" + dollar_count = 0 + dollar_index = i - 1 + while dollar_index > 0 and s[dollar_index] == '$': + dollar_count += 1 + dollar_index -= 1 + return dollar_count def _line(self, text, indent=0): """Write 'text' word-wrapped at self.width characters.""" @@ -117,19 +115,19 @@ class Writer(object): available_space = self.width - len(leading_space) - len(' $') space = available_space while True: - space = text.rfind(' ', 0, space) - if space < 0 or \ - self._count_dollars_before_index(text, space) % 2 == 0: - break + space = text.rfind(' ', 0, space) + if (space < 0 or + self._count_dollars_before_index(text, space) % 2 == 0): + break if space < 0: # No such space; just use the first unescaped space we can find. space = available_space - 1 while True: - space = text.find(' ', space + 1) - if space < 0 or \ - self._count_dollars_before_index(text, space) % 2 == 0: - break + space = text.find(' ', space + 1) + if (space < 0 or + self._count_dollars_before_index(text, space) % 2 == 0): + break if space < 0: # Give up on breaking. break |