diff --git a/Reference/upstream/google/protobuf/unittest_empty.pb.swift b/Reference/upstream/google/protobuf/unittest_empty.pb.swift index 03ed9adee..826fd255b 100644 --- a/Reference/upstream/google/protobuf/unittest_empty.pb.swift +++ b/Reference/upstream/google/protobuf/unittest_empty.pb.swift @@ -24,15 +24,4 @@ // This file intentionally left blank. (At one point this wouldn't compile // correctly.) -import Foundation -import SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} +// This file contained no messages, enums, or extensions. diff --git a/Sources/protoc-gen-swift/FileGenerator.swift b/Sources/protoc-gen-swift/FileGenerator.swift index 2e2e99775..4b9bfde0a 100644 --- a/Sources/protoc-gen-swift/FileGenerator.swift +++ b/Sources/protoc-gen-swift/FileGenerator.swift @@ -85,18 +85,25 @@ class FileGenerator { } else if let location = fileDescriptor.sourceCodeInfoLocation(path: syntaxPath) { commentLocation = location } - var comments = String() if let commentLocation = commentLocation { - comments = commentLocation.asSourceComment(commentPrefix: "///", - leadingDetachedPrefix: "//") - // If the was a leading or tailing comment it won't have a blank - // line, after it, so ensure there is one. - if !comments.isEmpty && !comments.hasSuffix("\n\n") { - comments.append("\n") + let comments = commentLocation.asSourceComment(commentPrefix: "///", + leadingDetachedPrefix: "//") + if !comments.isEmpty { + // If the was a leading or tailing comment it won't have a blank + // line, after it, so ensure there is one. + p.print(comments, newlines: !comments.hasSuffix("\n\n")) } } - p.print("\(comments)\(generatorOptions.importDirective.snippet) Foundation") + // If there is nothing to generate, then just record that and be done (usually means + // there just was one or more services). + let generateEmpty = fileDescriptor.enums.isEmpty && fileDescriptor.messages.isEmpty && fileDescriptor.extensions.isEmpty + guard !generateEmpty else { + p.print("// This file contained no messages, enums, or extensions.") + return + } + + p.print("\(generatorOptions.importDirective.snippet) Foundation") if fileDescriptor.isBundledProto { p.print("// 'import \(namer.swiftProtobufModuleName)' suppressed, this proto file is meant to be bundled in the runtime.")