Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/google/protobuf/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":code_generator",
":code_generator_lite",
":importer",
":retention",
":versions",
Expand Down
15 changes: 15 additions & 0 deletions src/google/protobuf/compiler/code_generator_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"


namespace google {
namespace protobuf {
namespace compiler {
Expand Down Expand Up @@ -56,5 +57,19 @@ bool IsKnownFeatureProto(absl::string_view filename) {
}

} // namespace compiler

namespace internal {

bool is_oss_was_read = false;

bool is_oss = true;

bool IsOss() {
is_oss_was_read = true;
return is_oss;
}

} // namespace internal

} // namespace protobuf
} // namespace google
11 changes: 11 additions & 0 deletions src/google/protobuf/compiler/code_generator_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ PROTOC_EXPORT std::string StripProto(absl::string_view filename);
PROTOC_EXPORT bool IsKnownFeatureProto(absl::string_view filename);

} // namespace compiler

namespace internal {

PROTOC_EXPORT bool IsOss();

#ifndef PROTO2_OPENSOURCE
void SetIsOss(bool new_is_oss);
#endif

} // namespace internal

} // namespace protobuf
} // namespace google

Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/compiler/command_line_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/code_generator_lite.h"
#include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor_database.h"
Expand Down
2 changes: 2 additions & 0 deletions src/google/protobuf/compiler/java/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ cc_library(
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf/compiler:code_generator_lite",
"//src/google/protobuf/compiler:versions",
"//src/google/protobuf/io:printer",
"//src/google/protobuf/io:tokenizer",
Expand Down Expand Up @@ -117,6 +118,7 @@ cc_library(
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf/compiler:code_generator_lite",
"@abseil-cpp//absl/log:absl_log",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
Expand Down
20 changes: 10 additions & 10 deletions src/google/protobuf/compiler/java/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void FileGenerator::Generate(io::Printer* printer) {
"GENCODE\n"
"// source: $filename$\n",
"filename", file_->name());
if (options_.opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print("// Protobuf Java Version: $protobuf_java_version$\n",
"protobuf_java_version", PROTOBUF_JAVA_VERSION_STRING);
}
Expand All @@ -335,7 +335,7 @@ void FileGenerator::Generate(io::Printer* printer) {
options_.annotate_code ? absl::StrCat(classname_, ".java.pb.meta") : "",
options_);

if (!options_.opensource_runtime) {
if (!google::protobuf::internal::IsOss()) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
Expand All @@ -353,7 +353,7 @@ void FileGenerator::Generate(io::Printer* printer) {
if (!context_->EnforceLite()) {
printer->Print("static {\n");
printer->Indent();
PrintGencodeVersionValidator(printer, options_.opensource_runtime,
PrintGencodeVersionValidator(printer, google::protobuf::internal::IsOss(),
classname_);
printer->Outdent();
printer->Print("}\n");
Expand Down Expand Up @@ -475,10 +475,10 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable(
" descriptor;\n"
"static {\n",
// TODO: Mark this as final.
"final", options_.opensource_runtime ? "" : "final");
"final", google::protobuf::internal::IsOss() ? "" : "final");
printer->Indent();

if (options_.opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
SharedCodeGenerator shared_code_generator(file_, options_);
shared_code_generator.GenerateDescriptors(printer);
} else {
Expand Down Expand Up @@ -610,7 +610,7 @@ static void GenerateSibling(
"GENCODE\n"
"// source: $filename$\n",
"filename", descriptor->file()->name());
if (opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer.Print("// Protobuf Java Version: $protobuf_java_version$\n",
"protobuf_java_version", PROTOBUF_JAVA_VERSION_STRING);
}
Expand Down Expand Up @@ -643,21 +643,21 @@ void FileGenerator::GenerateSiblings(
GenerateSibling<EnumGenerator>(
package_dir, java_package_, file_->enum_type(i), context, file_list,
options_.annotate_code, annotation_list, "", generator.get(),
options_.opensource_runtime, &EnumGenerator::Generate);
google::protobuf::internal::IsOss(), &EnumGenerator::Generate);
}
for (int i = 0; i < file_->message_type_count(); i++) {
if (NestedInFileClass(*file_->message_type(i), immutable_api_)) continue;
if (immutable_api_) {
GenerateSibling<MessageGenerator>(
package_dir, java_package_, file_->message_type(i), context,
file_list, options_.annotate_code, annotation_list, "OrBuilder",
message_generators_[i].get(), options_.opensource_runtime,
message_generators_[i].get(), google::protobuf::internal::IsOss(),
&MessageGenerator::GenerateInterface);
}
GenerateSibling<MessageGenerator>(
package_dir, java_package_, file_->message_type(i), context, file_list,
options_.annotate_code, annotation_list, "",
message_generators_[i].get(), options_.opensource_runtime,
message_generators_[i].get(), google::protobuf::internal::IsOss(),
&MessageGenerator::Generate);
}
if (HasGenericServices(file_, context_->EnforceLite())) {
Expand All @@ -668,7 +668,7 @@ void FileGenerator::GenerateSiblings(
GenerateSibling<ServiceGenerator>(
package_dir, java_package_, file_->service(i), context, file_list,
options_.annotate_code, annotation_list, "", generator.get(),
options_.opensource_runtime, &ServiceGenerator::Generate);
google::protobuf::internal::IsOss(), &ServiceGenerator::Generate);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/google/protobuf/compiler/java/full/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cc_library(
":fg",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator_lite",
"//src/google/protobuf/compiler/java:context",
"//src/google/protobuf/compiler/java:field_common",
"//src/google/protobuf/compiler/java:generator_common",
Expand Down Expand Up @@ -80,6 +81,7 @@ cc_library(
deps = [
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator_lite",
"//src/google/protobuf/compiler/java:context",
"//src/google/protobuf/compiler/java:generator_common",
"//src/google/protobuf/compiler/java:helpers",
Expand All @@ -98,6 +100,7 @@ cc_library(
deps = [
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator_lite",
"//src/google/protobuf/compiler/java:context",
"//src/google/protobuf/compiler/java:generator_common",
"//src/google/protobuf/compiler/java:helpers",
Expand Down Expand Up @@ -141,6 +144,7 @@ cc_library(
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf:protobuf_lite",
"//src/google/protobuf/compiler:code_generator_lite",
"//src/google/protobuf/compiler/java:context",
"//src/google/protobuf/compiler/java:field_common",
"//src/google/protobuf/compiler/java:generator_common",
Expand Down
9 changes: 5 additions & 4 deletions src/google/protobuf/compiler/java/full/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/code_generator_lite.h"
#include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h"
#include "google/protobuf/compiler/java/helpers.h"
Expand Down Expand Up @@ -75,7 +76,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) {
return;
}

if (!context_->options().opensource_runtime) {
if (!google::protobuf::internal::IsOss()) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
Expand Down Expand Up @@ -130,7 +131,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) {

printer->Print("static {\n");
printer->Indent();
PrintGencodeVersionValidator(printer, context_->options().opensource_runtime,
PrintGencodeVersionValidator(printer, google::protobuf::internal::IsOss(),
descriptor_->name());
printer->Outdent();
printer->Print("}\n");
Expand Down Expand Up @@ -188,7 +189,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) {
" return value;\n"
"}\n"
"\n");
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(
"/**\n"
" * @param value The numeric wire value of the corresponding enum "
Expand All @@ -209,7 +210,7 @@ void EnumNonLiteGenerator::Generate(io::Printer* printer) {
"entry.\n"
" * @return The enum associated with the given numeric wire value.\n"
" */\n");
if (!context_->options().opensource_runtime) {
if (!google::protobuf::internal::IsOss()) {
printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n");
}
printer->Print(
Expand Down
21 changes: 11 additions & 10 deletions src/google/protobuf/compiler/java/full/map_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "google/protobuf/compiler/code_generator_lite.h"
#include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h"
#include "google/protobuf/compiler/java/field_common.h"
Expand Down Expand Up @@ -75,7 +76,7 @@ void ImmutableMapFieldGenerator::SetMessageVariables(
// The code that generates the open-source version appears not to understand
// #else, so we have an #ifndef instead.
std::string pass_through_nullness =
context_->options().opensource_runtime
google::protobuf::internal::IsOss()
? "/* nullable */\n"
: "@com.google.protobuf.Internal.ProtoPassThroughNullness ";

Expand Down Expand Up @@ -201,7 +202,7 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(

const FieldDescriptor* value = MapValueField(descriptor_);
if (GetJavaType(value) == JAVATYPE_ENUM) {
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
Expand Down Expand Up @@ -261,7 +262,7 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
Expand Down Expand Up @@ -395,7 +396,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(

const FieldDescriptor* value = MapValueField(descriptor_);
if (GetJavaType(value) == JAVATYPE_ENUM) {
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(
variables_,
"/**\n"
Expand Down Expand Up @@ -439,7 +440,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_, Semantic::kSet);

if (SupportUnknownEnumValue(value)) {
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(
variables_,
"/**\n"
Expand Down Expand Up @@ -482,7 +483,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
} else {
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(
variables_,
"/**\n"
Expand Down Expand Up @@ -547,7 +548,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(

const FieldDescriptor* value = MapValueField(descriptor_);
if (GetJavaType(value) == JAVATYPE_ENUM) {
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(
variables_,
"/**\n"
Expand Down Expand Up @@ -661,7 +662,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
Expand Down Expand Up @@ -799,7 +800,7 @@ void ImmutableMapFieldGenerator::GenerateMessageMapBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_, Semantic::kSet);

if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(
variables_,
"/**\n"
Expand Down Expand Up @@ -887,7 +888,7 @@ void ImmutableMapFieldGenerator::GenerateMessageMapGetters(
"internalGet$capitalized_name$().ensureBuilderMap().containsKey(key);\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
if (google::protobuf::internal::IsOss()) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
Expand Down
Loading
Loading