Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 import os.path | 3 import os.path |
| 4 import re | 4 import re |
| 5 import subprocess | 5 import subprocess |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 from name_utilities import enum_for_css_keyword | 8 from name_utilities import enum_for_css_keyword |
| 9 from name_utilities import upper_first_letter | 9 from name_utilities import upper_first_letter |
| 10 import json5_generator | 10 import json5_generator |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 'value_keyword_strings': '\n'.join(' "%(name)s\\0"' % keyword for keyword in self._value_keywords), | 167 'value_keyword_strings': '\n'.join(' "%(name)s\\0"' % keyword for keyword in self._value_keywords), |
| 168 'value_keyword_offsets': '\n'.join(' %d,' % offset for offset in ke yword_offsets), | 168 'value_keyword_offsets': '\n'.join(' %d,' % offset for offset in ke yword_offsets), |
| 169 'value_keyword_to_enum_map': '\n'.join('%(lower_name)s, %(enum_name) s' % keyword for keyword in self._value_keywords), | 169 'value_keyword_to_enum_map': '\n'.join('%(lower_name)s, %(enum_name) s' % keyword for keyword in self._value_keywords), |
| 170 'ua_sheet_mode_values_keywords': '\n '.join(map(self._case_va lue_keyword, self._value_keywords_with_mode('UASheet'))), | 170 'ua_sheet_mode_values_keywords': '\n '.join(map(self._case_va lue_keyword, self._value_keywords_with_mode('UASheet'))), |
| 171 'quirks_mode_or_ua_sheet_mode_values_keywords': '\n '.join(map(se lf._case_value_keyword, self._value_keywords_with_mode('QuirksOrUASheet'))), | 171 'quirks_mode_or_ua_sheet_mode_values_keywords': '\n '.join(map(se lf._case_value_keyword, self._value_keywords_with_mode('QuirksOrUASheet'))), |
| 172 } | 172 } |
| 173 # FIXME: If we could depend on Python 2.7, we would use subprocess.check _output | 173 # FIXME: If we could depend on Python 2.7, we would use subprocess.check _output |
| 174 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 174 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
| 175 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 175 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
| 176 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 176 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
| 177 gperf_args.extend(['-Q', 'ValueStringPool']) # Unique var names. | |
|
fs
2017/07/07 12:58:30
Maybe CSSValueStringPool?
Daniel Bratell
2017/07/07 13:20:50
Done.
| |
| 177 | 178 |
| 178 # If gperf isn't in the path we get an OSError. We don't want to use | 179 # If gperf isn't in the path we get an OSError. We don't want to use |
| 179 # the normal solution of shell=True (as this has to run on many | 180 # the normal solution of shell=True (as this has to run on many |
| 180 # platforms), so instead we catch the error and raise a | 181 # platforms), so instead we catch the error and raise a |
| 181 # CalledProcessError like subprocess would do when shell=True is set. | 182 # CalledProcessError like subprocess would do when shell=True is set. |
| 182 try: | 183 try: |
| 183 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s ubprocess.PIPE, universal_newlines=True) | 184 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s ubprocess.PIPE, universal_newlines=True) |
| 184 return gperf.communicate(gperf_input)[0] | 185 return gperf.communicate(gperf_input)[0] |
| 185 except OSError: | 186 except OSError: |
| 186 raise subprocess.CalledProcessError(127, gperf_args, output='Command not found.') | 187 raise subprocess.CalledProcessError(127, gperf_args, output='Command not found.') |
| 187 | 188 |
| 188 | 189 |
| 189 if __name__ == "__main__": | 190 if __name__ == "__main__": |
| 190 json5_generator.Maker(CSSValueKeywordsWriter).main() | 191 json5_generator.Maker(CSSValueKeywordsWriter).main() |
| OLD | NEW |