Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/template_expander.py

Issue 306893010: Generate java bindings for structs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-upload after revert Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/generate/generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # 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
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # Based on: 5 # Based on:
6 # http://src.chromium.org/viewvc/blink/trunk/Source/build/scripts/template_expan der.py 6 # http://src.chromium.org/viewvc/blink/trunk/Source/build/scripts/template_expan der.py
7 7
8 import imp 8 import imp
9 import inspect 9 import inspect
10 import os.path 10 import os.path
(...skipping 12 matching lines...) Expand all
23 if tail == dirname: 23 if tail == dirname:
24 return path 24 return path
25 25
26 try: 26 try:
27 imp.find_module("jinja2") 27 imp.find_module("jinja2")
28 except ImportError: 28 except ImportError:
29 sys.path.append(os.path.join(_GetDirAbove("mojo"), "third_party")) 29 sys.path.append(os.path.join(_GetDirAbove("mojo"), "third_party"))
30 import jinja2 30 import jinja2
31 31
32 32
33 def ApplyTemplate(base_dir, path_to_template, params, filters=None, **kwargs): 33 def ApplyTemplate(mojo_generator, base_dir, path_to_template, params,
34 filters=None, **kwargs):
34 template_directory, template_name = os.path.split(path_to_template) 35 template_directory, template_name = os.path.split(path_to_template)
35 path_to_templates = os.path.join(base_dir, template_directory) 36 path_to_templates = os.path.join(base_dir, template_directory)
36 loader = jinja2.FileSystemLoader([path_to_templates]) 37 loader = jinja2.FileSystemLoader([path_to_templates])
38 final_kwargs = dict(mojo_generator.GetJinjaParameters())
39 final_kwargs.update(kwargs)
37 jinja_env = jinja2.Environment(loader=loader, keep_trailing_newline=True, 40 jinja_env = jinja2.Environment(loader=loader, keep_trailing_newline=True,
38 **kwargs) 41 **final_kwargs)
42 jinja_env.globals.update(mojo_generator.GetGlobals());
39 if filters: 43 if filters:
40 jinja_env.filters.update(filters) 44 jinja_env.filters.update(filters)
41 template = jinja_env.get_template(template_name) 45 template = jinja_env.get_template(template_name)
42 return template.render(params) 46 return template.render(params)
43 47
44 48
45 def UseJinja(path_to_template, **kwargs): 49 def UseJinja(path_to_template, **kwargs):
46 # Get the directory of our caller's file. 50 # Get the directory of our caller's file.
47 base_dir = os.path.dirname(inspect.getfile(sys._getframe(1))) 51 base_dir = os.path.dirname(inspect.getfile(sys._getframe(1)))
48 def RealDecorator(generator): 52 def RealDecorator(generator):
49 def GeneratorInternal(*args, **kwargs2): 53 def GeneratorInternal(*args, **kwargs2):
50 parameters = generator(*args, **kwargs2) 54 parameters = generator(*args, **kwargs2)
51 return ApplyTemplate(base_dir, path_to_template, parameters, **kwargs) 55 return ApplyTemplate(args[0], base_dir, path_to_template, parameters,
56 **kwargs)
52 GeneratorInternal.func_name = generator.func_name 57 GeneratorInternal.func_name = generator.func_name
53 return GeneratorInternal 58 return GeneratorInternal
54 return RealDecorator 59 return RealDecorator
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/generate/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698