ConfigurationFile.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2024, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /// The configuration of the plugin.
  17. struct ConfigurationFile: Codable {
  18. /// The visibility of the generated files.
  19. enum Visibility: String, Codable {
  20. /// The generated files should have `internal` access level.
  21. case `internal`
  22. /// The generated files should have `public` access level.
  23. case `public`
  24. /// The generated files should have `package` access level.
  25. case `package`
  26. }
  27. /// The visibility of the generated files.
  28. var visibility: Visibility?
  29. /// Whether server code is generated.
  30. var server: Bool?
  31. /// Whether client code is generated.
  32. var client: Bool?
  33. /// Whether message code is generated.
  34. var message: Bool?
  35. // /// Whether reflection data is generated.
  36. // var reflectionData: Bool?
  37. /// Path to module map .asciipb file.
  38. var protoPathModuleMappings: String?
  39. /// Whether imports should have explicit access levels.
  40. var useAccessLevelOnImports: Bool?
  41. /// Specify the directory in which to search for
  42. /// imports. May be specified multiple times;
  43. /// directories will be searched in order.
  44. /// The target source directory is always appended
  45. /// to the import paths.
  46. var importPaths: [String]?
  47. /// The path to the `protoc` binary.
  48. ///
  49. /// If this is not set, SPM will try to find the tool itself.
  50. var protocPath: String?
  51. }
  52. extension CommonConfiguration {
  53. init(configurationFile: ConfigurationFile) {
  54. if let visibility = configurationFile.visibility {
  55. self.visibility = .init(visibility)
  56. }
  57. self.server = configurationFile.server
  58. self.client = configurationFile.client
  59. self.protoPathModuleMappings = configurationFile.protoPathModuleMappings
  60. self.useAccessLevelOnImports = configurationFile.useAccessLevelOnImports
  61. self.importPaths = configurationFile.importPaths
  62. self.protocPath = configurationFile.protocPath
  63. }
  64. }
  65. extension CommonConfiguration.Visibility {
  66. init(_ configurationFileVisibility: ConfigurationFile.Visibility) {
  67. switch configurationFileVisibility {
  68. case .internal: self = .internal
  69. case .public: self = .public
  70. case .package: self = .package
  71. }
  72. }
  73. }