Skip to content
Permalink
Browse files

Add descriptor objects to the PluginLibrary.

These provides the same sorta info a google/protobuf does with
their src/google/protobuf/descriptor.{h,cc} -- a graph of the
data in the protos so a generator can walk up/down, and directly
to resolved info.

Add unittests to ensure the graph is built and resolved as expected.
  • Loading branch information...
thomasvl committed Apr 25, 2017
1 parent 158f5b3 commit 18a6529a6225a920c328177386d0981d79e9f5b0
@@ -8,6 +8,7 @@ xcbaselines
/docs
/build
mined_words.txt
/DescriptorTestData.bin

# Intermediate conformance test outputs
failing_tests.txt
@@ -163,6 +163,10 @@ CONFORMANCE_PROTOS= \
Protos/conformance/conformance.proto \
Protos/google/protobuf/test_messages_proto3.proto

SWIFT_DESCRIPTOR_TEST_PROTOS= \
Protos/pluginlib_descriptor_test.proto \
${PLUGIN_PROTOS}

XCODEBUILD_EXTRAS =
# Invoke make with XCODE_SKIP_OPTIMIZER=1 to suppress the optimizer when
# building the Xcode projects. For Release builds, this is a non trivial speed
@@ -357,7 +361,12 @@ reference: build ${PROTOC_GEN_SWIFT}
# * protoc is built and installed
# * PROTOC at the top of this file is set correctly
#
regenerate: regenerate-library-protos regenerate-plugin-protos regenerate-test-protos regenerate-conformance-protos
regenerate: \
regenerate-library-protos \
regenerate-plugin-protos \
regenerate-test-protos \
regenerate-conformance-protos \
Tests/PluginLibraryTests/DescriptorTestData.swift

# Rebuild just the protos included in the runtime library
regenerate-library-protos: build ${PROTOC_GEN_SWIFT}
@@ -387,6 +396,20 @@ regenerate-test-protos: build ${PROTOC_GEN_SWIFT} Protos/generated_swift_names_e
$$t; \
done

Tests/PluginLibraryTests/DescriptorTestData.swift: build ${PROTOC_GEN_SWIFT} ${SWIFT_DESCRIPTOR_TEST_PROTOS}
@${PROTOC} \
--include_imports \
--descriptor_set_out=DescriptorTestData.bin \
-I Protos \
${SWIFT_DESCRIPTOR_TEST_PROTOS}
@rm -f $@
@echo '// See Makefile how this is generated.' >> $@
@echo 'import Foundation' >> $@
@echo 'let fileDesciptorSetBytes: [UInt8] = [' >> $@
@xxd -i < DescriptorTestData.bin >> $@
@echo ']' >> $@
@echo 'let fileDesciptorSetData = Data(bytes: fileDesciptorSetBytes)' >> $@

#
# Collect a list of words that appear in the SwiftProtobuf library
# source. These are words that may cause problems for generated code.
@@ -0,0 +1,79 @@
// Protos/pluginlib_descriptor_test.proto - test proto
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
// -----------------------------------------------------------------------------
///
/// Test proto for Tests/PluginLibraryTests/Test_Descriptor.swift
///
// -----------------------------------------------------------------------------

syntax = "proto2";

package swift_descriptor_test;

import "google/protobuf/descriptor.proto";
import "google/protobuf/compiler/plugin.proto";

enum TopLevelEnum {
VALUE_ZERO = 0;
VALUE_ONE = 1;
VALUE_TWO = 2;
}

message TopLevelMessage {

enum SubEnum {
SUB_VALUE_0 = 0;
SUB_VALUE_1 = 1;
SUB_VALUE_2 = 2;
}

message SubMessage {
optional int32 field1 = 1;
optional string field2 = 2;
optional SubMessage field3 = 3;
}

optional string field1 = 1;
optional int32 field2 = 2;

oneof o {
TopLevelEnum field3 = 3;
SubEnum field4 = 4;
SubMessage field5 = 5;
TopLevelMessage2 field6 = 6;
}
}

message TopLevelMessage2 {
optional TopLevelMessage left = 1;
optional TopLevelMessage2 right = 2;
}

message ExternalRefs {
optional google.protobuf.DescriptorProto desc = 1;
optional google.protobuf.compiler.Version ver = 2;
}

extend google.protobuf.FieldOptions {
optional string ext_str = 90000;
}

message ScoperForExt {
extend google.protobuf.MessageOptions {
optional TopLevelEnum ext_enum = 99001;
optional TopLevelMessage2 ext_msg = 99002;
}
}

service SomeService {
rpc Foo(google.protobuf.DescriptorProto) returns (google.protobuf.compiler.Version);
rpc Bar(TopLevelMessage) returns (TopLevelMessage2);
}

0 comments on commit 18a6529

Please sign in to comment.
You can’t perform that action at this time.