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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 print(line, file=f) | 67 print(line, file=f) |
68 | 68 |
69 | 69 |
70 def main(argv): | 70 def main(argv): |
71 parser = argparse.ArgumentParser() | 71 parser = argparse.ArgumentParser() |
72 parser.add_argument("--protoc", | 72 parser.add_argument("--protoc", |
73 help="Relative path to compiler.") | 73 help="Relative path to compiler.") |
74 | 74 |
75 parser.add_argument("--proto-in-dir", | 75 parser.add_argument("--proto-in-dir", |
76 help="Base directory with source protos.") | 76 help="Base directory with source protos.") |
77 parser.add_argument("--proto-path", | |
sdefresne
2016/10/04 11:29:55
I would make this an argument that can be passed m
Olivier
2016/10/04 12:44:31
Done.
| |
78 help="Base directory with imported protos.") | |
77 parser.add_argument("--cc-out-dir", | 79 parser.add_argument("--cc-out-dir", |
78 help="Output directory for standard C++ generator.") | 80 help="Output directory for standard C++ generator.") |
79 parser.add_argument("--py-out-dir", | 81 parser.add_argument("--py-out-dir", |
80 help="Output directory for standard Python generator.") | 82 help="Output directory for standard Python generator.") |
81 parser.add_argument("--plugin-out-dir", | 83 parser.add_argument("--plugin-out-dir", |
82 help="Output directory for custom generator plugin.") | 84 help="Output directory for custom generator plugin.") |
83 | 85 |
84 parser.add_argument("--plugin", | 86 parser.add_argument("--plugin", |
85 help="Relative path to custom generator plugin.") | 87 help="Relative path to custom generator plugin.") |
86 parser.add_argument("--plugin-options", | 88 parser.add_argument("--plugin-options", |
(...skipping 27 matching lines...) Expand all Loading... | |
114 headers.append(os.path.join(cc_out_dir, stripped_name + ".pb.h")) | 116 headers.append(os.path.join(cc_out_dir, stripped_name + ".pb.h")) |
115 | 117 |
116 if options.plugin_out_dir: | 118 if options.plugin_out_dir: |
117 plugin_options = FormatGeneratorOptions(options.plugin_options) | 119 plugin_options = FormatGeneratorOptions(options.plugin_options) |
118 protoc_cmd += [ | 120 protoc_cmd += [ |
119 "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin), | 121 "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin), |
120 "--plugin_out", plugin_options + options.plugin_out_dir | 122 "--plugin_out", plugin_options + options.plugin_out_dir |
121 ] | 123 ] |
122 | 124 |
123 protoc_cmd += ["--proto_path", proto_dir] | 125 protoc_cmd += ["--proto_path", proto_dir] |
126 if options.proto_path: | |
sdefresne
2016/10/04 11:29:55
If you change the argument to one that accept mult
Olivier
2016/10/04 12:44:31
Done.
Kept the + [] instead of extend for file con
| |
127 protoc_cmd += ["--proto_path", os.path.relpath(options.proto_path)] | |
128 | |
124 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] | 129 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] |
125 ret = subprocess.call(protoc_cmd) | 130 ret = subprocess.call(protoc_cmd) |
126 if ret != 0: | 131 if ret != 0: |
127 raise RuntimeError("Protoc has returned non-zero status: " | 132 raise RuntimeError("Protoc has returned non-zero status: " |
128 "{0} .".format(ret)) | 133 "{0} .".format(ret)) |
129 | 134 |
130 if options.include: | 135 if options.include: |
131 WriteIncludes(headers, options.include) | 136 WriteIncludes(headers, options.include) |
132 | 137 |
133 | 138 |
134 if __name__ == "__main__": | 139 if __name__ == "__main__": |
135 try: | 140 try: |
136 main(sys.argv) | 141 main(sys.argv) |
137 except RuntimeError as e: | 142 except RuntimeError as e: |
138 print(e, file=sys.stderr) | 143 print(e, file=sys.stderr) |
139 sys.exit(1) | 144 sys.exit(1) |
OLD | NEW |