OLD | NEW |
1 # This file comes from | 1 # This file comes from |
2 # https://github.com/martine/ninja/blob/master/misc/ninja_syntax.py | 2 # https://github.com/martine/ninja/blob/master/misc/ninja_syntax.py |
3 # Do not edit! Edit the upstream one instead. | 3 # Do not edit! Edit the upstream one instead. |
4 | 4 |
5 """Python module for generating .ninja files. | 5 """Python module for generating .ninja files. |
6 | 6 |
7 Note that this is emphatically not a required piece of Ninja; it's | 7 Note that this is emphatically not a required piece of Ninja; it's |
8 just a helpful utility for build-file-generation systems that already | 8 just a helpful utility for build-file-generation systems that already |
9 use Python. | 9 use Python. |
10 """ | 10 """ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 self.variable('restat', '1', indent=1) | 51 self.variable('restat', '1', indent=1) |
52 if rspfile: | 52 if rspfile: |
53 self.variable('rspfile', rspfile, indent=1) | 53 self.variable('rspfile', rspfile, indent=1) |
54 if rspfile_content: | 54 if rspfile_content: |
55 self.variable('rspfile_content', rspfile_content, indent=1) | 55 self.variable('rspfile_content', rspfile_content, indent=1) |
56 | 56 |
57 def build(self, outputs, rule, inputs=None, implicit=None, order_only=None, | 57 def build(self, outputs, rule, inputs=None, implicit=None, order_only=None, |
58 variables=None): | 58 variables=None): |
59 outputs = self._as_list(outputs) | 59 outputs = self._as_list(outputs) |
60 all_inputs = self._as_list(inputs)[:] | 60 all_inputs = self._as_list(inputs)[:] |
61 out_outputs = map(escape_spaces, outputs) | 61 out_outputs = list(map(escape_spaces, outputs)) |
62 all_inputs = map(escape_spaces, all_inputs) | 62 all_inputs = list(map(escape_spaces, all_inputs)) |
63 | 63 |
64 if implicit: | 64 if implicit: |
65 implicit = map(escape_spaces, self._as_list(implicit)) | 65 implicit = map(escape_spaces, self._as_list(implicit)) |
66 all_inputs.append('|') | 66 all_inputs.append('|') |
67 all_inputs.extend(implicit) | 67 all_inputs.extend(implicit) |
68 if order_only: | 68 if order_only: |
69 order_only = map(escape_spaces, self._as_list(order_only)) | 69 order_only = map(escape_spaces, self._as_list(order_only)) |
70 all_inputs.append('||') | 70 all_inputs.append('||') |
71 all_inputs.extend(order_only) | 71 all_inputs.extend(order_only) |
72 | 72 |
73 self._line('build %s: %s %s' % (' '.join(out_outputs), | 73 self._line('build %s: %s %s' % (' '.join(out_outputs), |
74 rule, | 74 rule, |
75 ' '.join(all_inputs))) | 75 ' '.join(all_inputs))) |
76 | 76 |
77 if variables: | 77 if variables: |
78 for key, val in variables: | 78 if isinstance(variables, dict): |
| 79 iterator = variables.iteritems() |
| 80 else: |
| 81 iterator = iter(variables) |
| 82 |
| 83 for key, val in iterator: |
79 self.variable(key, val, indent=1) | 84 self.variable(key, val, indent=1) |
80 | 85 |
81 return outputs | 86 return outputs |
82 | 87 |
83 def include(self, path): | 88 def include(self, path): |
84 self._line('include %s' % path) | 89 self._line('include %s' % path) |
85 | 90 |
86 def subninja(self, path): | 91 def subninja(self, path): |
87 self._line('subninja %s' % path) | 92 self._line('subninja %s' % path) |
88 | 93 |
89 def default(self, paths): | 94 def default(self, paths): |
90 self._line('default %s' % ' '.join(self._as_list(paths))) | 95 self._line('default %s' % ' '.join(self._as_list(paths))) |
91 | 96 |
92 def _count_dollars_before_index(self, s, i): | 97 def _count_dollars_before_index(self, s, i): |
93 """Returns the number of '$' characters right in front of s[i].""" | 98 """Returns the number of '$' characters right in front of s[i].""" |
94 dollar_count = 0 | 99 dollar_count = 0 |
95 dollar_index = i - 1 | 100 dollar_index = i - 1 |
96 while dollar_index > 0 and s[dollar_index] == '$': | 101 while dollar_index > 0 and s[dollar_index] == '$': |
97 dollar_count += 1 | 102 dollar_count += 1 |
98 dollar_index -= 1 | 103 dollar_index -= 1 |
99 return dollar_count | 104 return dollar_count |
100 | 105 |
101 def _line(self, text, indent=0): | 106 def _line(self, text, indent=0): |
102 """Write 'text' word-wrapped at self.width characters.""" | 107 """Write 'text' word-wrapped at self.width characters.""" |
103 leading_space = ' ' * indent | 108 leading_space = ' ' * indent |
104 while len(text) > self.width: | 109 while len(leading_space) + len(text) > self.width: |
105 # The text is too wide; wrap if possible. | 110 # The text is too wide; wrap if possible. |
106 | 111 |
107 # Find the rightmost space that would obey our width constraint and | 112 # Find the rightmost space that would obey our width constraint and |
108 # that's not an escaped space. | 113 # that's not an escaped space. |
109 available_space = self.width - len(leading_space) - len(' $') | 114 available_space = self.width - len(leading_space) - len(' $') |
110 space = available_space | 115 space = available_space |
111 while True: | 116 while True: |
112 space = text.rfind(' ', 0, space) | 117 space = text.rfind(' ', 0, space) |
113 if space < 0 or \ | 118 if space < 0 or \ |
114 self._count_dollars_before_index(text, space) % 2 == 0: | 119 self._count_dollars_before_index(text, space) % 2 == 0: |
(...skipping 26 matching lines...) Expand all Loading... |
141 return input | 146 return input |
142 return [input] | 147 return [input] |
143 | 148 |
144 | 149 |
145 def escape(string): | 150 def escape(string): |
146 """Escape a string such that it can be embedded into a Ninja file without | 151 """Escape a string such that it can be embedded into a Ninja file without |
147 further interpretation.""" | 152 further interpretation.""" |
148 assert '\n' not in string, 'Ninja syntax does not allow newlines' | 153 assert '\n' not in string, 'Ninja syntax does not allow newlines' |
149 # We only have one special metacharacter: '$'. | 154 # We only have one special metacharacter: '$'. |
150 return string.replace('$', '$$') | 155 return string.replace('$', '$$') |
OLD | NEW |