OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """ | 6 """ |
7 A simple wrapper for protoc. | 7 A simple wrapper for protoc. |
8 Script for //third_party/protobuf/proto_library.gni . | 8 Script for //third_party/protobuf/proto_library.gni . |
9 Features: | 9 Features: |
10 - Inserts #include for extra header automatically. | 10 - Inserts #include for extra header automatically. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 help="Standard C++ generator options.") | 89 help="Standard C++ generator options.") |
90 parser.add_argument("--include", | 90 parser.add_argument("--include", |
91 help="Name of include to insert into generated headers.") | 91 help="Name of include to insert into generated headers.") |
92 | 92 |
93 parser.add_argument("protos", nargs="+", | 93 parser.add_argument("protos", nargs="+", |
94 help="Input protobuf definition file(s).") | 94 help="Input protobuf definition file(s).") |
95 | 95 |
96 options = parser.parse_args() | 96 options = parser.parse_args() |
97 | 97 |
98 proto_dir = os.path.relpath(options.proto_in_dir) | 98 proto_dir = os.path.relpath(options.proto_in_dir) |
99 protoc_cmd = [ | 99 protoc_cmd = [os.path.realpath(options.protoc)] |
100 os.path.realpath(options.protoc), | |
101 "--proto_path", proto_dir | |
102 ] | |
103 | 100 |
104 protos = options.protos | 101 protos = options.protos |
105 headers = [] | 102 headers = [] |
106 VerifyProtoNames(protos) | 103 VerifyProtoNames(protos) |
107 | 104 |
| 105 if options.py_out_dir: |
| 106 protoc_cmd += ["--python_out", options.py_out_dir] |
| 107 |
108 if options.cc_out_dir: | 108 if options.cc_out_dir: |
109 cc_out_dir = options.cc_out_dir | 109 cc_out_dir = options.cc_out_dir |
110 cc_options = FormatGeneratorOptions(options.cc_options) | 110 cc_options = FormatGeneratorOptions(options.cc_options) |
111 protoc_cmd += ["--cpp_out", cc_options + cc_out_dir] | 111 protoc_cmd += ["--cpp_out", cc_options + cc_out_dir] |
112 for filename in protos: | 112 for filename in protos: |
113 stripped_name = StripProtoExtension(filename) | 113 stripped_name = StripProtoExtension(filename) |
114 headers.append(os.path.join(cc_out_dir, stripped_name + ".pb.h")) | 114 headers.append(os.path.join(cc_out_dir, stripped_name + ".pb.h")) |
115 | 115 |
116 if options.py_out_dir: | |
117 protoc_cmd += ["--python_out", options.py_out_dir] | |
118 | |
119 if options.plugin_out_dir: | 116 if options.plugin_out_dir: |
120 plugin_options = FormatGeneratorOptions(options.plugin_options) | 117 plugin_options = FormatGeneratorOptions(options.plugin_options) |
121 protoc_cmd += [ | 118 protoc_cmd += [ |
122 "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin), | 119 "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin), |
123 "--plugin_out", plugin_options + options.plugin_out_dir | 120 "--plugin_out", plugin_options + options.plugin_out_dir |
124 ] | 121 ] |
125 | 122 |
| 123 protoc_cmd += ["--proto_path", proto_dir] |
126 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] | 124 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] |
127 ret = subprocess.call(protoc_cmd) | 125 ret = subprocess.call(protoc_cmd) |
128 if ret != 0: | 126 if ret != 0: |
129 raise RuntimeError("Protoc has returned non-zero status: " | 127 raise RuntimeError("Protoc has returned non-zero status: " |
130 "{0} .".format(ret)) | 128 "{0} .".format(ret)) |
131 | 129 |
132 if options.include: | 130 if options.include: |
133 WriteIncludes(headers, options.include) | 131 WriteIncludes(headers, options.include) |
134 | 132 |
135 | 133 |
136 if __name__ == "__main__": | 134 if __name__ == "__main__": |
137 try: | 135 try: |
138 main(sys.argv) | 136 main(sys.argv) |
139 except RuntimeError as e: | 137 except RuntimeError as e: |
140 print(e, file=sys.stderr) | 138 print(e, file=sys.stderr) |
141 sys.exit(1) | 139 sys.exit(1) |
OLD | NEW |