| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 if not include_point_found: | 61 if not include_point_found: |
| 62 raise RuntimeError("Include point not found in header: " | 62 raise RuntimeError("Include point not found in header: " |
| 63 "{0} .".format(filename)) | 63 "{0} .".format(filename)) |
| 64 | 64 |
| 65 with open(filename, "w") as f: | 65 with open(filename, "w") as f: |
| 66 for line in contents: | 66 for line in contents: |
| 67 print(line, file=f) | 67 print(line, file=f) |
| 68 | 68 |
| 69 | 69 |
| 70 def WritePythonInit(base_dir, protos): |
| 71 def write_init_py(path): |
| 72 if not path: |
| 73 return |
| 74 open(os.path.join(base_dir, path, '__init__.py'), 'a').close() |
| 75 write_init_py(os.path.dirname(path)) |
| 76 |
| 77 for proto in protos: |
| 78 write_init_py(os.path.dirname(proto)) |
| 79 |
| 80 |
| 70 def main(argv): | 81 def main(argv): |
| 71 parser = argparse.ArgumentParser() | 82 parser = argparse.ArgumentParser() |
| 72 parser.add_argument("--protoc", | 83 parser.add_argument("--protoc", |
| 73 help="Relative path to compiler.") | 84 help="Relative path to compiler.") |
| 74 | 85 |
| 75 parser.add_argument("--proto-in-dir", | 86 parser.add_argument("--proto-in-dir", |
| 76 help="Base directory with source protos.") | 87 help="Base directory with source protos.") |
| 77 parser.add_argument("--cc-out-dir", | 88 parser.add_argument("--cc-out-dir", |
| 78 help="Output directory for standard C++ generator.") | 89 help="Output directory for standard C++ generator.") |
| 79 parser.add_argument("--py-out-dir", | 90 parser.add_argument("--py-out-dir", |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] | 140 protoc_cmd += [os.path.join(proto_dir, name) for name in protos] |
| 130 | 141 |
| 131 ret = subprocess.call(protoc_cmd) | 142 ret = subprocess.call(protoc_cmd) |
| 132 if ret != 0: | 143 if ret != 0: |
| 133 raise RuntimeError("Protoc has returned non-zero status: " | 144 raise RuntimeError("Protoc has returned non-zero status: " |
| 134 "{0} .".format(ret)) | 145 "{0} .".format(ret)) |
| 135 | 146 |
| 136 if options.include: | 147 if options.include: |
| 137 WriteIncludes(headers, options.include) | 148 WriteIncludes(headers, options.include) |
| 138 | 149 |
| 150 if options.py_out_dir: |
| 151 WritePythonInit(options.py_out_dir, protos) |
| 152 |
| 139 | 153 |
| 140 if __name__ == "__main__": | 154 if __name__ == "__main__": |
| 141 try: | 155 try: |
| 142 main(sys.argv) | 156 main(sys.argv) |
| 143 except RuntimeError as e: | 157 except RuntimeError as e: |
| 144 print(e, file=sys.stderr) | 158 print(e, file=sys.stderr) |
| 145 sys.exit(1) | 159 sys.exit(1) |
| OLD | NEW |