-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[NFC] Remove SupportedPlatforms, add PlatformVersionProvider
#7161
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
Changes from 10 commits
7430175
6fd1606
456959e
420f01a
76121f4
4bd4bb4
d6c0c8a
f3004a7
a6760d9
f8aee43
9387af3
b777e12
5b6670e
20b84c9
49e0955
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift open source project | ||
| // | ||
| // Copyright (c) 2014-2023 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See http://swift.org/LICENSE.txt for license information | ||
| // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import struct PackageModel.MinimumDeploymentTarget | ||
| import struct PackageModel.Platform | ||
| import struct PackageModel.PlatformVersion | ||
| import struct PackageModel.SupportedPlatform | ||
|
|
||
| /// Merging two sets of supported platforms, preferring the max constraint | ||
| func merge(into partial: inout [SupportedPlatform], platforms: [SupportedPlatform]) { | ||
| for platformSupport in platforms { | ||
| if let existing = partial.firstIndex(where: { $0.platform == platformSupport.platform }) { | ||
| if partial[existing].version < platformSupport.version { | ||
| partial.remove(at: existing) | ||
| partial.append(platformSupport) | ||
| } | ||
| } else { | ||
| partial.append(platformSupport) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public struct PlatformVersionProvider: Hashable { | ||
| public enum Implementation: Hashable { | ||
| case mergingFromTargets([ResolvedTarget]) | ||
| case customXCTestMinimumDeploymentTargets([PackageModel.Platform: PlatformVersion]?) | ||
| case empty | ||
| } | ||
|
|
||
| private let implementation: Implementation | ||
|
|
||
| public init(implementation: Implementation) { | ||
| self.implementation = implementation | ||
| } | ||
|
|
||
| func derivedXCTestPlatformProvider(_ declared: PackageModel.Platform) -> PlatformVersion? { | ||
| switch implementation { | ||
| case .mergingFromTargets(let targets): | ||
| let platforms = targets.reduce(into: [SupportedPlatform]()) { partial, item in | ||
| merge(into: &partial, platforms: [item.getDerived(for: declared, usingXCTest: item.type == .test)]) | ||
| } | ||
| return platforms.first!.version | ||
|
|
||
| case .customXCTestMinimumDeploymentTargets(let customXCTestMinimumDeploymentTargets): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are creating the implementation enum here, I wonder if we should make custom and default two separate cases?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I also found that |
||
| if let customXCTestMinimumDeploymentTargets { | ||
| return customXCTestMinimumDeploymentTargets[declared] | ||
| } else { | ||
| return MinimumDeploymentTarget.default.computeXCTestMinimumDeploymentTarget(for: declared) | ||
| } | ||
|
|
||
| case .empty: | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| /// Returns the supported platform instance for the given platform. | ||
| func getDerived(declared: [SupportedPlatform], for platform: Platform, usingXCTest: Bool) -> SupportedPlatform { | ||
| // derived platform based on known minimum deployment target logic | ||
| if let declaredPlatform = declared.first(where: { $0.platform == platform }) { | ||
| var version = declaredPlatform.version | ||
|
|
||
| if usingXCTest, let xcTestMinimumDeploymentTarget = self.derivedXCTestPlatformProvider(platform), version < xcTestMinimumDeploymentTarget { | ||
| version = xcTestMinimumDeploymentTarget | ||
| } | ||
|
|
||
| // If the declared version is smaller than the oldest supported one, we raise the derived version to that. | ||
| if version < platform.oldestSupportedVersion { | ||
| version = platform.oldestSupportedVersion | ||
| } | ||
|
|
||
| return SupportedPlatform( | ||
| platform: declaredPlatform.platform, | ||
| version: version, | ||
| options: declaredPlatform.options | ||
| ) | ||
| } else { | ||
| let minimumSupportedVersion: PlatformVersion | ||
| if usingXCTest, let xcTestMinimumDeploymentTarget = self.derivedXCTestPlatformProvider(platform), xcTestMinimumDeploymentTarget > platform.oldestSupportedVersion { | ||
| minimumSupportedVersion = xcTestMinimumDeploymentTarget | ||
| } else { | ||
| minimumSupportedVersion = platform.oldestSupportedVersion | ||
| } | ||
|
|
||
| let oldestSupportedVersion: PlatformVersion | ||
| if platform == .macCatalyst { | ||
| let iOS = self.getDerived(declared: declared, for: .iOS, usingXCTest: usingXCTest) | ||
| // If there was no deployment target specified for Mac Catalyst, fall back to the iOS deployment target. | ||
| oldestSupportedVersion = max(minimumSupportedVersion, iOS.version) | ||
| } else { | ||
| oldestSupportedVersion = minimumSupportedVersion | ||
| } | ||
|
|
||
| return SupportedPlatform( | ||
| platform: platform, | ||
| version: oldestSupportedVersion, | ||
| options: [] | ||
| ) | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.