Commit ca89a1a1 authored by Jon Skeet's avatar Jon Skeet

Change where we rename Descriptor.cs to DescriptorProtoFile.cs.

We now do this in protoc instead of the generation simpler.

Benefits:
- Generation script is simpler
- Detection is simpler as we now only need to care about one filename
- The embedded descriptor knows itself as "google/protobuf/descriptor.proto" avoiding dependency issues

This PR also makes the "invalid dependency" exception clearer in terms of expected and actual dependencies.
parent 3253634d
...@@ -37,10 +37,8 @@ fi ...@@ -37,10 +37,8 @@ fi
# Descriptor proto # Descriptor proto
# TODO(jonskeet): Remove fixup # TODO(jonskeet): Remove fixup
cp src/google/protobuf/descriptor.proto src/google/protobuf/descriptor_proto_file.proto
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/Reflection \ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/Reflection \
src/google/protobuf/descriptor_proto_file.proto src/google/protobuf/descriptor.proto
rm src/google/protobuf/descriptor_proto_file.proto
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/WellKnownTypes \ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/WellKnownTypes \
src/google/protobuf/any.proto \ src/google/protobuf/any.proto \
......
...@@ -301,7 +301,8 @@ namespace Google.Protobuf.Reflection ...@@ -301,7 +301,8 @@ namespace Google.Protobuf.Reflection
{ {
throw new DescriptorValidationException(result, throw new DescriptorValidationException(result,
"Dependencies passed to FileDescriptor.BuildFrom() don't match " + "Dependencies passed to FileDescriptor.BuildFrom() don't match " +
"those listed in the FileDescriptorProto."); "those listed in the FileDescriptorProto. Expected: " +
proto.Dependency[i] + " but was: " + dependencies[i].Name);
} }
} }
......
...@@ -118,6 +118,12 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) { ...@@ -118,6 +118,12 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) {
} }
std::string GetUmbrellaClassUnqualifiedName(const FileDescriptor* descriptor) { std::string GetUmbrellaClassUnqualifiedName(const FileDescriptor* descriptor) {
// We manually rename Descriptor to DescriptorProtoFile to avoid collisions with
// the static Descriptor property. It would be nice to be able to do this with an
// option, but it would be rarely used.
if (IsDescriptorProto(descriptor)) {
return "DescriptorProtoFile";
}
// umbrella_classname can no longer be set using message option. // umbrella_classname can no longer be set using message option.
std::string proto_file = descriptor->name(); std::string proto_file = descriptor->name();
int lastslash = proto_file.find_last_of("/"); int lastslash = proto_file.find_last_of("/");
......
...@@ -115,12 +115,7 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) { ...@@ -115,12 +115,7 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) {
// for use in the runtime. This is the only type which is allowed to use proto2 syntax, // for use in the runtime. This is the only type which is allowed to use proto2 syntax,
// and it generates internal classes. // and it generates internal classes.
inline bool IsDescriptorProto(const FileDescriptor* descriptor) { inline bool IsDescriptorProto(const FileDescriptor* descriptor) {
// TODO: Do this better! (Currently this depends on a hack in generate_protos.sh to rename return descriptor->name() == "google/protobuf/descriptor.proto";
// the file...)
// We need to be able to detect the "normal" name as well, for times that we're just
// depending on descriptor.proto instead of generating it.
return descriptor->name() == "google/protobuf/descriptor_proto_file.proto"
|| descriptor->name() == "google/protobuf/descriptor.proto";
} }
inline bool IsWrapperType(const FieldDescriptor* descriptor) { inline bool IsWrapperType(const FieldDescriptor* descriptor) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment