Skip to content

Commit 94eaaa3

Browse files
Use availability item platform name to compute default availability information. (#1208)
Use availability item platform name to compute default availability information. This change makes a small tweak to the default availability logic so it uses the symbol availability item platform name instead of the symbol graph platform name to calculate the corresponding default introduced version from the default availability. rdar://146774862
1 parent 38ea39d commit 94eaaa3

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift

Lines changed: 4 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
@@ -317,9 +317,10 @@ struct SymbolGraphLoader {
317317

318318
// Fill introduced versions when missing.
319319
availability.availability = availability.availability.map {
320-
$0.fillingMissingIntroducedVersion(
320+
let availabilityPlatformName = $0.domain.map { PlatformName(operatingSystemName: $0.rawValue) } ?? platformName
321+
return $0.fillingMissingIntroducedVersion(
321322
from: defaultAvailabilityVersionByPlatform,
322-
fallbackPlatform: DefaultAvailability.fallbackPlatforms[platformName]?.rawValue
323+
fallbackPlatform: DefaultAvailability.fallbackPlatforms[availabilityPlatformName]?.rawValue
323324
)
324325
}
325326
// Add the module availability information to each of the symbols availability mixin.

Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift

Lines changed: 32 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) 2024 Apple Inc. and the Swift project authors
4+
Copyright (c) 2024-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
@@ -45,6 +45,7 @@ class SymbolAvailabilityTests: XCTestCase {
4545
private func renderNodeAvailability(
4646
defaultAvailability: [DefaultAvailability.ModuleAvailability] = [],
4747
symbolGraphOperatingSystemPlatformName: String,
48+
symbolGraphEnvironmentName: String? = nil,
4849
symbols: [SymbolGraph.Symbol],
4950
symbolName: String
5051
) throws -> [AvailabilityRenderItem] {
@@ -56,7 +57,7 @@ class SymbolAvailabilityTests: XCTestCase {
5657
]),
5758
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(
5859
moduleName: "ModuleName",
59-
platform: SymbolGraph.Platform(architecture: nil, vendor: nil, operatingSystem: SymbolGraph.OperatingSystem(name: symbolGraphOperatingSystemPlatformName), environment: nil),
60+
platform: SymbolGraph.Platform(architecture: nil, vendor: nil, operatingSystem: SymbolGraph.OperatingSystem(name: symbolGraphOperatingSystemPlatformName), environment: symbolGraphEnvironmentName),
6061
symbols: symbols,
6162
relationships: []
6263
)),
@@ -71,7 +72,7 @@ class SymbolAvailabilityTests: XCTestCase {
7172

7273
func testSymbolGraphSymbolWithoutDeprecatedVersionAndIntroducedVersion() throws {
7374

74-
let availability = try renderNodeAvailability(
75+
var availability = try renderNodeAvailability(
7576
defaultAvailability: [],
7677
symbolGraphOperatingSystemPlatformName: "ios",
7778
symbols: [
@@ -91,6 +92,34 @@ class SymbolAvailabilityTests: XCTestCase {
9192
"iPadOS <nil> - 1.2.3",
9293
"Mac Catalyst <nil> - 1.2.3",
9394
])
95+
96+
availability = try renderNodeAvailability(
97+
defaultAvailability: [
98+
DefaultAvailability.ModuleAvailability(platformName: PlatformName(operatingSystemName: "iOS"), platformVersion: "1.2.3")
99+
],
100+
symbolGraphOperatingSystemPlatformName: "ios",
101+
symbolGraphEnvironmentName: "macabi",
102+
symbols: [
103+
makeSymbol(
104+
id: "platform-1-symbol",
105+
kind: .class,
106+
pathComponents: ["SymbolName"],
107+
availability: [
108+
makeAvailabilityItem(domainName: "iOS", deprecated: SymbolGraph.SemanticVersion(string: "1.2.3")),
109+
makeAvailabilityItem(domainName: "visionOS", deprecated: SymbolGraph.SemanticVersion(string: "1.0.0"))
110+
]
111+
)
112+
],
113+
symbolName: "SymbolName"
114+
)
115+
116+
XCTAssertEqual(availability.map { "\($0.name ?? "<nil>") \($0.introduced ?? "<nil>") - \($0.deprecated ?? "<nil>")" }, [
117+
// The default availability for iOS shouldnt be copied to visionOS.
118+
"iOS 1.2.3 - 1.2.3",
119+
"iPadOS 1.2.3 - <nil>",
120+
"Mac Catalyst 1.2.3 - 1.2.3",
121+
"visionOS <nil> - 1.0",
122+
])
94123
}
95124

96125
func testSymbolGraphSymbolWithObsoleteVersion() throws {

0 commit comments

Comments
 (0)