plugin.proto 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. //
  32. // WARNING: The plugin interface is currently EXPERIMENTAL and is subject to
  33. // change.
  34. //
  35. // protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is
  36. // just a program that reads a CodeGeneratorRequest from stdin and writes a
  37. // CodeGeneratorResponse to stdout.
  38. //
  39. // Plugins written using C++ can use google/protobuf/compiler/plugin.h instead
  40. // of dealing with the raw protocol defined here.
  41. //
  42. // A plugin executable needs only to be placed somewhere in the path. The
  43. // plugin should be named "protoc-gen-$NAME", and will then be used when the
  44. // flag "--${NAME}_out" is passed to protoc.
  45. syntax = "proto2";
  46. package google.protobuf.compiler;
  47. option java_package = "com.google.protobuf.compiler";
  48. option java_outer_classname = "PluginProtos";
  49. option go_package = "google.golang.org/protobuf/types/pluginpb";
  50. import "google/protobuf/descriptor.proto";
  51. // The version number of protocol compiler.
  52. message Version {
  53. optional int32 major = 1;
  54. optional int32 minor = 2;
  55. optional int32 patch = 3;
  56. // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
  57. // be empty for mainline stable releases.
  58. optional string suffix = 4;
  59. }
  60. // An encoded CodeGeneratorRequest is written to the plugin's stdin.
  61. message CodeGeneratorRequest {
  62. // The .proto files that were explicitly listed on the command-line. The
  63. // code generator should generate code only for these files. Each file's
  64. // descriptor will be included in proto_file, below.
  65. repeated string file_to_generate = 1;
  66. // The generator parameter passed on the command-line.
  67. optional string parameter = 2;
  68. // FileDescriptorProtos for all files in files_to_generate and everything
  69. // they import. The files will appear in topological order, so each file
  70. // appears before any file that imports it.
  71. //
  72. // protoc guarantees that all proto_files will be written after
  73. // the fields above, even though this is not technically guaranteed by the
  74. // protobuf wire format. This theoretically could allow a plugin to stream
  75. // in the FileDescriptorProtos and handle them one by one rather than read
  76. // the entire set into memory at once. However, as of this writing, this
  77. // is not similarly optimized on protoc's end -- it will store all fields in
  78. // memory at once before sending them to the plugin.
  79. //
  80. // Type names of fields and extensions in the FileDescriptorProto are always
  81. // fully qualified.
  82. repeated FileDescriptorProto proto_file = 15;
  83. // The version number of protocol compiler.
  84. optional Version compiler_version = 3;
  85. }
  86. // The plugin writes an encoded CodeGeneratorResponse to stdout.
  87. message CodeGeneratorResponse {
  88. // Error message. If non-empty, code generation failed. The plugin process
  89. // should exit with status code zero even if it reports an error in this way.
  90. //
  91. // This should be used to indicate errors in .proto files which prevent the
  92. // code generator from generating correct code. Errors which indicate a
  93. // problem in protoc itself -- such as the input CodeGeneratorRequest being
  94. // unparseable -- should be reported by writing a message to stderr and
  95. // exiting with a non-zero status code.
  96. optional string error = 1;
  97. // A bitmask of supported features that the code generator supports.
  98. // This is a bitwise "or" of values from the Feature enum.
  99. optional uint64 supported_features = 2;
  100. // Sync with code_generator.h.
  101. enum Feature {
  102. FEATURE_NONE = 0;
  103. FEATURE_PROTO3_OPTIONAL = 1;
  104. }
  105. // Represents a single generated file.
  106. message File {
  107. // The file name, relative to the output directory. The name must not
  108. // contain "." or ".." components and must be relative, not be absolute (so,
  109. // the file cannot lie outside the output directory). "/" must be used as
  110. // the path separator, not "\".
  111. //
  112. // If the name is omitted, the content will be appended to the previous
  113. // file. This allows the generator to break large files into small chunks,
  114. // and allows the generated text to be streamed back to protoc so that large
  115. // files need not reside completely in memory at one time. Note that as of
  116. // this writing protoc does not optimize for this -- it will read the entire
  117. // CodeGeneratorResponse before writing files to disk.
  118. optional string name = 1;
  119. // If non-empty, indicates that the named file should already exist, and the
  120. // content here is to be inserted into that file at a defined insertion
  121. // point. This feature allows a code generator to extend the output
  122. // produced by another code generator. The original generator may provide
  123. // insertion points by placing special annotations in the file that look
  124. // like:
  125. // @@protoc_insertion_point(NAME)
  126. // The annotation can have arbitrary text before and after it on the line,
  127. // which allows it to be placed in a comment. NAME should be replaced with
  128. // an identifier naming the point -- this is what other generators will use
  129. // as the insertion_point. Code inserted at this point will be placed
  130. // immediately above the line containing the insertion point (thus multiple
  131. // insertions to the same point will come out in the order they were added).
  132. // The double-@ is intended to make it unlikely that the generated code
  133. // could contain things that look like insertion points by accident.
  134. //
  135. // For example, the C++ code generator places the following line in the
  136. // .pb.h files that it generates:
  137. // // @@protoc_insertion_point(namespace_scope)
  138. // This line appears within the scope of the file's package namespace, but
  139. // outside of any particular class. Another plugin can then specify the
  140. // insertion_point "namespace_scope" to generate additional classes or
  141. // other declarations that should be placed in this scope.
  142. //
  143. // Note that if the line containing the insertion point begins with
  144. // whitespace, the same whitespace will be added to every line of the
  145. // inserted text. This is useful for languages like Python, where
  146. // indentation matters. In these languages, the insertion point comment
  147. // should be indented the same amount as any inserted code will need to be
  148. // in order to work correctly in that context.
  149. //
  150. // The code generator that generates the initial file and the one which
  151. // inserts into it must both run as part of a single invocation of protoc.
  152. // Code generators are executed in the order in which they appear on the
  153. // command line.
  154. //
  155. // If |insertion_point| is present, |name| must also be present.
  156. optional string insertion_point = 2;
  157. // The file contents.
  158. optional string content = 15;
  159. // Information describing the file content being inserted. If an insertion
  160. // point is used, this information will be appropriately offset and inserted
  161. // into the code generation metadata for the generated files.
  162. optional GeneratedCodeInfo generated_code_info = 16;
  163. }
  164. repeated File file = 15;
  165. }