aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/cpp/cpp_generator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_generator.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_generator.cc74
1 files changed, 51 insertions, 23 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc
index 20bb8a1a..0e7e4dfd 100644
--- a/src/google/protobuf/compiler/cpp/cpp_generator.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc
@@ -77,6 +77,21 @@ bool CppGenerator::Generate(const FileDescriptor* file,
// __declspec(dllimport) depending on what is being compiled.
//
Options file_options;
+
+ switch (runtime_) {
+ case Runtime::kGoogle3:
+ file_options.opensource_runtime = false;
+ break;
+ case Runtime::kOpensource:
+ file_options.opensource_runtime = true;
+ file_options.opensource_include_paths = true;
+ break;
+ case Runtime::kOpensourceGoogle3:
+ file_options.opensource_runtime = true;
+ file_options.opensource_include_paths = false;
+ break;
+ }
+
for (int i = 0; i < options.size(); i++) {
if (options[i].first == "dllexport_decl") {
file_options.dllexport_decl = options[i].second;
@@ -108,7 +123,7 @@ bool CppGenerator::Generate(const FileDescriptor* file,
// The safe_boundary_check option controls behavior for Google-internal
// protobuf APIs.
- if (file_options.safe_boundary_check) {
+ if (file_options.safe_boundary_check && file_options.opensource_runtime) {
*error =
"The safe_boundary_check option is not supported outside of Google.";
return false;
@@ -119,6 +134,10 @@ bool CppGenerator::Generate(const FileDescriptor* file,
string basename = StripProto(file->name());
+ if (MaybeBootstrap(file_options, generator_context, file_options.bootstrap,
+ &basename)) {
+ return true;
+ }
FileGenerator file_generator(file, file_options);
@@ -163,32 +182,41 @@ bool CppGenerator::Generate(const FileDescriptor* file,
// Generate cc file(s).
if (UsingImplicitWeakFields(file, file_options)) {
- {
- // This is the global .cc file, containing enum/services/tables/reflection
+ if (file->name() == "net/proto2/proto/descriptor.proto") {
+ // If we are building with implicit weak fields then we do not want to
+ // produce any symbols for descriptor.proto, so we just create an empty
+ // pb.cc file.
std::unique_ptr<io::ZeroCopyOutputStream> output(
generator_context->Open(basename + ".pb.cc"));
- io::Printer printer(output.get(), '$');
- file_generator.GenerateGlobalSource(&printer);
- }
+ } else {
+ {
+ // This is the global .cc file, containing
+ // enum/services/tables/reflection
+ std::unique_ptr<io::ZeroCopyOutputStream> output(
+ generator_context->Open(basename + ".pb.cc"));
+ io::Printer printer(output.get(), '$');
+ file_generator.GenerateGlobalSource(&printer);
+ }
- int num_cc_files = file_generator.NumMessages();
+ int num_cc_files = file_generator.NumMessages();
- // If we're using implicit weak fields then we allow the user to optionally
- // specify how many files to generate, not counting the global pb.cc file.
- // If we have more files than messages, then some files will be generated as
- // empty placeholders.
- if (file_options.num_cc_files > 0) {
- GOOGLE_CHECK_LE(file_generator.NumMessages(), file_options.num_cc_files)
- << "There must be at least as many numbered .cc files as messages.";
- num_cc_files = file_options.num_cc_files;
- }
- for (int i = 0; i < num_cc_files; i++) {
- // TODO(gerbens) Agree on naming scheme.
- std::unique_ptr<io::ZeroCopyOutputStream> output(
- generator_context->Open(basename + "." + SimpleItoa(i) + ".cc"));
- io::Printer printer(output.get(), '$');
- if (i < file_generator.NumMessages()) {
- file_generator.GenerateSourceForMessage(i, &printer);
+ // If we're using implicit weak fields then we allow the user to
+ // optionally specify how many files to generate, not counting the global
+ // pb.cc file. If we have more files than messages, then some files will
+ // be generated as empty placeholders.
+ if (file_options.num_cc_files > 0) {
+ GOOGLE_CHECK_LE(file_generator.NumMessages(), file_options.num_cc_files)
+ << "There must be at least as many numbered .cc files as messages.";
+ num_cc_files = file_options.num_cc_files;
+ }
+ for (int i = 0; i < num_cc_files; i++) {
+ std::unique_ptr<io::ZeroCopyOutputStream> output(
+ generator_context->Open(basename + ".out/" +
+ SimpleItoa(i) + ".cc"));
+ io::Printer printer(output.get(), '$');
+ if (i < file_generator.NumMessages()) {
+ file_generator.GenerateSourceForMessage(i, &printer);
+ }
}
}
} else {