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

Side by Side Diff: mojo/public/tools/bindings/mojom_bindings_generator.py

Issue 443293003: Mojo: Add PRESUBMIT.py to mojo/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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/PRESUBMIT.py ('k') | mojo/public/tools/bindings/pylib/mojom/generate/data.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """The frontend for the Mojo bindings system.""" 6 """The frontend for the Mojo bindings system."""
7 7
8 8
9 import argparse 9 import argparse
10 import imp 10 import imp
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 70
71 def MakeImportStackMessage(imported_filename_stack): 71 def MakeImportStackMessage(imported_filename_stack):
72 """Make a (human-readable) message listing a chain of imports. (Returned 72 """Make a (human-readable) message listing a chain of imports. (Returned
73 string begins with a newline (if nonempty) and does not end with one.)""" 73 string begins with a newline (if nonempty) and does not end with one.)"""
74 return ''.join( 74 return ''.join(
75 reversed(["\n %s was imported by %s" % (a, b) for (a, b) in \ 75 reversed(["\n %s was imported by %s" % (a, b) for (a, b) in \
76 zip(imported_filename_stack[1:], imported_filename_stack)])) 76 zip(imported_filename_stack[1:], imported_filename_stack)]))
77 77
78 78
79 def FindImportFile(dir, file, search_dirs): 79 def FindImportFile(dir_name, file_name, search_dirs):
80 for search_dir in [dir] + search_dirs: 80 for search_dir in [dir_name] + search_dirs:
81 path = os.path.join(search_dir, file) 81 path = os.path.join(search_dir, file_name)
82 if os.path.isfile(path): 82 if os.path.isfile(path):
83 return path 83 return path
84 return os.path.join(dir, file); 84 return os.path.join(dir_name, file_name)
85 85
86 86
87 # Disable check for dangerous default arguments (they're "private" keyword 87 # Disable check for dangerous default arguments (they're "private" keyword
88 # arguments; note that we want |_processed_files| to memoize across invocations 88 # arguments; note that we want |_processed_files| to memoize across invocations
89 # of |ProcessFile()|): 89 # of |ProcessFile()|):
90 # pylint: disable=W0102 90 # pylint: disable=W0102
91 def ProcessFile(args, remaining_args, generator_modules, filename, 91 def ProcessFile(args, remaining_args, generator_modules, filename,
92 _processed_files={}, _imported_filename_stack=None): 92 _processed_files={}, _imported_filename_stack=None):
93 # Memoized results. 93 # Memoized results.
94 if filename in _processed_files: 94 if filename in _processed_files:
(...skipping 25 matching lines...) Expand all
120 dirname, name = os.path.split(filename) 120 dirname, name = os.path.split(filename)
121 mojom = Translate(tree, name) 121 mojom = Translate(tree, name)
122 if args.debug_print_intermediate: 122 if args.debug_print_intermediate:
123 pprint.PrettyPrinter().pprint(mojom) 123 pprint.PrettyPrinter().pprint(mojom)
124 124
125 # Process all our imports first and collect the module object for each. 125 # Process all our imports first and collect the module object for each.
126 # We use these to generate proper type info. 126 # We use these to generate proper type info.
127 for import_data in mojom['imports']: 127 for import_data in mojom['imports']:
128 import_filename = FindImportFile(dirname, 128 import_filename = FindImportFile(dirname,
129 import_data['filename'], 129 import_data['filename'],
130 args.import_directories); 130 args.import_directories)
131 import_data['module'] = ProcessFile( 131 import_data['module'] = ProcessFile(
132 args, remaining_args, generator_modules, import_filename, 132 args, remaining_args, generator_modules, import_filename,
133 _processed_files=_processed_files, 133 _processed_files=_processed_files,
134 _imported_filename_stack=_imported_filename_stack + [filename]) 134 _imported_filename_stack=_imported_filename_stack + [filename])
135 135
136 module = OrderedModuleFromData(mojom) 136 module = OrderedModuleFromData(mojom)
137 137
138 # Set the path as relative to the source root. 138 # Set the path as relative to the source root.
139 module.path = os.path.relpath(os.path.abspath(filename), 139 module.path = os.path.relpath(os.path.abspath(filename),
140 os.path.abspath(args.depth)) 140 os.path.abspath(args.depth))
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 os.makedirs(args.output_dir) 183 os.makedirs(args.output_dir)
184 184
185 for filename in args.filename: 185 for filename in args.filename:
186 ProcessFile(args, remaining_args, generator_modules, filename) 186 ProcessFile(args, remaining_args, generator_modules, filename)
187 187
188 return 0 188 return 0
189 189
190 190
191 if __name__ == "__main__": 191 if __name__ == "__main__":
192 sys.exit(main()) 192 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/PRESUBMIT.py ('k') | mojo/public/tools/bindings/pylib/mojom/generate/data.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698