OLD | NEW |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 | 67 |
68 def MakeImportStackMessage(imported_filename_stack): | 68 def MakeImportStackMessage(imported_filename_stack): |
69 """Make a (human-readable) message listing a chain of imports. (Returned | 69 """Make a (human-readable) message listing a chain of imports. (Returned |
70 string begins with a newline (if nonempty) and does not end with one.)""" | 70 string begins with a newline (if nonempty) and does not end with one.)""" |
71 return ''.join( | 71 return ''.join( |
72 reversed(["\n %s was imported by %s" % (a, b) for (a, b) in \ | 72 reversed(["\n %s was imported by %s" % (a, b) for (a, b) in \ |
73 zip(imported_filename_stack[1:], imported_filename_stack)])) | 73 zip(imported_filename_stack[1:], imported_filename_stack)])) |
74 | 74 |
75 | 75 |
76 # Disable Check for dangerous default arguments (they're "private" keyword | 76 # Disable check for dangerous default arguments (they're "private" keyword |
77 # arguments): | 77 # arguments; note that we want |_processed_files| to memoize across invocations |
| 78 # of |ProcessFile()|): |
78 # pylint: disable=W0102 | 79 # pylint: disable=W0102 |
79 def ProcessFile(args, remaining_args, generator_modules, filename, | 80 def ProcessFile(args, remaining_args, generator_modules, filename, |
80 _processed_files={}, _imported_filename_stack=[]): | 81 _processed_files={}, _imported_filename_stack=None): |
81 # Memoized results. | 82 # Memoized results. |
82 if filename in _processed_files: | 83 if filename in _processed_files: |
83 return _processed_files[filename] | 84 return _processed_files[filename] |
84 | 85 |
| 86 if _imported_filename_stack is None: |
| 87 _imported_filename_stack = [] |
| 88 |
85 # Ensure we only visit each file once. | 89 # Ensure we only visit each file once. |
86 if filename in _imported_filename_stack: | 90 if filename in _imported_filename_stack: |
87 print "%s: Error: Circular dependency" % filename + \ | 91 print "%s: Error: Circular dependency" % filename + \ |
88 MakeImportStackMessage(_imported_filename_stack + [filename]) | 92 MakeImportStackMessage(_imported_filename_stack + [filename]) |
89 sys.exit(1) | 93 sys.exit(1) |
90 | 94 |
91 try: | 95 try: |
92 with open(filename) as f: | 96 with open(filename) as f: |
93 source = f.read() | 97 source = f.read() |
94 except IOError as e: | 98 except IOError as e: |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 os.makedirs(args.output_dir) | 167 os.makedirs(args.output_dir) |
164 | 168 |
165 for filename in args.filename: | 169 for filename in args.filename: |
166 ProcessFile(args, remaining_args, generator_modules, filename) | 170 ProcessFile(args, remaining_args, generator_modules, filename) |
167 | 171 |
168 return 0 | 172 return 0 |
169 | 173 |
170 | 174 |
171 if __name__ == "__main__": | 175 if __name__ == "__main__": |
172 sys.exit(main()) | 176 sys.exit(main()) |
OLD | NEW |