OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import json | 7 import json |
8 import io | 8 import io |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
11 import sys | 11 import sys |
12 | 12 |
13 jinja2_path = os.path.normpath(os.path.join(os.path.abspath(__file__), | 13 jinja2_path = os.path.normpath(os.path.join(os.path.abspath(__file__), |
14 *[os.path.pardir] * 7 + ['third_party'])) | 14 *[os.path.pardir] * 7 + ['third_party'])) |
15 nom_path = os.path.normpath(os.path.join(os.path.abspath(__file__), | 15 nom_path = os.path.normpath(os.path.join(os.path.abspath(__file__), |
16 *[os.path.pardir] * 7 + ['tools/json_comment_eater'])) | 16 *[os.path.pardir] * 7 + ['tools/json_comment_eater'])) |
| 17 version_py_path = os.path.normpath(os.path.join(os.path.abspath(__file__), |
| 18 *[os.path.pardir] * 7 + ['build/util'])) |
17 sys.path.insert(0, jinja2_path) | 19 sys.path.insert(0, jinja2_path) |
18 sys.path.insert(0, nom_path) | 20 sys.path.insert(0, nom_path) |
| 21 sys.path.insert(0, version_py_path) |
19 import jinja2 | 22 import jinja2 |
20 from json_comment_eater import Nom | 23 from json_comment_eater import Nom |
| 24 import version |
21 | 25 |
22 | 26 |
23 '''Generate an extension manifest based on a template.''' | 27 '''Generate an extension manifest based on a template.''' |
24 | 28 |
| 29 def getChromeVersion(version_file): |
| 30 values = version.fetch_values([version_file]) |
| 31 return version.subst_template('@MAJOR@.@MINOR@.@BUILD@.@PATCH@', values) |
| 32 |
25 | 33 |
26 def processJinjaTemplate(input_file, output_file, context): | 34 def processJinjaTemplate(input_file, output_file, context): |
27 (template_path, template_name) = os.path.split(input_file) | 35 (template_path, template_name) = os.path.split(input_file) |
28 env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path), | 36 env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path), |
29 trim_blocks=True) | 37 trim_blocks=True) |
30 template = env.get_template(template_name) | 38 template = env.get_template(template_name) |
31 rendered = template.render(context) | 39 rendered = template.render(context) |
32 rendered_without_comments = Nom(rendered) | 40 rendered_without_comments = Nom(rendered) |
33 # Simply for validation. | 41 # Simply for validation. |
34 json.loads(rendered_without_comments) | 42 json.loads(rendered_without_comments) |
(...skipping 15 matching lines...) Expand all Loading... |
50 help='Whether to generate a ChromeVox Classic manifest') | 58 help='Whether to generate a ChromeVox Classic manifest') |
51 parser.add_option( | 59 parser.add_option( |
52 '--is_js_compressed', default='1', action='store', metavar='NUM', | 60 '--is_js_compressed', default='1', action='store', metavar='NUM', |
53 help='Whether compressed JavaScript files are used') | 61 help='Whether compressed JavaScript files are used') |
54 parser.add_option( | 62 parser.add_option( |
55 '--set_version', action='store', metavar='SET_VERSION', | 63 '--set_version', action='store', metavar='SET_VERSION', |
56 help='Set the extension version') | 64 help='Set the extension version') |
57 parser.add_option( | 65 parser.add_option( |
58 '--key', action='store', metavar='KEY', | 66 '--key', action='store', metavar='KEY', |
59 help='Set the extension key') | 67 help='Set the extension key') |
| 68 parser.add_option( |
| 69 '--version_file', action='store', metavar='NAME', |
| 70 help='File with version information') |
60 | 71 |
61 options, args = parser.parse_args() | 72 options, args = parser.parse_args() |
62 if len(args) != 1: | 73 if len(args) != 1: |
63 print >>sys.stderr, 'Expected exactly one argument' | 74 print >>sys.stderr, 'Expected exactly one argument' |
64 sys.exit(1) | 75 sys.exit(1) |
65 if options.output_manifest is None: | 76 if options.output_manifest is None: |
66 print >>sys.stderr, '--output_manifest option must be specified' | 77 print >>sys.stderr, '--output_manifest option must be specified' |
67 sys.exit(1) | 78 sys.exit(1) |
68 if options.set_version is None: | 79 if options.set_version is not None and options.version_file is not None: |
69 print >>sys.stderr, '--set_version option must be specified' | 80 print >>sys.stderr, ('only one of --set_version and --version_file may ' + |
| 81 'be specified') |
| 82 if options.set_version is None and options.version_file is None: |
| 83 print >>sys.stderr, ('one of --set_version or --version_file option ' + |
| 84 'must be specified') |
70 sys.exit(1) | 85 sys.exit(1) |
71 | |
72 context = {k: v for k, v in parser.values.__dict__.items() if v is not None} | 86 context = {k: v for k, v in parser.values.__dict__.items() if v is not None} |
| 87 if options.version_file is not None: |
| 88 context['set_version'] = getChromeVersion(options.version_file) |
73 processJinjaTemplate(args[0], options.output_manifest, context) | 89 processJinjaTemplate(args[0], options.output_manifest, context) |
74 | 90 |
75 if __name__ == '__main__': | 91 if __name__ == '__main__': |
76 main() | 92 main() |
OLD | NEW |