OLD | NEW |
1 #!/usr/bin/python | |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 3 # found in the LICENSE file. |
5 | 4 |
6 import argparse | 5 """Holds the constants for pretty printing histograms.xml.""" |
7 import subprocess | 6 |
| 7 import os |
8 import sys | 8 import sys |
9 import os | |
10 | 9 |
11 DESCRIPTION = '''Run the given JavaScript files through jscompile.''' | 10 # Import the metrics/common module for pretty print xml. |
12 FILES_HELP = '''A list of Javascript files. The Javascript files should include | 11 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
13 files that contain definitions of types or functions that are known to Chrome | 12 import pretty_print_xml |
14 but not to jscompile.''' | |
15 STAMP_HELP = 'Timestamp file to update on success.' | |
16 | 13 |
17 def checkJavascript(js_files): | 14 # Desired order for tag attributes; attributes listed here will appear first, |
18 args = ['jscompile'] + js_files | 15 # and in the same order as in these lists. |
19 result = subprocess.call(args) | 16 # { tag_name: [attribute_name, ...] } |
20 return result == 0 | 17 ATTRIBUTE_ORDER = { |
| 18 'enum': ['name', 'type'], |
| 19 'histogram': ['name', 'enum', 'units'], |
| 20 'int': ['value', 'label'], |
| 21 'fieldtrial': ['name', 'separator', 'ordering'], |
| 22 'group': ['name', 'label'], |
| 23 'affected-histogram': ['name'], |
| 24 'with-group': ['name'], |
| 25 } |
| 26 |
| 27 # Tag names for top-level nodes whose children we don't want to indent. |
| 28 TAGS_THAT_DONT_INDENT = [ |
| 29 'histogram-configuration', |
| 30 'histograms', |
| 31 'fieldtrials', |
| 32 'enums' |
| 33 ] |
| 34 |
| 35 # Extra vertical spacing rules for special tag names. |
| 36 # {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)} |
| 37 TAGS_THAT_HAVE_EXTRA_NEWLINE = { |
| 38 'histogram-configuration': (2, 1, 1), |
| 39 'histograms': (2, 1, 1), |
| 40 'fieldtrials': (2, 1, 1), |
| 41 'enums': (2, 1, 1), |
| 42 'histogram': (1, 1, 1), |
| 43 'enum': (1, 1, 1), |
| 44 'fieldtrial': (1, 1, 1), |
| 45 } |
| 46 |
| 47 # Tags that we allow to be squished into a single line for brevity. |
| 48 TAGS_THAT_ALLOW_SINGLE_LINE = [ |
| 49 'summary', |
| 50 'int', |
| 51 ] |
21 | 52 |
22 | 53 |
23 def main(): | |
24 parser = argparse.ArgumentParser(description = DESCRIPTION) | |
25 parser.add_argument('files', nargs = '+', help = FILES_HELP) | |
26 parser.add_argument('--success-stamp', dest = 'success_stamp', | |
27 help = STAMP_HELP) | |
28 options = parser.parse_args() | |
29 | |
30 js = [] | |
31 for file in options.files: | |
32 name, extension = os.path.splitext(file) | |
33 if extension == '.js': | |
34 js.append(file) | |
35 else: | |
36 print >> sys.stderr, 'Unknown extension (' + extension + ') for ' + file | |
37 return 1 | |
38 | |
39 if not checkJavascript(js): | |
40 return 1 | |
41 | |
42 if options.success_stamp: | |
43 with open(options.success_stamp, 'w'): | |
44 os.utime(options.success_stamp, None) | |
45 | |
46 return 0 | |
47 | |
48 if __name__ == '__main__': | |
49 sys.exit(main()) | |
OLD | NEW |