114 parser = argparse.ArgumentParser()
115 parser.add_argument("--protoc",
116 help="Relative path to compiler.")
117
118 parser.add_argument("--proto-in-dir",
119 help="Base directory with source protos.")
120 parser.add_argument("--cc-out-dir",
121 help="Output directory for standard C++ generator.")
122 parser.add_argument("--py-out-dir",
123 help="Output directory for standard Python generator.")
124 parser.add_argument("--plugin-out-dir",
125 help="Output directory for custom generator plugin.")
126
127 parser.add_argument("--depfile",
128 help="Output location for the protoc depfile.")
129 parser.add_argument("--depfile-outputs",
130 help="File containing a list of files to be generated.")
131
132 parser.add_argument("--plugin",
133 help="Relative path to custom generator plugin.")
134 parser.add_argument("--plugin-depfile",
135 help="Output location for the plugin depfile.")
136 parser.add_argument("--plugin-depfile-deps",
137 help="File containing plugin deps not set as other input.")
138 parser.add_argument("--plugin-depfile-outputs",
139 help="File containing a list of files that will be generated.")
140 parser.add_argument("--plugin-options",
141 help="Custom generator plugin options.")
142 parser.add_argument("--cc-options",
143 help="Standard C++ generator options.")
144 parser.add_argument("--include",
145 help="Name of include to insert into generated headers.")
146 parser.add_argument("--import-dir", action="append", default=[],
147 help="Extra import directory for protos, can be repeated."
148 )
149 parser.add_argument("--descriptor-set-out",
150 help="Passed through to protoc as --descriptor_set_out")
151
152 parser.add_argument("protos", nargs="+",
153 help="Input protobuf definition file(s).")
154
155 options = parser.parse_args()
156
157 proto_dir = os.path.relpath(options.proto_in_dir)
158 protoc_cmd = [os.path.realpath(options.protoc)]
159
160 protos = options.protos
161 headers = []
163
164 if options.descriptor_set_out:
165 protoc_cmd += ["--descriptor_set_out", options.descriptor_set_out]
166
167 if options.py_out_dir:
168 protoc_cmd += ["--python_out", options.py_out_dir]
169
170 if options.cc_out_dir:
171 cc_out_dir = options.cc_out_dir
173 protoc_cmd += ["--cpp_out", cc_options + cc_out_dir]
174 for filename in protos:
176 headers.append(os.path.join(cc_out_dir, stripped_name + ".pb.h"))
177
178 if options.plugin_out_dir:
180 protoc_cmd += [
181 "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin),
182 "--plugin_out", plugin_options + options.plugin_out_dir
183 ]
184
185 if options.plugin_depfile:
186 if not options.plugin_depfile_deps or not options.plugin_depfile_outputs:
187 raise RuntimeError("If plugin depfile is supplied, then the plugin "
188 "depfile deps and outputs must be set.")
189 depfile = options.plugin_depfile
190 dep_info = options.plugin_depfile_deps
191 outputs = options.plugin_depfile_outputs
193
194 if options.depfile:
195 if not options.depfile_outputs:
196 raise RuntimeError("If depfile is supplied, depfile outputs must also"
197 "be supplied.")
198
199 depfile = options.depfile
200 outputs = options.depfile_outputs
202
203 for proto in protos:
206
207 protoc_cmd += ["--proto_path", proto_dir]
208 for path in options.import_dir:
209 protoc_cmd += ["--proto_path", path]
210
211 protoc_cmd += [os.path.join(proto_dir, name) for name in protos]
212
213 ret = subprocess.call(protoc_cmd)
214 if ret != 0:
215 raise RuntimeError("Protoc has returned non-zero status: "
217
218 if options.include:
220
221
uint32_t uint32_t * format
def StripProtoExtension(filename)
def WriteProtocDepfile(depfile, outputs, deps_list)
def VerifyProtoNames(protos)
def WritePluginDepfile(depfile, outputs, dependencies)
def WriteIncludes(headers, include)