| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 """This script drives the mojom bindings generation.""" | 6 """This script drives the mojom bindings generation.""" |
| 7 | 7 |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import os | 10 import os |
| 11 import platform | |
| 12 import subprocess | 11 import subprocess |
| 13 import sys | 12 import sys |
| 14 | 13 |
| 14 import mojom.parse.parser_runner |
| 15 |
| 15 # We assume this script is located in the Mojo SDK in tools/bindings. | 16 # We assume this script is located in the Mojo SDK in tools/bindings. |
| 16 BINDINGS_DIR = os.path.abspath(os.path.dirname(__file__)) | 17 BINDINGS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 17 | 18 |
| 18 def RunParser(args): | 19 def RunParser(args): |
| 19 """Runs the mojom parser. | 20 """Runs the mojom parser. |
| 20 | 21 |
| 21 Args: | 22 Args: |
| 22 args: {Namespace} The parsed arguments passed to the script. | 23 args: {Namespace} The parsed arguments passed to the script. |
| 23 | 24 |
| 24 Returns: | 25 Returns: |
| 25 {str} The serialized mojom_files.MojomFileGraph returned by mojom parser, | 26 {str} The serialized mojom_files.MojomFileGraph returned by mojom parser, |
| 26 or None if the mojom parser returned a non-zero error code. | 27 or None if the mojom parser returned a non-zero error code. |
| 27 """ | 28 """ |
| 28 system_dirs = { | 29 sdk_root = os.path.abspath( |
| 29 ("Linux", "64bit"): "linux64", | 30 os.path.join(BINDINGS_DIR, os.path.pardir, os.path.pardir)) |
| 30 ("Darwin", "64bit"): "mac64", | |
| 31 } | |
| 32 system = (platform.system(), platform.architecture()[0]) | |
| 33 if system not in system_dirs: | |
| 34 raise Exception("The mojom parser only supports Linux or Mac 64 bits.") | |
| 35 | 31 |
| 36 mojom_parser = os.path.join(BINDINGS_DIR, | 32 return mojom.parse.parser_runner.RunParser(sdk_root, args.filename, |
| 37 "mojom_parser", "bin", system_dirs[system], "mojom_parser") | 33 args.import_directories) |
| 38 | |
| 39 if args.mojom_parser: | |
| 40 mojom_parser = args.mojom_parser | |
| 41 if not os.path.exists(mojom_parser): | |
| 42 raise Exception( | |
| 43 "The mojom parser could not be found at %s. " | |
| 44 "You may need to run gclient sync." | |
| 45 % mojom_parser) | |
| 46 | |
| 47 cmd = [mojom_parser] | |
| 48 if args.import_directories: | |
| 49 cmd.extend(["-I", ",".join(args.import_directories)]) | |
| 50 | |
| 51 cmd.extend(args.filename) | |
| 52 | |
| 53 try: | |
| 54 return subprocess.check_output(cmd) | |
| 55 except subprocess.CalledProcessError: | |
| 56 return None | |
| 57 | 34 |
| 58 def RunGenerators(serialized_file_graph, args, remaining_args): | 35 def RunGenerators(serialized_file_graph, args, remaining_args): |
| 59 """Runs the code generators. | 36 """Runs the code generators. |
| 60 | 37 |
| 61 As a side-effect, this function will create the generated bindings | 38 As a side-effect, this function will create the generated bindings |
| 62 corresponding to the serialized_file_graph passed in. | 39 corresponding to the serialized_file_graph passed in. |
| 63 | 40 |
| 64 Args: | 41 Args: |
| 65 serialized_file_graph: {str} A serialized mojom_files.MojomFileGraph. | 42 serialized_file_graph: {str} A serialized mojom_files.MojomFileGraph. |
| 66 args: {Namespace} The parsed arguments passed to the script. | 43 args: {Namespace} The parsed arguments passed to the script. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 103 |
| 127 serialized_file_graph = RunParser(args) | 104 serialized_file_graph = RunParser(args) |
| 128 | 105 |
| 129 if serialized_file_graph: | 106 if serialized_file_graph: |
| 130 return RunGenerators(serialized_file_graph, args, remaining_args) | 107 return RunGenerators(serialized_file_graph, args, remaining_args) |
| 131 return 1 | 108 return 1 |
| 132 | 109 |
| 133 | 110 |
| 134 if __name__ == "__main__": | 111 if __name__ == "__main__": |
| 135 sys.exit(main(sys.argv[1:])) | 112 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |