Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make check for bundled protos more resilient #21

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,20 @@ package struct ProtobufCodeGenParser {
}

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

// If any services in the file depend on well-known Protobuf types then also import
// SwiftProtobuf. Importing SwiftProtobuf unconditionally results in warnings in the generated
// code if access-levels are used on imports and no well-known types are used.
let usesAnyWellKnownTypesInServices = file.services.contains { service in
service.methods.contains { method in
let inputIsWellKnown = method.inputType.wellKnownType != nil
let outputIsWellKnown = method.outputType.wellKnownType != nil
return inputIsWellKnown || outputIsWellKnown
}
// If there's a dependency on a bundled proto then add the SwiftProtobuf import.
//
// Importing SwiftProtobuf unconditionally results in warnings in the generated
// code if access-levels are used on imports and no bundled protos are used.
let dependsOnBundledProto = file.dependencies.contains { descriptor in
SwiftProtobufInfo.isBundledProto(file: descriptor)
}
if usesAnyWellKnownTypesInServices {

if dependsOnBundledProto {
codeDependencies.append(Dependency(module: "SwiftProtobuf", accessLevel: self.accessLevel))
}

Expand Down
Loading