OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import subprocess | 3 import subprocess |
4 import sys | 4 import sys |
5 | 5 |
6 import css_properties | 6 import css_properties |
7 import json5_generator | 7 import json5_generator |
8 import license | 8 import license |
9 | 9 |
10 | 10 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 'license': license.license_for_generated_cpp(), | 243 'license': license.license_for_generated_cpp(), |
244 'class_name': self.class_name, | 244 'class_name': self.class_name, |
245 'property_name_strings': '\n'.join(' "%s\\0"' % name for name in
property_names), | 245 'property_name_strings': '\n'.join(' "%s\\0"' % name for name in
property_names), |
246 'property_name_offsets': '\n'.join(' %d,' % offset for offset in
property_offsets), | 246 'property_name_offsets': '\n'.join(' %d,' % offset for offset in
property_offsets), |
247 'property_to_enum_map': '\n'.join('%s, %s' % property for property i
n css_name_and_enum_pairs), | 247 'property_to_enum_map': '\n'.join('%s, %s' % property for property i
n css_name_and_enum_pairs), |
248 } | 248 } |
249 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 249 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
250 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 250 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
251 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 251 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
252 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 252 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
| 253 gperf_args.extend(['-Q', 'CSSPropStringPool']) # Unique var names. |
253 | 254 |
254 # If gperf isn't in the path we get an OSError. We don't want to use | 255 # If gperf isn't in the path we get an OSError. We don't want to use |
255 # the normal solution of shell=True (as this has to run on many | 256 # the normal solution of shell=True (as this has to run on many |
256 # platforms), so instead we catch the error and raise a | 257 # platforms), so instead we catch the error and raise a |
257 # CalledProcessError like subprocess would do when shell=True is set. | 258 # CalledProcessError like subprocess would do when shell=True is set. |
258 try: | 259 try: |
259 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s
ubprocess.PIPE, universal_newlines=True) | 260 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s
ubprocess.PIPE, universal_newlines=True) |
260 return gperf.communicate(gperf_input)[0] | 261 return gperf.communicate(gperf_input)[0] |
261 except OSError: | 262 except OSError: |
262 raise subprocess.CalledProcessError(127, gperf_args, output='Command
not found.') | 263 raise subprocess.CalledProcessError(127, gperf_args, output='Command
not found.') |
263 | 264 |
264 | 265 |
265 if __name__ == "__main__": | 266 if __name__ == "__main__": |
266 json5_generator.Maker(CSSPropertyNamesWriter).main() | 267 json5_generator.Maker(CSSPropertyNamesWriter).main() |
OLD | NEW |