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

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

Issue 2646123002: Option added to protobuf build for import directories (Closed)
Patch Set: Created 3 years, 11 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
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", nargs='*',
93 help="Name of include to insert into generated headers.")
xyzzyz 2017/01/20 18:27:40 Please update the help text.
Ramin Halavati 2017/01/23 14:27:06 Done.
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
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 if options.import_dir:
128 protoc_cmd += ["--proto_path"]
129 protoc_cmd += options.import_dir
xyzzyz 2017/01/20 18:27:40 Isn't options.import_dir a list? You should probab
Ramin Halavati 2017/01/23 14:27:06 Yes, it had to be changed into looping through the
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
« third_party/protobuf/proto_library.gni ('K') | « third_party/protobuf/proto_library.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698