Internal changes

PiperOrigin-RevId: 542613464
pull/13126/head
Mike Kruskal 1 year ago committed by Copybara-Service
parent 7795c895dd
commit fd5167d40e
  1. 32
      src/google/protobuf/compiler/cpp/file.cc
  2. 3
      src/google/protobuf/compiler/cpp/file.h

@ -107,8 +107,26 @@ void UnmuteWuninitialized(io::Printer* p) {
#endif // __llvm__
)");
}
} // namespace
bool FileGenerator::ShouldSkipDependencyImports(
const FileDescriptor* dep) const {
// Do not import weak deps.
if (!options_.opensource_runtime && IsDepWeak(dep)) {
return true;
}
// Skip feature imports, which are a visible (but non-functional) deviation
// between editions and legacy syntax.
if (options_.strip_nonfunctional_codegen &&
dep->name() == "third_party/protobuf/cpp_features.proto") {
return true;
}
return false;
}
FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
: file_(file), options_(options), scc_analyzer_(options) {
std::vector<const Descriptor*> msgs = FlattenMessagesInFile(file);
@ -481,10 +499,7 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* p) {
for (int i = 0; i < file_->dependency_count(); ++i) {
const FileDescriptor* dep = file_->dependency(i);
if (!options_.opensource_runtime &&
IsDepWeak(dep)) { // Do not import weak deps.
continue;
}
if (ShouldSkipDependencyImports(dep)) continue;
std::string basename = StripProto(dep->name());
if (IsBootstrapProto(options_, file_)) {
@ -698,10 +713,10 @@ void FileGenerator::GetCrossFileReferencesForFile(const FileDescriptor* file,
for (int i = 0; i < file->dependency_count(); ++i) {
const FileDescriptor* dep = file->dependency(i);
if (IsDepWeak(dep)) {
refs->weak_reflection_files.insert(dep);
} else {
if (!ShouldSkipDependencyImports(file->dependency(i))) {
refs->strong_reflection_files.insert(dep);
} else if (IsDepWeak(dep)) {
refs->weak_reflection_files.insert(dep);
}
}
}
@ -1456,8 +1471,7 @@ void FileGenerator::GenerateDependencyIncludes(io::Printer* p) {
for (int i = 0; i < file_->dependency_count(); ++i) {
const FileDescriptor* dep = file_->dependency(i);
// Do not import weak deps.
if (IsDepWeak(dep)) {
if (ShouldSkipDependencyImports(dep)) {
continue;
}

@ -177,6 +177,9 @@ class FileGenerator {
// generally a breaking change so we prefer the #undef approach.
void GenerateMacroUndefs(io::Printer* p);
// Calculates if we should skip importing a specific dependency.
bool ShouldSkipDependencyImports(const FileDescriptor* dep) const;
bool IsDepWeak(const FileDescriptor* dep) const {
if (weak_deps_.count(dep) != 0) {
ABSL_CHECK(!options_.opensource_runtime);

Loading…
Cancel
Save