OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 # usage: rule_gperf.py INPUT_FILE OUTPUT_DIR |
| 8 # INPUT_FILE is a path to DocTypeStrings.gperf, HTMLEntityNames.gperf, or |
| 9 # ColorData.gperf. |
| 10 # OUTPUT_DIR is where the gperf-generated .cpp file should be placed. Because |
| 11 # some users want a .c file instead of a .cpp file, the .cpp file is copied |
| 12 # to .c when done. |
| 13 |
| 14 import posixpath |
| 15 import shutil |
| 16 import subprocess |
| 17 import sys |
| 18 |
| 19 assert len(sys.argv) == 3 |
| 20 |
| 21 input_file = sys.argv[1] |
| 22 output_dir = sys.argv[2] |
| 23 |
| 24 gperf_commands = { |
| 25 'DocTypeStrings.gperf': [ |
| 26 '-CEot', '-L', 'ANSI-C', '-k*', '-N', 'findDoctypeEntry', |
| 27 '-F', ',PubIDInfo::eAlmostStandards,PubIDInfo::eAlmostStandards' |
| 28 ], |
| 29 'HTMLEntityNames.gperf': [ |
| 30 '-a', '-L', 'ANSI-C', '-C', '-G', '-c', '-o', '-t', '-k*', |
| 31 '-N', 'findEntity', '-D', '-s', '2' |
| 32 ], |
| 33 'ColorData.gperf': [ |
| 34 '-CDEot', '-L', 'ANSI-C', '-k*', '-N', 'findColor', '-D', '-s', '2' |
| 35 ], |
| 36 } |
| 37 |
| 38 input_name = posixpath.basename(input_file) |
| 39 assert input_name in gperf_commands |
| 40 |
| 41 (input_root, input_ext) = posixpath.splitext(input_name) |
| 42 output_cpp = posixpath.join(output_dir, input_root + '.cpp') |
| 43 |
| 44 command = ['gperf', '--output-file', output_cpp] |
| 45 command.extend(gperf_commands[input_name]) |
| 46 command.append(input_file) |
| 47 |
| 48 # Do it. check_call is new in 2.5, so simulate its behavior with call and |
| 49 # assert. |
| 50 return_code = subprocess.call(command) |
| 51 assert return_code == 0 |
| 52 |
| 53 output_c = posixpath.join(output_dir, input_root + '.c') |
| 54 shutil.copyfile(output_cpp, output_c) |
OLD | NEW |