| 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 argparse | 10 import argparse |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 contents, filename, uptodate = jinja2.FileSystemLoader.get_source( | 30 contents, filename, uptodate = jinja2.FileSystemLoader.get_source( |
| 31 self, environment, template) | 31 self, environment, template) |
| 32 self.loaded_templates.add(os.path.relpath(filename)) | 32 self.loaded_templates.add(os.path.relpath(filename)) |
| 33 return contents, filename, uptodate | 33 return contents, filename, uptodate |
| 34 | 34 |
| 35 | 35 |
| 36 class JinjaProcessor(object): | 36 class JinjaProcessor(object): |
| 37 """Allows easy rendering of jinja templates with input file tracking.""" | 37 """Allows easy rendering of jinja templates with input file tracking.""" |
| 38 def __init__(self, loader_base_dir, variables=None): | 38 def __init__(self, loader_base_dir, variables=None): |
| 39 self.loader_base_dir = loader_base_dir | 39 self.loader_base_dir = loader_base_dir |
| 40 self.variables = variables | 40 self.variables = variables or {} |
| 41 self.loader = _RecordingFileSystemLoader(loader_base_dir) | 41 self.loader = _RecordingFileSystemLoader(loader_base_dir) |
| 42 self.env = jinja2.Environment(loader=self.loader) | 42 self.env = jinja2.Environment(loader=self.loader) |
| 43 self.env.undefined = jinja2.StrictUndefined | 43 self.env.undefined = jinja2.StrictUndefined |
| 44 self.env.line_comment_prefix = '##' | 44 self.env.line_comment_prefix = '##' |
| 45 self.env.trim_blocks = True | 45 self.env.trim_blocks = True |
| 46 self.env.lstrip_blocks = True | 46 self.env.lstrip_blocks = True |
| 47 self._template_cache = {} # Map of path -> Template | 47 self._template_cache = {} # Map of path -> Template |
| 48 | 48 |
| 49 def Render(self, input_filename, variables=None): | 49 def Render(self, input_filename, variables=None): |
| 50 input_rel_path = os.path.relpath(input_filename, self.loader_base_dir) | 50 input_rel_path = os.path.relpath(input_filename, self.loader_base_dir) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 options.outputs_zip) | 132 options.outputs_zip) |
| 133 | 133 |
| 134 if options.depfile: | 134 if options.depfile: |
| 135 output = options.output or options.outputs_zip | 135 output = options.output or options.outputs_zip |
| 136 deps = processor.GetLoadedTemplates() | 136 deps = processor.GetLoadedTemplates() |
| 137 build_utils.WriteDepfile(options.depfile, output, deps) | 137 build_utils.WriteDepfile(options.depfile, output, deps) |
| 138 | 138 |
| 139 | 139 |
| 140 if __name__ == '__main__': | 140 if __name__ == '__main__': |
| 141 main() | 141 main() |
| OLD | NEW |