Skip to content

Commit 464b9cc

Browse files
Apply fallback availability logic to beta information.
For platforms that have a fallback platform, copy the availability information passed through the CLI, including the `isBeta` value. rdar://127227456
1 parent aa0a99e commit 464b9cc

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationConverter.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
166166
self.experimentalModifyCatalogWithGeneratedCuration = experimentalModifyCatalogWithGeneratedCuration
167167

168168
// Inject current platform versions if provided
169-
if let currentPlatforms {
169+
if var currentPlatforms {
170+
171+
// Add missing platforms if their fallback platform is present.
172+
DefaultAvailability.fallbackPlatforms.forEach { fallbackPlatform in
173+
if (!currentPlatforms.keys.contains(fallbackPlatform.key.displayName)) {
174+
currentPlatforms[fallbackPlatform.key.displayName] = currentPlatforms[fallbackPlatform.value.rawValue]
175+
}
176+
}
170177
self.context.externalMetadata.currentPlatforms = currentPlatforms
171178
}
172179
}

Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,71 @@ class ConvertActionTests: XCTestCase {
18181818
])
18191819
}
18201820

1821+
func testBetaInAvailabilityFallbackPlatforms() throws {
1822+
1823+
func generateConvertAction(currentPlatforms: [String : PlatformVersion]) throws -> ConvertAction {
1824+
try ConvertAction(
1825+
documentationBundleURL: bundle.absoluteURL,
1826+
outOfProcessResolver: nil,
1827+
analyze: false,
1828+
targetDirectory: targetDirectory,
1829+
htmlTemplateDirectory: Folder.emptyHTMLTemplateDirectory.absoluteURL,
1830+
emitDigest: false,
1831+
currentPlatforms: currentPlatforms,
1832+
dataProvider: testDataProvider,
1833+
fileManager: testDataProvider,
1834+
temporaryDirectory: testDataProvider.uniqueTemporaryDirectory()
1835+
)
1836+
}
1837+
let bundle = Folder(name: "nested", content: [
1838+
Folder(name: "folders", content: [
1839+
Folder(name: "unit-test.docc", content: [
1840+
InfoPlist(displayName: "TestBundle", identifier: "com.test.example"),
1841+
]),
1842+
])
1843+
])
1844+
let testDataProvider = try TestFileSystem(folders: [bundle, Folder.emptyHTMLTemplateDirectory])
1845+
let targetDirectory = URL(fileURLWithPath: testDataProvider.currentDirectoryPath)
1846+
.appendingPathComponent("target", isDirectory: true)
1847+
1848+
// Test whether the missing platforms copy the availability information from the fallback platform.
1849+
var action = try generateConvertAction(currentPlatforms: ["iOS": PlatformVersion(.init(10, 0, 0), beta: true)])
1850+
XCTAssertEqual(action.context.externalMetadata.currentPlatforms, [
1851+
"iOS" : PlatformVersion(.init(10, 0, 0), beta: true),
1852+
"Mac Catalyst" : PlatformVersion(.init(10, 0, 0), beta: true),
1853+
"iPadOS" : PlatformVersion(.init(10, 0, 0), beta: true),
1854+
])
1855+
// Test whether the non-missing platforms don't copy the availability information from the fallback platform.
1856+
action = try generateConvertAction(currentPlatforms: [
1857+
"iOS": PlatformVersion(.init(10, 0, 0), beta: true),
1858+
"Mac Catalyst": PlatformVersion(.init(11, 0, 0), beta: false)
1859+
])
1860+
XCTAssertEqual(action.context.externalMetadata.currentPlatforms, [
1861+
"iOS" : PlatformVersion(.init(10, 0, 0), beta: true),
1862+
"Mac Catalyst" : PlatformVersion(.init(11, 0, 0), beta: false),
1863+
"iPadOS" : PlatformVersion(.init(10, 0, 0), beta: true)
1864+
])
1865+
action = try generateConvertAction(currentPlatforms: [
1866+
"iOS": PlatformVersion(.init(10, 0, 0), beta: true),
1867+
"Mac Catalyst" : PlatformVersion(.init(11, 0, 0), beta: true),
1868+
"iPadOS": PlatformVersion(.init(12, 0, 0), beta: false),
1869+
1870+
])
1871+
XCTAssertEqual(action.context.externalMetadata.currentPlatforms, [
1872+
"iOS" : PlatformVersion(.init(10, 0, 0), beta: true),
1873+
"Mac Catalyst" : PlatformVersion(.init(11, 0, 0), beta: true),
1874+
"iPadOS" : PlatformVersion(.init(12, 0, 0), beta: false),
1875+
])
1876+
// Test whether the non-missing platforms don't copy the availability information from the non-fallback platform.
1877+
action = try generateConvertAction(currentPlatforms: [
1878+
"tvOS": PlatformVersion(.init(13, 0, 0), beta: true)
1879+
1880+
])
1881+
XCTAssertEqual(action.context.externalMetadata.currentPlatforms, [
1882+
"tvOS": PlatformVersion(.init(13, 0, 0), beta: true)
1883+
])
1884+
}
1885+
18211886
func testResolvedTopicReferencesAreCachedByDefaultWhenConverting() throws {
18221887
let bundle = Folder(
18231888
name: "unit-test.docc",

0 commit comments

Comments
 (0)