| 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 |
| 11 import os | 11 import os |
| 12 import pprint | 12 import pprint |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 # Disable lint check for finding modules: | 15 # Disable lint check for finding modules: |
| 16 # pylint: disable=F0401 | 16 # pylint: disable=F0401 |
| 17 | 17 |
| 18 def _GetDirAbove(dirname): | 18 def _GetDirAbove(dirname): |
| 19 """Returns the directory "above" this file containing |dirname| (which must | 19 """Returns the directory "above" this file containing |dirname| (which must |
| 20 also be "above" this file).""" | 20 also be "above" this file).""" |
| 21 path = os.path.abspath(__file__) | 21 path = os.path.abspath(__file__) |
| 22 while True: | 22 while True: |
| 23 path, tail = os.path.split(path) | 23 path, tail = os.path.split(path) |
| 24 assert tail | 24 assert tail |
| 25 if tail == dirname: | 25 if tail == dirname: |
| 26 return path | 26 return path |
| 27 | 27 |
| 28 # Manually check for the command-line flag. (This isn't quite right, since it | 28 # Manually check for the command-line flag. (This isn't quite right, since it |
| 29 # ignores, e.g., "--", but it's close enough.) | 29 # ignores, e.g., "--", but it's close enough.) |
| 30 if "--use_chromium_bundled_pylibs" in sys.argv[1:]: | 30 if "--use_bundled_pylibs" in sys.argv[1:]: |
| 31 sys.path.insert(0, os.path.join(_GetDirAbove("mojo"), "third_party")) | 31 sys.path.insert(0, os.path.join(_GetDirAbove("public"), "public/third_party")) |
| 32 | 32 |
| 33 sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), | 33 sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), |
| 34 "pylib")) | 34 "pylib")) |
| 35 | 35 |
| 36 from mojom.error import Error | 36 from mojom.error import Error |
| 37 from mojom.generate.data import OrderedModuleFromData | 37 from mojom.generate.data import OrderedModuleFromData |
| 38 from mojom.parse.parser import Parse | 38 from mojom.parse.parser import Parse |
| 39 from mojom.parse.translate import Translate | 39 from mojom.parse.translate import Translate |
| 40 | 40 |
| 41 | 41 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 help="output directory for generated files") | 191 help="output directory for generated files") |
| 192 parser.add_argument("-g", "--generators", dest="generators_string", | 192 parser.add_argument("-g", "--generators", dest="generators_string", |
| 193 metavar="GENERATORS", | 193 metavar="GENERATORS", |
| 194 default="c++,dart,javascript,java,python", | 194 default="c++,dart,javascript,java,python", |
| 195 help="comma-separated list of generators") | 195 help="comma-separated list of generators") |
| 196 parser.add_argument("--debug_print_intermediate", action="store_true", | 196 parser.add_argument("--debug_print_intermediate", action="store_true", |
| 197 help="print the intermediate representation") | 197 help="print the intermediate representation") |
| 198 parser.add_argument("-I", dest="import_directories", action="append", | 198 parser.add_argument("-I", dest="import_directories", action="append", |
| 199 metavar="directory", default=[], | 199 metavar="directory", default=[], |
| 200 help="add a directory to be searched for import files") | 200 help="add a directory to be searched for import files") |
| 201 parser.add_argument("--use_chromium_bundled_pylibs", action="store_true", | 201 parser.add_argument("--use_bundled_pylibs", action="store_true", |
| 202 help="use Python modules bundled in the Chromium source") | 202 help="use Python modules bundled in the SDK") |
| 203 (args, remaining_args) = parser.parse_known_args() | 203 (args, remaining_args) = parser.parse_known_args() |
| 204 | 204 |
| 205 generator_modules = LoadGenerators(args.generators_string) | 205 generator_modules = LoadGenerators(args.generators_string) |
| 206 | 206 |
| 207 if not os.path.exists(args.output_dir): | 207 if not os.path.exists(args.output_dir): |
| 208 os.makedirs(args.output_dir) | 208 os.makedirs(args.output_dir) |
| 209 | 209 |
| 210 processor = MojomProcessor(lambda filename: filename in args.filename) | 210 processor = MojomProcessor(lambda filename: filename in args.filename) |
| 211 for filename in args.filename: | 211 for filename in args.filename: |
| 212 processor.ProcessFile(args, remaining_args, generator_modules, filename) | 212 processor.ProcessFile(args, remaining_args, generator_modules, filename) |
| 213 | 213 |
| 214 return 0 | 214 return 0 |
| 215 | 215 |
| 216 | 216 |
| 217 if __name__ == "__main__": | 217 if __name__ == "__main__": |
| 218 sys.exit(main()) | 218 sys.exit(main()) |
| OLD | NEW |