Skip to content

Commit

Permalink
Add empty proto file test
Browse files Browse the repository at this point in the history
* Add empty proto file test
* Add a preamble to `foo-messages.proto`
* Don't unconditionally add a dependency on `GRPCProtobuf` if there are
  no services
* Add the new test case code generation to `dev/protos/generate.sh`
* depend on `grpc-swift` `main` to pick up empty file generation
  changes.
  • Loading branch information
rnro committed Jan 7, 2025
1 parent 9f07522 commit 5731604
Show file tree
Hide file tree
Showing 7 changed files with 875 additions and 815 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let products: [Product] = [
let dependencies: [Package.Dependency] = [
.package(
url: "https://github.com/grpc/grpc-swift.git",
exact: "2.0.0-beta.2"
branch: "main"
),
.package(
url: "https://github.com/apple/swift-protobuf.git",
Expand Down
8 changes: 5 additions & 3 deletions Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ package struct ProtobufCodeGenParser {

extension ProtobufCodeGenParser {
fileprivate func codeDependencies(file: FileDescriptor) -> [Dependency] {
var codeDependencies: [Dependency] = [
Dependency(module: "GRPCProtobuf", accessLevel: .internal)
]
var codeDependencies: [Dependency] = []

if file.services.count > 0 {
codeDependencies.append(Dependency(module: "GRPCProtobuf", accessLevel: .internal))
}

// If there's a dependency on a bundled proto then add the SwiftProtobuf import.
//
Expand Down
Binary file not shown.
Binary file modified Tests/GRPCProtobufCodeGenTests/Generated/foo-service.pb
Binary file not shown.
1,667 changes: 856 additions & 811 deletions Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions dev/protos/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ function generate_foo_service_descriptor_set {
--include_imports
}

function generate_foo_messages_descriptor_set {
local proto proto_path output
proto="$here/local/foo-messages.proto"
proto_path="$(dirname "$proto")"
output="$root/Tests/GRPCProtobufCodeGenTests/Generated/foo-messages.pb"

invoke_protoc --descriptor_set_out="$output" "$proto" -I "$proto_path" \
--include_source_info \
--include_imports
}

function generate_bar_service_descriptor_set {
local proto proto_path output
proto="$here/local/bar-service.proto"
Expand Down Expand Up @@ -152,5 +163,6 @@ generate_error_service
# Descriptor sets for tests
generate_test_service_descriptor_set
generate_foo_service_descriptor_set
generate_foo_messages_descriptor_set
generate_bar_service_descriptor_set
generate_wkt_service_descriptor_set
1 change: 1 addition & 0 deletions dev/protos/local/foo-messages.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Leading trivia.
syntax = "proto3";

package foo;
Expand Down

0 comments on commit 5731604

Please sign in to comment.