-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
DefaultAvailabilityOptions
.
`DefaultAvailabilityOptions` is a new info plist key that contains a dictionary of options to customise the logic of the default availbaility. The only option for now is `InheritVersionNumber` that lets you add the version into the symbols availability that don't define explicit availability annotation. The default is true.
- Loading branch information
1 parent
6055aa9
commit fbc3ead
Showing
5 changed files
with
118 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Sources/SwiftDocC/Infrastructure/Workspace/DefaultAvailailabilityOptions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
Copyright (c) 2024 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 | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension DocumentationBundle.Info { | ||
|
||
/// A collection of options that customaise the default availability behaviour. | ||
/// | ||
/// Default availability options are applied to all the modules contained in the documentation bundle. | ||
/// | ||
/// This information can be authored in the bundle's Info.plist file, as a dictionary of option name and boolean pairs. | ||
/// | ||
/// ``` | ||
/// <key>CDDefaultAvailabilityOptions</key> | ||
/// <dict> | ||
/// <key>OptionName</key> | ||
/// <bool/> | ||
/// </dict> | ||
/// ``` | ||
public struct DefaultAvailabilityOptions: Codable, Equatable { | ||
|
||
/// A set of non-standard behaviors that apply to this node. | ||
fileprivate(set) var options: Options | ||
|
||
/// Options that specify behaviors of the default availability logic. | ||
struct Options: OptionSet { | ||
|
||
let rawValue: Int | ||
|
||
/// Enable or disable symbol availability version inference from the module default availability. | ||
static let inheritVersionNumber = Options(rawValue: 1 << 0) | ||
} | ||
|
||
/// String representation of the default availability options. | ||
private enum CodingKeys: String, CodingKey { | ||
case inheritVersionNumber = "InheritVersionNumber" | ||
} | ||
|
||
public init(from decoder: any Decoder) throws { | ||
self.init() | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
if try values.decodeIfPresent(Bool.self, forKey: .inheritVersionNumber) == false { | ||
options.remove(.inheritVersionNumber) | ||
} | ||
} | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
if !options.contains(.inheritVersionNumber) { | ||
try container.encode(false, forKey: .inheritVersionNumber) | ||
} | ||
|
||
} | ||
|
||
public init() { | ||
self.options = .inheritVersionNumber | ||
} | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters