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 """Renders one or more template files using the Jinja template engine.""" | 7 """Renders one or more template files using the Jinja template engine.""" |
8 | 8 |
9 import codecs | 9 import codecs |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 | 13 |
| 14 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) |
| 15 from pylib import constants |
14 from util import build_utils | 16 from util import build_utils |
15 | 17 |
16 # Import jinja2 from third_party/jinja2 | 18 # Import jinja2 from third_party/jinja2 |
17 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../third_party')) | 19 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'third_party')) |
18 import jinja2 # pylint: disable=F0401 | 20 import jinja2 # pylint: disable=F0401 |
19 | 21 |
20 | 22 |
21 class RecordingFileSystemLoader(jinja2.FileSystemLoader): | 23 class RecordingFileSystemLoader(jinja2.FileSystemLoader): |
22 '''A FileSystemLoader that stores a list of loaded templates.''' | 24 '''A FileSystemLoader that stores a list of loaded templates.''' |
23 def __init__(self, searchpath): | 25 def __init__(self, searchpath): |
24 jinja2.FileSystemLoader.__init__(self, searchpath) | 26 jinja2.FileSystemLoader.__init__(self, searchpath) |
25 self.loaded_templates = set() | 27 self.loaded_templates = set() |
26 | 28 |
27 def get_source(self, environment, template): | 29 def get_source(self, environment, template): |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 parser.add_option('--output', help='The output file to generate. Valid ' | 71 parser.add_option('--output', help='The output file to generate. Valid ' |
70 'only if there is a single input.') | 72 'only if there is a single input.') |
71 parser.add_option('--outputs-zip', help='A zip file containing the processed ' | 73 parser.add_option('--outputs-zip', help='A zip file containing the processed ' |
72 'templates. Required if there are multiple inputs.') | 74 'templates. Required if there are multiple inputs.') |
73 parser.add_option('--inputs-base-dir', help='A common ancestor directory of ' | 75 parser.add_option('--inputs-base-dir', help='A common ancestor directory of ' |
74 'the inputs. Each output\'s path in the output zip will ' | 76 'the inputs. Each output\'s path in the output zip will ' |
75 'match the relative path from INPUTS_BASE_DIR to the ' | 77 'match the relative path from INPUTS_BASE_DIR to the ' |
76 'input. Required if --output-zip is given.') | 78 'input. Required if --output-zip is given.') |
77 parser.add_option('--loader-base-dir', help='Base path used by the template ' | 79 parser.add_option('--loader-base-dir', help='Base path used by the template ' |
78 'loader. Must be a common ancestor directory of ' | 80 'loader. Must be a common ancestor directory of ' |
79 'the inputs. Defaults to CHROMIUM_SRC.', | 81 'the inputs. Defaults to DIR_SOURCE_ROOT.', |
80 default=build_utils.CHROMIUM_SRC) | 82 default=constants.DIR_SOURCE_ROOT) |
81 parser.add_option('--variables', help='Variables to be made available in the ' | 83 parser.add_option('--variables', help='Variables to be made available in the ' |
82 'template processing environment, as a GYP list (e.g. ' | 84 'template processing environment, as a GYP list (e.g. ' |
83 '--variables "channel=beta mstone=39")', default='') | 85 '--variables "channel=beta mstone=39")', default='') |
84 options, args = parser.parse_args() | 86 options, args = parser.parse_args() |
85 | 87 |
86 build_utils.CheckOptions(options, parser, required=['inputs']) | 88 build_utils.CheckOptions(options, parser, required=['inputs']) |
87 inputs = build_utils.ParseGypList(options.inputs) | 89 inputs = build_utils.ParseGypList(options.inputs) |
88 | 90 |
89 if (options.output is None) == (options.outputs_zip is None): | 91 if (options.output is None) == (options.outputs_zip is None): |
90 parser.error('Exactly one of --output and --output-zip must be given') | 92 parser.error('Exactly one of --output and --output-zip must be given') |
(...skipping 21 matching lines...) Expand all Loading... |
112 ProcessFiles(env, inputs, options.loader_base_dir, options.inputs_base_dir, | 114 ProcessFiles(env, inputs, options.loader_base_dir, options.inputs_base_dir, |
113 options.outputs_zip, variables) | 115 options.outputs_zip, variables) |
114 | 116 |
115 if options.depfile: | 117 if options.depfile: |
116 deps = loader.get_loaded_templates() + build_utils.GetPythonDependencies() | 118 deps = loader.get_loaded_templates() + build_utils.GetPythonDependencies() |
117 build_utils.WriteDepfile(options.depfile, deps) | 119 build_utils.WriteDepfile(options.depfile, deps) |
118 | 120 |
119 | 121 |
120 if __name__ == '__main__': | 122 if __name__ == '__main__': |
121 main() | 123 main() |
OLD | NEW |