Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/protoc_wrapper/protoc_wrapper.py

Issue 2646123002: Option added to protobuf build for import directories (Closed)
Patch Set: Warning added. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/protobuf/proto_library.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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", action="append", default=[],
93 help="Extra import directory for protos, can be repeated."
94 )
93 parser.add_argument("protos", nargs="+", 95 parser.add_argument("protos", nargs="+",
94 help="Input protobuf definition file(s).") 96 help="Input protobuf definition file(s).")
95 97
96 options = parser.parse_args() 98 options = parser.parse_args()
97 99
98 proto_dir = os.path.relpath(options.proto_in_dir) 100 proto_dir = os.path.relpath(options.proto_in_dir)
99 protoc_cmd = [os.path.realpath(options.protoc)] 101 protoc_cmd = [os.path.realpath(options.protoc)]
100 102
101 protos = options.protos 103 protos = options.protos
102 headers = [] 104 headers = []
(...skipping 11 matching lines...) Expand all
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 for path in options.import_dir:
127 protoc_cmd += ["--proto_path", 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]
130
125 ret = subprocess.call(protoc_cmd) 131 ret = subprocess.call(protoc_cmd)
126 if ret != 0: 132 if ret != 0:
127 raise RuntimeError("Protoc has returned non-zero status: " 133 raise RuntimeError("Protoc has returned non-zero status: "
128 "{0} .".format(ret)) 134 "{0} .".format(ret))
129 135
130 if options.include: 136 if options.include:
131 WriteIncludes(headers, options.include) 137 WriteIncludes(headers, options.include)
132 138
133 139
134 if __name__ == "__main__": 140 if __name__ == "__main__":
135 try: 141 try:
136 main(sys.argv) 142 main(sys.argv)
137 except RuntimeError as e: 143 except RuntimeError as e:
138 print(e, file=sys.stderr) 144 print(e, file=sys.stderr)
139 sys.exit(1) 145 sys.exit(1)
OLDNEW
« no previous file with comments | « third_party/protobuf/proto_library.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698