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