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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 help="Output directory for custom generator plugin.") | 82 help="Output directory for custom generator plugin.") |
83 | 83 |
84 parser.add_argument("--plugin", | 84 parser.add_argument("--plugin", |
85 help="Relative path to custom generator plugin.") | 85 help="Relative path to custom generator plugin.") |
86 parser.add_argument("--plugin-options", | 86 parser.add_argument("--plugin-options", |
87 help="Custom generator plugin options.") | 87 help="Custom generator plugin options.") |
88 parser.add_argument("--cc-options", | 88 parser.add_argument("--cc-options", |
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 parser.add_argument("--import-dir", nargs='*', default=[], |
scottmg
2017/01/23 16:53:11
I have no idea why this script uses " everywhere,
Ramin Halavati
2017/01/24 08:38:33
Done.
| |
93 help="Name of extra import directories for protos.") | |
scottmg
2017/01/23 16:53:11
nit; "Extra import directories for protos." would
xyzzyz
2017/01/23 17:53:56
Just like my comment in the other file, please ren
Ramin Halavati
2017/01/24 08:38:33
Done. Help corrected, name did not change as it no
| |
93 parser.add_argument("protos", nargs="+", | 94 parser.add_argument("protos", nargs="+", |
94 help="Input protobuf definition file(s).") | 95 help="Input protobuf definition file(s).") |
95 | 96 |
96 options = parser.parse_args() | 97 options = parser.parse_args() |
97 | 98 |
98 proto_dir = os.path.relpath(options.proto_in_dir) | 99 proto_dir = os.path.relpath(options.proto_in_dir) |
99 protoc_cmd = [os.path.realpath(options.protoc)] | 100 protoc_cmd = [os.path.realpath(options.protoc)] |
100 | 101 |
101 protos = options.protos | 102 protos = options.protos |
102 headers = [] | 103 headers = [] |
(...skipping 12 matching lines...) Expand all Loading... | |
115 | 116 |
116 if options.plugin_out_dir: | 117 if options.plugin_out_dir: |
117 plugin_options = FormatGeneratorOptions(options.plugin_options) | 118 plugin_options = FormatGeneratorOptions(options.plugin_options) |
118 protoc_cmd += [ | 119 protoc_cmd += [ |
119 "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin), | 120 "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin), |
120 "--plugin_out", plugin_options + options.plugin_out_dir | 121 "--plugin_out", plugin_options + options.plugin_out_dir |
121 ] | 122 ] |
122 | 123 |
123 protoc_cmd += ["--proto_path", proto_dir] | 124 protoc_cmd += ["--proto_path", proto_dir] |
124 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] | 125 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] |
126 | |
127 for path in options.import_dir: | |
xyzzyz
2017/01/23 17:53:56
This loop should probably be between lines 124 and
Ramin Halavati
2017/01/24 08:38:33
Done.
| |
128 protoc_cmd += ["--proto_path", path] | |
129 | |
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 |