plugin.proto 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file or at
  6. // https://developers.google.com/open-source/licenses/bsd
  7. // Author: kenton@google.com (Kenton Varda)
  8. //
  9. // protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is
  10. // just a program that reads a CodeGeneratorRequest from stdin and writes a
  11. // CodeGeneratorResponse to stdout.
  12. //
  13. // Plugins written using C++ can use google/protobuf/compiler/plugin.h instead
  14. // of dealing with the raw protocol defined here.
  15. //
  16. // A plugin executable needs only to be placed somewhere in the path. The
  17. // plugin should be named "protoc-gen-$NAME", and will then be used when the
  18. // flag "--${NAME}_out" is passed to protoc.
  19. syntax = "proto2";
  20. package google.protobuf.compiler;
  21. option java_package = "com.google.protobuf.compiler";
  22. option java_outer_classname = "PluginProtos";
  23. option csharp_namespace = "Google.Protobuf.Compiler";
  24. option go_package = "google.golang.org/protobuf/types/pluginpb";
  25. import "google/protobuf/descriptor.proto";
  26. // The version number of protocol compiler.
  27. message Version {
  28. optional int32 major = 1;
  29. optional int32 minor = 2;
  30. optional int32 patch = 3;
  31. // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
  32. // be empty for mainline stable releases.
  33. optional string suffix = 4;
  34. }
  35. // An encoded CodeGeneratorRequest is written to the plugin's stdin.
  36. message CodeGeneratorRequest {
  37. // The .proto files that were explicitly listed on the command-line. The
  38. // code generator should generate code only for these files. Each file's
  39. // descriptor will be included in proto_file, below.
  40. repeated string file_to_generate = 1;
  41. // The generator parameter passed on the command-line.
  42. optional string parameter = 2;
  43. // FileDescriptorProtos for all files in files_to_generate and everything
  44. // they import. The files will appear in topological order, so each file
  45. // appears before any file that imports it.
  46. //
  47. // Note: the files listed in files_to_generate will include runtime-retention
  48. // options only, but all other files will include source-retention options.
  49. // The source_file_descriptors field below is available in case you need
  50. // source-retention options for files_to_generate.
  51. //
  52. // protoc guarantees that all proto_files will be written after
  53. // the fields above, even though this is not technically guaranteed by the
  54. // protobuf wire format. This theoretically could allow a plugin to stream
  55. // in the FileDescriptorProtos and handle them one by one rather than read
  56. // the entire set into memory at once. However, as of this writing, this
  57. // is not similarly optimized on protoc's end -- it will store all fields in
  58. // memory at once before sending them to the plugin.
  59. //
  60. // Type names of fields and extensions in the FileDescriptorProto are always
  61. // fully qualified.
  62. repeated FileDescriptorProto proto_file = 15;
  63. // File descriptors with all options, including source-retention options.
  64. // These descriptors are only provided for the files listed in
  65. // files_to_generate.
  66. repeated FileDescriptorProto source_file_descriptors = 17;
  67. // The version number of protocol compiler.
  68. optional Version compiler_version = 3;
  69. }
  70. // The plugin writes an encoded CodeGeneratorResponse to stdout.
  71. message CodeGeneratorResponse {
  72. // Error message. If non-empty, code generation failed. The plugin process
  73. // should exit with status code zero even if it reports an error in this way.
  74. //
  75. // This should be used to indicate errors in .proto files which prevent the
  76. // code generator from generating correct code. Errors which indicate a
  77. // problem in protoc itself -- such as the input CodeGeneratorRequest being
  78. // unparseable -- should be reported by writing a message to stderr and
  79. // exiting with a non-zero status code.
  80. optional string error = 1;
  81. // A bitmask of supported features that the code generator supports.
  82. // This is a bitwise "or" of values from the Feature enum.
  83. optional uint64 supported_features = 2;
  84. // Sync with code_generator.h.
  85. enum Feature {
  86. FEATURE_NONE = 0;
  87. FEATURE_PROTO3_OPTIONAL = 1;
  88. FEATURE_SUPPORTS_EDITIONS = 2;
  89. }
  90. // The minimum edition this plugin supports. This will be treated as an
  91. // Edition enum, but we want to allow unknown values. It should be specified
  92. // according the edition enum value, *not* the edition number. Only takes
  93. // effect for plugins that have FEATURE_SUPPORTS_EDITIONS set.
  94. optional int32 minimum_edition = 3;
  95. // The maximum edition this plugin supports. This will be treated as an
  96. // Edition enum, but we want to allow unknown values. It should be specified
  97. // according the edition enum value, *not* the edition number. Only takes
  98. // effect for plugins that have FEATURE_SUPPORTS_EDITIONS set.
  99. optional int32 maximum_edition = 4;
  100. // Represents a single generated file.
  101. message File {
  102. // The file name, relative to the output directory. The name must not
  103. // contain "." or ".." components and must be relative, not be absolute (so,
  104. // the file cannot lie outside the output directory). "/" must be used as
  105. // the path separator, not "\".
  106. //
  107. // If the name is omitted, the content will be appended to the previous
  108. // file. This allows the generator to break large files into small chunks,
  109. // and allows the generated text to be streamed back to protoc so that large
  110. // files need not reside completely in memory at one time. Note that as of
  111. // this writing protoc does not optimize for this -- it will read the entire
  112. // CodeGeneratorResponse before writing files to disk.
  113. optional string name = 1;
  114. // If non-empty, indicates that the named file should already exist, and the
  115. // content here is to be inserted into that file at a defined insertion
  116. // point. This feature allows a code generator to extend the output
  117. // produced by another code generator. The original generator may provide
  118. // insertion points by placing special annotations in the file that look
  119. // like:
  120. // @@protoc_insertion_point(NAME)
  121. // The annotation can have arbitrary text before and after it on the line,
  122. // which allows it to be placed in a comment. NAME should be replaced with
  123. // an identifier naming the point -- this is what other generators will use
  124. // as the insertion_point. Code inserted at this point will be placed
  125. // immediately above the line containing the insertion point (thus multiple
  126. // insertions to the same point will come out in the order they were added).
  127. // The double-@ is intended to make it unlikely that the generated code
  128. // could contain things that look like insertion points by accident.
  129. //
  130. // For example, the C++ code generator places the following line in the
  131. // .pb.h files that it generates:
  132. // // @@protoc_insertion_point(namespace_scope)
  133. // This line appears within the scope of the file's package namespace, but
  134. // outside of any particular class. Another plugin can then specify the
  135. // insertion_point "namespace_scope" to generate additional classes or
  136. // other declarations that should be placed in this scope.
  137. //
  138. // Note that if the line containing the insertion point begins with
  139. // whitespace, the same whitespace will be added to every line of the
  140. // inserted text. This is useful for languages like Python, where
  141. // indentation matters. In these languages, the insertion point comment
  142. // should be indented the same amount as any inserted code will need to be
  143. // in order to work correctly in that context.
  144. //
  145. // The code generator that generates the initial file and the one which
  146. // inserts into it must both run as part of a single invocation of protoc.
  147. // Code generators are executed in the order in which they appear on the
  148. // command line.
  149. //
  150. // If |insertion_point| is present, |name| must also be present.
  151. optional string insertion_point = 2;
  152. // The file contents.
  153. optional string content = 15;
  154. // Information describing the file content being inserted. If an insertion
  155. // point is used, this information will be appropriately offset and inserted
  156. // into the code generation metadata for the generated files.
  157. optional GeneratedCodeInfo generated_code_info = 16;
  158. }
  159. repeated File file = 15;
  160. }