From 913a7afb6eacbc91fa8e0d952eb58323bba5a02e Mon Sep 17 00:00:00 2001 From: Sofia Rodriguez Morales Date: Thu, 24 Apr 2025 14:58:44 +0100 Subject: [PATCH 1/2] 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 --- .../Symbol Graph/SymbolGraphLoader.swift | 5 +-- .../Rendering/SymbolAvailabilityTests.swift | 33 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift b/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift index 920fa88397..18f15dedd1 100644 --- a/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift +++ b/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift @@ -317,9 +317,10 @@ struct SymbolGraphLoader { // Fill introduced versions when missing. availability.availability = availability.availability.map { - $0.fillingMissingIntroducedVersion( + let availabilityPlatformName = $0.domain.map { PlatformName(operatingSystemName: $0.rawValue) } ?? platformName + return $0.fillingMissingIntroducedVersion( from: defaultAvailabilityVersionByPlatform, - fallbackPlatform: DefaultAvailability.fallbackPlatforms[platformName]?.rawValue + fallbackPlatform: DefaultAvailability.fallbackPlatforms[availabilityPlatformName]?.rawValue ) } // Add the module availability information to each of the symbols availability mixin. diff --git a/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift b/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift index 643e9ba2f2..b760d3c3f3 100644 --- a/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift +++ b/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift @@ -45,6 +45,7 @@ class SymbolAvailabilityTests: XCTestCase { private func renderNodeAvailability( defaultAvailability: [DefaultAvailability.ModuleAvailability] = [], symbolGraphOperatingSystemPlatformName: String, + symbolGraphEnvironmentName: String? = nil, symbols: [SymbolGraph.Symbol], symbolName: String ) throws -> [AvailabilityRenderItem] { @@ -56,7 +57,7 @@ class SymbolAvailabilityTests: XCTestCase { ]), JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph( moduleName: "ModuleName", - platform: SymbolGraph.Platform(architecture: nil, vendor: nil, operatingSystem: SymbolGraph.OperatingSystem(name: symbolGraphOperatingSystemPlatformName), environment: nil), + platform: SymbolGraph.Platform(architecture: nil, vendor: nil, operatingSystem: SymbolGraph.OperatingSystem(name: symbolGraphOperatingSystemPlatformName), environment: symbolGraphEnvironmentName), symbols: symbols, relationships: [] )), @@ -71,7 +72,7 @@ class SymbolAvailabilityTests: XCTestCase { func testSymbolGraphSymbolWithoutDeprecatedVersionAndIntroducedVersion() throws { - let availability = try renderNodeAvailability( + var availability = try renderNodeAvailability( defaultAvailability: [], symbolGraphOperatingSystemPlatformName: "ios", symbols: [ @@ -91,6 +92,34 @@ class SymbolAvailabilityTests: XCTestCase { "iPadOS - 1.2.3", "Mac Catalyst - 1.2.3", ]) + + availability = try renderNodeAvailability( + defaultAvailability: [ + DefaultAvailability.ModuleAvailability(platformName: PlatformName(operatingSystemName: "iOS"), platformVersion: "1.2.3") + ], + symbolGraphOperatingSystemPlatformName: "ios", + symbolGraphEnvironmentName: "macabi", + symbols: [ + makeSymbol( + id: "platform-1-symbol", + kind: .class, + pathComponents: ["SymbolName"], + availability: [ + makeAvailabilityItem(domainName: "iOS", deprecated: SymbolGraph.SemanticVersion(string: "1.2.3")), + makeAvailabilityItem(domainName: "visionOS", deprecated: SymbolGraph.SemanticVersion(string: "1.0.0")) + ] + ) + ], + symbolName: "SymbolName" + ) + + XCTAssertEqual(availability.map { "\($0.name ?? "") \($0.introduced ?? "") - \($0.deprecated ?? "")" }, [ + // The default availability for iOS shouldnt be copied to visionOS. + "iOS 1.2.3 - 1.2.3", + "iPadOS 1.2.3 - ", + "Mac Catalyst 1.2.3 - 1.2.3", + "visionOS - 1.0", + ]) } func testSymbolGraphSymbolWithObsoleteVersion() throws { From 11e6360091c12bc996c6effffbbc984311b37a69 Mon Sep 17 00:00:00 2001 From: Sofia Rodriguez Morales Date: Thu, 24 Apr 2025 15:01:53 +0100 Subject: [PATCH 2/2] Update license header year. --- .../Infrastructure/Symbol Graph/SymbolGraphLoader.swift | 2 +- Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift b/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift index 18f15dedd1..50baa2529c 100644 --- a/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift +++ b/Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2024 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information diff --git a/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift b/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift index b760d3c3f3..a0c0b129e9 100644 --- a/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift +++ b/Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2024 Apple Inc. and the Swift project authors + Copyright (c) 2024-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information