SwiftProtobufInfo.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Sources/SwiftProtobufPluginLibrary/LibraryInfo.swift - Helpers info about the SwiftProtobuf library
  2. //
  3. // Copyright (c) 2014 - 2017 Apple Inc. and the project authors
  4. // Licensed under Apache License v2.0 with Runtime Library Exception
  5. //
  6. // See LICENSE.txt for license information:
  7. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  8. //
  9. // -----------------------------------------------------------------------------
  10. ///
  11. /// Helpers for info about the SwiftProtobuf library itself.
  12. ///
  13. // -----------------------------------------------------------------------------
  14. import Foundation
  15. import SwiftProtobuf
  16. /// Helpers about the library.
  17. public enum SwiftProtobufInfo {
  18. /// Proto Files that ship with the library.
  19. public static let bundledProtoFiles: Set<String> = [
  20. "google/protobuf/any.proto",
  21. "google/protobuf/api.proto",
  22. // Even though descriptor.proto is *not* a WKT, it is included in the
  23. // library so developers trying to compile .proto files with message,
  24. // field, or file extensions don't have to generate it.
  25. "google/protobuf/descriptor.proto",
  26. "google/protobuf/duration.proto",
  27. "google/protobuf/empty.proto",
  28. "google/protobuf/field_mask.proto",
  29. "google/protobuf/source_context.proto",
  30. "google/protobuf/struct.proto",
  31. "google/protobuf/timestamp.proto",
  32. "google/protobuf/type.proto",
  33. "google/protobuf/wrappers.proto",
  34. ]
  35. /// Checks if a `Google_Protobuf_FileDescriptorProto` is a library bundled proto file.
  36. @available(*, deprecated, message: "Use the version that takes a FileDescriptor instead.")
  37. public static func isBundledProto(file: Google_Protobuf_FileDescriptorProto) -> Bool {
  38. file.package == "google.protobuf" && bundledProtoFiles.contains(file.name)
  39. }
  40. /// Checks if a `FileDescriptor` is a library bundled proto file.
  41. public static func isBundledProto(file: FileDescriptor) -> Bool {
  42. file.package == "google.protobuf" && bundledProtoFiles.contains(file.name)
  43. }
  44. }