Skip to content

Commit 3a1efba

Browse files
committed
Expand iOS platform to include iPadOS and Mac Catalyst in declaration fragments
Automatically expands iOS to include its fallback platforms (iPadOS and Mac Catalyst) in declaration fragment platform arrays to ensure consistent platform representation. Uses the existing DefaultAvailability.fallbackPlatforms mapping to determine which platforms should be included when a base platform is present. rdar://158142013
1 parent 899007f commit 3a1efba

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

Sources/SwiftDocC/Model/Rendering/RenderSectionTranslator/DeclarationsSectionTranslator.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -187,6 +187,26 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
187187
return declarations
188188
}
189189

190+
/// Returns the given platforms with any missing fallback platforms added.
191+
///
192+
/// This function uses the centralized `DefaultAvailability.fallbackPlatforms` mapping to ensure
193+
/// consistency with platform expansion logic used throughout the codebase.
194+
///
195+
/// For example, when iOS is present in the platforms array, this function adds iPadOS and Mac Catalyst
196+
/// if they are not already included.
197+
///
198+
/// - Parameter platforms: The original platforms array.
199+
/// - Returns: The platforms array with fallback platforms added where applicable.
200+
func expandPlatformsWithFallbacks(_ platforms: [PlatformName?]) -> [PlatformName?] {
201+
guard !platforms.isEmpty else { return platforms }
202+
203+
// Add fallback platforms if their primary platform is present but the fallback is missing
204+
let fallbacks = DefaultAvailability.fallbackPlatforms.compactMap { fallback, primary in
205+
platforms.contains(primary) && !platforms.contains(fallback) ? fallback : nil
206+
}
207+
return platforms + fallbacks
208+
}
209+
190210
func comparePlatformNames(_ lhs: PlatformName?, _ rhs: PlatformName?) -> Bool {
191211
guard let lhsValue = lhs, let rhsValue = rhs else {
192212
return lhs == nil
@@ -204,6 +224,8 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
204224
]
205225
for pair in declaration {
206226
let (platforms, declaration) = pair
227+
let expandedPlatforms = expandPlatformsWithFallbacks(platforms)
228+
let platformNames = sortPlatformNames(expandedPlatforms)
207229

208230
let renderedTokens: [DeclarationRenderSection.Token]
209231
let otherDeclarations: DeclarationRenderSection.OtherDeclarations?
@@ -242,7 +264,7 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
242264
declarations.append(
243265
DeclarationRenderSection(
244266
languages: languages,
245-
platforms: sortPlatformNames(platforms),
267+
platforms: platformNames,
246268
tokens: renderedTokens,
247269
otherDeclarations: otherDeclarations
248270
)
@@ -252,7 +274,8 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
252274
if let alternateDeclarations = symbol.alternateDeclarationVariants[trait] {
253275
for pair in alternateDeclarations {
254276
let (platforms, decls) = pair
255-
let platformNames = sortPlatformNames(platforms)
277+
let expandedPlatforms = expandPlatformsWithFallbacks(platforms)
278+
let platformNames = sortPlatformNames(expandedPlatforms)
256279
for alternateDeclaration in decls {
257280
let renderedTokens = alternateDeclaration.declarationFragments.map(translateFragment)
258281

Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,6 @@ class SemaToRenderNodeTests: XCTestCase {
927927
}
928928

929929
func testCompileSymbol() async throws {
930-
throw XCTSkip("TDD: Temporarily disabled while implementing platform expansion")
931930
let (_, bundle, context) = try await testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in
932931
// Remove the SideClass sub heading to match the expectations of this test
933932
let graphURL = url.appendingPathComponent("sidekit.symbols.json")
@@ -1174,7 +1173,6 @@ class SemaToRenderNodeTests: XCTestCase {
11741173
}
11751174

11761175
func testCompileSymbolWithExternalReferences() async throws {
1177-
throw XCTSkip("TDD: Temporarily disabled while implementing platform expansion")
11781176
class TestSymbolResolver: GlobalExternalSymbolResolver {
11791177
func symbolReferenceAndEntity(withPreciseIdentifier preciseIdentifier: String) -> (ResolvedTopicReference, LinkResolver.ExternalEntity)? {
11801178
let reference = ResolvedTopicReference(bundleID: "com.test.external.symbols", path: "/\(preciseIdentifier)", sourceLanguage: .objectiveC)

Tests/SwiftDocCTests/Rendering/DeclarationsRenderSectionTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ class DeclarationsRenderSectionTests: XCTestCase {
134134
}
135135

136136
func testAlternateDeclarations() async throws {
137-
throw XCTSkip("TDD: Temporarily disabled while implementing platform expansion")
138137
let (bundle, context) = try await testBundleAndContext(named: "AlternateDeclarations")
139138
let reference = ResolvedTopicReference(
140139
bundleID: bundle.id,
@@ -162,7 +161,6 @@ class DeclarationsRenderSectionTests: XCTestCase {
162161
}
163162

164163
func testPlatformSpecificDeclarations() async throws {
165-
throw XCTSkip("TDD: Temporarily disabled while implementing platform expansion")
166164
// init(_ content: MyClass) throws
167165
let declaration1: SymbolGraph.Symbol.DeclarationFragments = .init(declarationFragments: [
168166
.init(kind: .keyword, spelling: "init", preciseIdentifier: nil),

Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
368368
}
369369

370370
func testDeclarationsSectionVariants() async throws {
371-
throw XCTSkip("TDD: Temporarily disabled while implementing platform expansion")
372371
func declarationSection(in renderNode: RenderNode) throws -> DeclarationRenderSection {
373372
try XCTUnwrap(
374373
(renderNode.primaryContentSections.first as? DeclarationsRenderSection)?.declarations.first

0 commit comments

Comments
 (0)