@ -11,6 +11,7 @@
# include "google/protobuf/compiler/command_line_interface.h"
# include "google/protobuf/compiler/command_line_interface.h"
# include <cstdint>
# include <cstdlib>
# include <cstdlib>
# include "absl/algorithm/container.h"
# include "absl/algorithm/container.h"
@ -295,28 +296,6 @@ bool GetBootstrapParam(const std::string& parameter) {
}
}
bool EnforceEditionsSupport (
const std : : string & codegen_name , uint64_t supported_features ,
const std : : vector < const FileDescriptor * > & parsed_files ) {
if ( ( supported_features & CodeGenerator : : FEATURE_SUPPORTS_EDITIONS ) = = 0 ) {
for ( const auto fd : parsed_files ) {
if ( FileDescriptorLegacy ( fd ) . syntax ( ) = =
FileDescriptorLegacy : : SYNTAX_EDITIONS ) {
std : : cerr
< < fd - > name ( ) < < " : is an editions file, but code generator "
< < codegen_name
< < " hasn't been updated to support editions yet. Please ask "
" the owner of this code generator to add support or "
" switch back to proto2/proto3. \n \n See "
" https://protobuf.dev/editions/overview/ for more information. "
< < std : : endl ;
return false ;
}
}
}
return true ;
}
} // namespace
} // namespace
void CommandLineInterface : : GetTransitiveDependencies (
void CommandLineInterface : : GetTransitiveDependencies (
@ -1538,24 +1517,26 @@ bool CommandLineInterface::SetupFeatureResolution(DescriptorPool& pool) {
for ( const auto & output : output_directives_ ) {
for ( const auto & output : output_directives_ ) {
if ( output . generator = = nullptr ) continue ;
if ( output . generator = = nullptr ) continue ;
if ( ( output . generator - > GetSupportedFeatures ( ) &
if ( ( output . generator - > GetSupportedFeatures ( ) &
CodeGenerator : : FEATURE_SUPPORTS_EDITIONS ) = = 0 ) {
CodeGenerator : : FEATURE_SUPPORTS_EDITIONS ) ! = 0 ) {
continue ;
// Only validate min/max edition on generators that advertise editions
}
// support. Generators still under development will always use the
if ( output . generator - > GetMinimumEdition ( ) ! = PROTOBUF_MINIMUM_EDITION ) {
// correct values.
ABSL_LOG ( ERROR ) < < " Built-in generator " < < output . name
if ( output . generator - > GetMinimumEdition ( ) ! = minimum_edition ) {
< < " specifies a minimum edition "
ABSL_LOG ( ERROR ) < < " Built-in generator " < < output . name
< < output . generator - > GetMinimumEdition ( )
< < " specifies a minimum edition "
< < " which is not the protoc minimum "
< < output . generator - > GetMinimumEdition ( )
< < PROTOBUF_MINIMUM_EDITION < < " . " ;
< < " which is not the protoc minimum "
return false ;
< < minimum_edition < < " . " ;
}
return false ;
if ( output . generator - > GetMaximumEdition ( ) ! = PROTOBUF_MAXIMUM_EDITION ) {
}
ABSL_LOG ( ERROR ) < < " Built-in generator " < < output . name
if ( output . generator - > GetMaximumEdition ( ) ! = maximum_edition ) {
< < " specifies a maximum edition "
ABSL_LOG ( ERROR ) < < " Built-in generator " < < output . name
< < output . generator - > GetMaximumEdition ( )
< < " specifies a maximum edition "
< < " which is not the protoc maximum "
< < output . generator - > GetMaximumEdition ( )
< < PROTOBUF_MAXIMUM_EDITION < < " . " ;
< < " which is not the protoc maximum "
return false ;
< < maximum_edition < < " . " ;
return false ;
}
}
}
for ( const FieldDescriptor * ext :
for ( const FieldDescriptor * ext :
output . generator - > GetFeatureExtensions ( ) ) {
output . generator - > GetFeatureExtensions ( ) ) {
@ -2566,6 +2547,37 @@ bool CommandLineInterface::EnforceProto3OptionalSupport(
return true ;
return true ;
}
}
bool CommandLineInterface : : EnforceEditionsSupport (
const std : : string & codegen_name , uint64_t supported_features ,
const std : : vector < const FileDescriptor * > & parsed_files ) const {
if ( supported_features & CodeGenerator : : FEATURE_SUPPORTS_EDITIONS ) {
// This generator explicitly supports editions.
return true ;
}
if ( experimental_editions_ ) {
// The user has explicitly specified the experimental flag.
return true ;
}
for ( const auto * fd : parsed_files ) {
// Skip enforcement for allowlisted files.
if ( IsEarlyEditionsFile ( fd - > name ( ) ) ) continue ;
if ( FileDescriptorLegacy ( fd ) . syntax ( ) = =
FileDescriptorLegacy : : SYNTAX_EDITIONS ) {
std : : cerr
< < fd - > name ( ) < < " : is an editions file, but code generator "
< < codegen_name
< < " hasn't been updated to support editions yet. Please ask "
" the owner of this code generator to add support or "
" switch back to proto2/proto3. \n \n See "
" https://protobuf.dev/editions/overview/ for more information. "
< < std : : endl ;
return false ;
}
}
return true ;
}
bool CommandLineInterface : : GenerateOutput (
bool CommandLineInterface : : GenerateOutput (
const std : : vector < const FileDescriptor * > & parsed_files ,
const std : : vector < const FileDescriptor * > & parsed_files ,
const OutputDirective & output_directive ,
const OutputDirective & output_directive ,