Platform.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2020 Google LLC
  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. import Foundation
  17. // The supported platforms.
  18. enum Platform: CaseIterable {
  19. case iOS
  20. case macOS
  21. case tvOS
  22. case watchOS
  23. var platformTargets: [TargetPlatform] {
  24. switch self {
  25. case .iOS: return [.iOSDevice, .iOSSimulator] + (SkipCatalyst.skip ? [] : [.catalyst])
  26. case .macOS: return [.macOS]
  27. case .tvOS: return [.tvOSDevice, .tvOSSimulator]
  28. case .watchOS: return [.watchOSDevice, .watchOSSimulator]
  29. }
  30. }
  31. /// Name of the platform as used in Podfiles.
  32. var name: String {
  33. switch self {
  34. case .iOS: return "ios"
  35. case .macOS: return "macos"
  36. case .tvOS: return "tvos"
  37. case .watchOS: return "watchos"
  38. }
  39. }
  40. /// Minimum supported version
  41. var minimumVersion: String {
  42. switch self {
  43. case .iOS: return PlatformMinimum.minimumIOSVersion
  44. case .macOS: return PlatformMinimum.minimumMacOSVersion
  45. case .tvOS: return PlatformMinimum.minimumTVOSVersion
  46. case .watchOS: return PlatformMinimum.minimumWatchOSVersion
  47. }
  48. }
  49. }
  50. enum PlatformMinimum {
  51. fileprivate static var minimumIOSVersion = ""
  52. fileprivate static var minimumMacOSVersion = ""
  53. fileprivate static var minimumTVOSVersion = ""
  54. fileprivate static var minimumWatchOSVersion = ""
  55. static func initialize(ios: String, macos: String, tvos: String, watchos: String) {
  56. minimumIOSVersion = ios
  57. minimumMacOSVersion = macos
  58. minimumTVOSVersion = tvos
  59. minimumWatchOSVersion = watchos
  60. }
  61. /// Useful to disable minimum version checking on pod installation. Pods still get built with
  62. /// for the minimum version specified in the podspec.
  63. static func useRecentVersions() {
  64. minimumIOSVersion = "15.0"
  65. minimumMacOSVersion = "12.0"
  66. minimumTVOSVersion = "15.0"
  67. minimumWatchOSVersion = "8.0"
  68. }
  69. }
  70. enum SkipCatalyst {
  71. fileprivate static var skip = false
  72. static func set() {
  73. skip = true
  74. }
  75. }