blob: acaee1f49456c5554f6b8ce0f7a6ab38b8fda26e [file] [log] [blame]
kenton@google.com5e744ff2009-12-18 04:51:42 +00001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
Feng Xiaoe4288622014-10-01 16:26:23 -07003// https://developers.google.com/protocol-buffers/
kenton@google.com5e744ff2009-12-18 04:51:42 +00004//
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
31// Author: kenton@google.com (Kenton Varda)
32//
kenton@google.com7f4938b2009-12-22 22:57:39 +000033// WARNING: The plugin interface is currently EXPERIMENTAL and is subject to
34// change.
35//
kenton@google.com5e744ff2009-12-18 04:51:42 +000036// protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is
37// just a program that reads a CodeGeneratorRequest from stdin and writes a
38// CodeGeneratorResponse to stdout.
39//
40// Plugins written using C++ can use google/protobuf/compiler/plugin.h instead
41// of dealing with the raw protocol defined here.
42//
43// A plugin executable needs only to be placed somewhere in the path. The
44// plugin should be named "protoc-gen-$NAME", and will then be used when the
45// flag "--${NAME}_out" is passed to protoc.
46
Feng Xiao6ef984a2014-11-10 17:34:54 -080047syntax = "proto2";
kenton@google.com5e744ff2009-12-18 04:51:42 +000048package google.protobuf.compiler;
liujisi@google.com2273ee42012-12-05 23:47:43 +000049option java_package = "com.google.protobuf.compiler";
50option java_outer_classname = "PluginProtos";
kenton@google.com5e744ff2009-12-18 04:51:42 +000051
Jisi Liu885b6122015-02-28 14:51:22 -080052option go_package = "plugin_go";
53
kenton@google.com5e744ff2009-12-18 04:51:42 +000054import "google/protobuf/descriptor.proto";
55
56// An encoded CodeGeneratorRequest is written to the plugin's stdin.
57message CodeGeneratorRequest {
58 // The .proto files that were explicitly listed on the command-line. The
59 // code generator should generate code only for these files. Each file's
60 // descriptor will be included in proto_file, below.
61 repeated string file_to_generate = 1;
62
63 // The generator parameter passed on the command-line.
64 optional string parameter = 2;
65
66 // FileDescriptorProtos for all files in files_to_generate and everything
67 // they import. The files will appear in topological order, so each file
68 // appears before any file that imports it.
69 //
70 // protoc guarantees that all proto_files will be written after
71 // the fields above, even though this is not technically guaranteed by the
72 // protobuf wire format. This theoretically could allow a plugin to stream
73 // in the FileDescriptorProtos and handle them one by one rather than read
74 // the entire set into memory at once. However, as of this writing, this
75 // is not similarly optimized on protoc's end -- it will store all fields in
76 // memory at once before sending them to the plugin.
77 repeated FileDescriptorProto proto_file = 15;
78}
79
80// The plugin writes an encoded CodeGeneratorResponse to stdout.
81message CodeGeneratorResponse {
82 // Error message. If non-empty, code generation failed. The plugin process
83 // should exit with status code zero even if it reports an error in this way.
84 //
85 // This should be used to indicate errors in .proto files which prevent the
86 // code generator from generating correct code. Errors which indicate a
87 // problem in protoc itself -- such as the input CodeGeneratorRequest being
88 // unparseable -- should be reported by writing a message to stderr and
89 // exiting with a non-zero status code.
90 optional string error = 1;
91
92 // Represents a single generated file.
93 message File {
94 // The file name, relative to the output directory. The name must not
95 // contain "." or ".." components and must be relative, not be absolute (so,
96 // the file cannot lie outside the output directory). "/" must be used as
97 // the path separator, not "\".
98 //
99 // If the name is omitted, the content will be appended to the previous
100 // file. This allows the generator to break large files into small chunks,
101 // and allows the generated text to be streamed back to protoc so that large
102 // files need not reside completely in memory at one time. Note that as of
103 // this writing protoc does not optimize for this -- it will read the entire
104 // CodeGeneratorResponse before writing files to disk.
105 optional string name = 1;
106
107 // If non-empty, indicates that the named file should already exist, and the
108 // content here is to be inserted into that file at a defined insertion
109 // point. This feature allows a code generator to extend the output
110 // produced by another code generator. The original generator may provide
111 // insertion points by placing special annotations in the file that look
112 // like:
113 // @@protoc_insertion_point(NAME)
114 // The annotation can have arbitrary text before and after it on the line,
115 // which allows it to be placed in a comment. NAME should be replaced with
116 // an identifier naming the point -- this is what other generators will use
117 // as the insertion_point. Code inserted at this point will be placed
118 // immediately above the line containing the insertion point (thus multiple
119 // insertions to the same point will come out in the order they were added).
120 // The double-@ is intended to make it unlikely that the generated code
121 // could contain things that look like insertion points by accident.
122 //
123 // For example, the C++ code generator places the following line in the
124 // .pb.h files that it generates:
kenton@google.com7b7a80e2010-01-08 03:56:03 +0000125 // // @@protoc_insertion_point(namespace_scope)
kenton@google.com5e744ff2009-12-18 04:51:42 +0000126 // This line appears within the scope of the file's package namespace, but
127 // outside of any particular class. Another plugin can then specify the
kenton@google.com7b7a80e2010-01-08 03:56:03 +0000128 // insertion_point "namespace_scope" to generate additional classes or
kenton@google.com5e744ff2009-12-18 04:51:42 +0000129 // other declarations that should be placed in this scope.
130 //
kenton@google.com5f121642009-12-23 07:03:06 +0000131 // Note that if the line containing the insertion point begins with
132 // whitespace, the same whitespace will be added to every line of the
133 // inserted text. This is useful for languages like Python, where
134 // indentation matters. In these languages, the insertion point comment
135 // should be indented the same amount as any inserted code will need to be
136 // in order to work correctly in that context.
137 //
kenton@google.com7b7a80e2010-01-08 03:56:03 +0000138 // The code generator that generates the initial file and the one which
liujisi@google.com33165fe2010-11-02 13:14:58 +0000139 // inserts into it must both run as part of a single invocation of protoc.
kenton@google.com7b7a80e2010-01-08 03:56:03 +0000140 // Code generators are executed in the order in which they appear on the
141 // command line.
142 //
kenton@google.com5e744ff2009-12-18 04:51:42 +0000143 // If |insertion_point| is present, |name| must also be present.
144 optional string insertion_point = 2;
145
146 // The file contents.
147 optional string content = 15;
148 }
149 repeated File file = 15;
150}