Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
607b9214
Commit
607b9214
authored
Dec 06, 2016
by
Feng Xiao
Committed by
GitHub
Dec 06, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2437 from xfxyjwf/plugin
Add version number to plugin protocol.
parents
05090726
ced8f73f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
73 additions
and
2 deletions
+73
-2
code_generator.cc
src/google/protobuf/compiler/code_generator.cc
+8
-0
code_generator.h
src/google/protobuf/compiler/code_generator.h
+5
-0
command_line_interface.cc
src/google/protobuf/compiler/command_line_interface.cc
+7
-0
command_line_interface_unittest.cc
...ogle/protobuf/compiler/command_line_interface_unittest.cc
+16
-0
mock_code_generator.cc
src/google/protobuf/compiler/mock_code_generator.cc
+10
-0
plugin.cc
src/google/protobuf/compiler/plugin.cc
+11
-2
plugin.pb.cc
src/google/protobuf/compiler/plugin.pb.cc
+0
-0
plugin.pb.h
src/google/protobuf/compiler/plugin.pb.h
+0
-0
plugin.proto
src/google/protobuf/compiler/plugin.proto
+13
-0
common.h
src/google/protobuf/stubs/common.h
+3
-0
No files found.
src/google/protobuf/compiler/code_generator.cc
View file @
607b9214
...
...
@@ -34,6 +34,7 @@
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/descriptor.h>
...
...
@@ -89,6 +90,13 @@ void GeneratorContext::ListParsedFiles(
GOOGLE_LOG
(
FATAL
)
<<
"This GeneratorContext does not support ListParsedFiles"
;
}
void
GeneratorContext
::
GetCompilerVersion
(
Version
*
version
)
const
{
version
->
set_major
(
GOOGLE_PROTOBUF_VERSION
/
1000000
);
version
->
set_minor
(
GOOGLE_PROTOBUF_VERSION
/
1000
%
1000
);
version
->
set_patch
(
GOOGLE_PROTOBUF_VERSION
%
1000
);
version
->
set_suffix
(
GOOGLE_PROTOBUF_VERSION_SUFFIX
);
}
// Parses a set of comma-delimited name/value pairs.
void
ParseGeneratorParameter
(
const
string
&
text
,
std
::
vector
<
std
::
pair
<
string
,
string
>
>*
output
)
{
...
...
src/google/protobuf/compiler/code_generator.h
View file @
607b9214
...
...
@@ -50,6 +50,7 @@ namespace io { class ZeroCopyOutputStream; }
class
FileDescriptor
;
namespace
compiler
{
class
Version
;
// Defined in this file.
class
CodeGenerator
;
...
...
@@ -143,6 +144,10 @@ class LIBPROTOC_EXPORT GeneratorContext {
// differently when compiled as a set rather than individually.
virtual
void
ListParsedFiles
(
std
::
vector
<
const
FileDescriptor
*>*
output
);
// Retrieves the version number of the protocol compiler associated with
// this GeneratorContext.
virtual
void
GetCompilerVersion
(
Version
*
version
)
const
;
private
:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
GeneratorContext
);
};
...
...
src/google/protobuf/compiler/command_line_interface.cc
View file @
607b9214
...
...
@@ -1619,6 +1619,13 @@ bool CommandLineInterface::GeneratePluginOutput(
&
already_seen
,
request
.
mutable_proto_file
());
}
google
::
protobuf
::
compiler
::
Version
*
version
=
request
.
mutable_compiler_version
();
version
->
set_major
(
GOOGLE_PROTOBUF_VERSION
/
1000000
);
version
->
set_minor
(
GOOGLE_PROTOBUF_VERSION
/
1000
%
1000
);
version
->
set_patch
(
GOOGLE_PROTOBUF_VERSION
%
1000
);
version
->
set_suffix
(
GOOGLE_PROTOBUF_VERSION_SUFFIX
);
// Invoke the plugin.
Subprocess
subprocess
;
...
...
src/google/protobuf/compiler/command_line_interface_unittest.cc
View file @
607b9214
...
...
@@ -57,6 +57,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
...
...
@@ -1582,6 +1583,21 @@ TEST_F(CommandLineInterfaceTest, PluginReceivesJsonName) {
ExpectErrorSubstring
(
"Saw json_name: 1"
);
}
TEST_F
(
CommandLineInterfaceTest
,
PluginReceivesCompilerVersion
)
{
CreateTempFile
(
"foo.proto"
,
"syntax =
\"
proto2
\"
;
\n
"
"message MockCodeGenerator_ShowVersionNumber {
\n
"
" optional int32 value = 1;
\n
"
"}
\n
"
);
Run
(
"protocol_compiler --plug_out=$tmpdir --proto_path=$tmpdir foo.proto"
);
ExpectErrorSubstring
(
StringPrintf
(
"Saw compiler_version: %d %s"
,
GOOGLE_PROTOBUF_VERSION
,
GOOGLE_PROTOBUF_VERSION_SUFFIX
));
}
TEST_F
(
CommandLineInterfaceTest
,
GeneratorPluginNotFound
)
{
// Test what happens if the plugin isn't found.
...
...
src/google/protobuf/compiler/mock_code_generator.cc
View file @
607b9214
...
...
@@ -40,6 +40,7 @@
#endif
#include <vector>
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/testing/file.h>
...
...
@@ -160,6 +161,15 @@ bool MockCodeGenerator::Generate(
std
::
cerr
<<
"Saw json_name: "
<<
field_descriptor_proto
.
has_json_name
()
<<
std
::
endl
;
abort
();
}
else
if
(
command
==
"ShowVersionNumber"
)
{
Version
compiler_version
;
context
->
GetCompilerVersion
(
&
compiler_version
);
std
::
cerr
<<
"Saw compiler_version: "
<<
compiler_version
.
major
()
*
1000000
+
compiler_version
.
minor
()
*
1000
+
compiler_version
.
patch
()
<<
" "
<<
compiler_version
.
suffix
()
<<
std
::
endl
;
abort
();
}
else
{
GOOGLE_LOG
(
FATAL
)
<<
"Unknown MockCodeGenerator command: "
<<
command
;
}
...
...
src/google/protobuf/compiler/plugin.cc
View file @
607b9214
...
...
@@ -63,9 +63,12 @@ namespace compiler {
class
GeneratorResponseContext
:
public
GeneratorContext
{
public
:
GeneratorResponseContext
(
const
Version
&
compiler_version
,
CodeGeneratorResponse
*
response
,
const
std
::
vector
<
const
FileDescriptor
*>&
parsed_files
)
:
response_
(
response
),
parsed_files_
(
parsed_files
)
{}
:
compiler_version_
(
compiler_version
),
response_
(
response
),
parsed_files_
(
parsed_files
)
{}
virtual
~
GeneratorResponseContext
()
{}
// implements GeneratorContext --------------------------------------
...
...
@@ -88,7 +91,12 @@ class GeneratorResponseContext : public GeneratorContext {
*
output
=
parsed_files_
;
}
void
GetCompilerVersion
(
Version
*
version
)
const
{
*
version
=
compiler_version_
;
}
private
:
Version
compiler_version_
;
CodeGeneratorResponse
*
response_
;
const
std
::
vector
<
const
FileDescriptor
*>&
parsed_files_
;
};
...
...
@@ -116,7 +124,8 @@ bool GenerateCode(const CodeGeneratorRequest& request,
}
}
GeneratorResponseContext
context
(
response
,
parsed_files
);
GeneratorResponseContext
context
(
request
.
compiler_version
(),
response
,
parsed_files
);
string
error
;
bool
succeeded
=
generator
.
GenerateAll
(
...
...
src/google/protobuf/compiler/plugin.pb.cc
View file @
607b9214
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/plugin.pb.h
View file @
607b9214
This diff is collapsed.
Click to expand it.
src/google/protobuf/compiler/plugin.proto
View file @
607b9214
...
...
@@ -53,6 +53,16 @@ option go_package = "plugin_go";
import
"google/protobuf/descriptor.proto"
;
// The version number of protocol compiler.
message
Version
{
optional
int32
major
=
1
;
optional
int32
minor
=
2
;
optional
int32
patch
=
3
;
// A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
// be empty for mainline stable releases.
optional
string
suffix
=
4
;
}
// An encoded CodeGeneratorRequest is written to the plugin's stdin.
message
CodeGeneratorRequest
{
// The .proto files that were explicitly listed on the command-line. The
...
...
@@ -75,6 +85,9 @@ message CodeGeneratorRequest {
// is not similarly optimized on protoc's end -- it will store all fields in
// memory at once before sending them to the plugin.
repeated
FileDescriptorProto
proto_file
=
15
;
// The version number of protocol compiler.
optional
Version
compiler_version
=
3
;
}
// The plugin writes an encoded CodeGeneratorResponse to stdout.
...
...
src/google/protobuf/stubs/common.h
View file @
607b9214
...
...
@@ -98,6 +98,9 @@ namespace internal {
// easier: major * 10^6 + minor * 10^3 + micro
#define GOOGLE_PROTOBUF_VERSION 3001000
// A suffix string for alpha, beta or rc releases. Empty for stable releases.
#define GOOGLE_PROTOBUF_VERSION_SUFFIX ""
// The minimum library version which works with the current version of the
// headers.
#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3001000
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment