Skip to content

Commit e17d4eb

Browse files
authored
Revert "Minimal viable merge command (#821)"
This reverts commit 491d26a.
1 parent 2ed33fb commit e17d4eb

28 files changed

+179
-1434
lines changed

Sources/SwiftDocC/Converter/RenderNode+Coding.swift

Lines changed: 17 additions & 19 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 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
@@ -27,9 +27,6 @@ extension CodingUserInfoKey {
2727
static let variantOverrides = CodingUserInfoKey(rawValue: "variantOverrides")!
2828

2929
static let baseEncodingPath = CodingUserInfoKey(rawValue: "baseEncodingPath")!
30-
31-
/// A user info key to indicate a base path for local asset URLs.
32-
static let assetPrefixComponent = CodingUserInfoKey(rawValue: "assetPrefixComponent")!
3330
}
3431

3532
extension Encoder {
@@ -48,12 +45,12 @@ extension Encoder {
4845
///
4946
/// These references will then be encoded at a later stage by `TopicRenderReferenceEncoder`.
5047
var skipsEncodingReferences: Bool {
51-
userInfo[.skipsEncodingReferences] as? Bool ?? false
52-
}
53-
54-
/// A base path to use when creating destination URLs for local assets (images, videos, downloads, etc.)
55-
var assetPrefixComponent: String? {
56-
userInfo[.assetPrefixComponent] as? String
48+
guard let userInfoValue = userInfo[.skipsEncodingReferences] as? Bool else {
49+
// The value doesn't exist so we should encode reference. Return false.
50+
return false
51+
}
52+
53+
return userInfoValue
5754
}
5855
}
5956

@@ -84,7 +81,12 @@ extension JSONEncoder {
8481
/// These references will then be encoded at a later stage by `TopicRenderReferenceEncoder`.
8582
var skipsEncodingReferences: Bool {
8683
get {
87-
userInfo[.skipsEncodingReferences] as? Bool ?? false
84+
guard let userInfoValue = userInfo[.skipsEncodingReferences] as? Bool else {
85+
// The value doesn't exist so we should encode reference. Return false.
86+
return false
87+
}
88+
89+
return userInfoValue
8890
}
8991
set {
9092
userInfo[.skipsEncodingReferences] = newValue
@@ -102,14 +104,13 @@ public enum RenderJSONEncoder {
102104
/// process which should not be shared in other encoding units. Instead, call this API to create a new encoder for each render node you want to encode.
103105
///
104106
/// - Parameters:
105-
/// - prettyPrint: If `true`, the encoder formats its output to make it easy to read; if `false`, the output is compact.
106-
/// - emitVariantOverrides: Whether the encoder should emit the top-level ``RenderNode/variantOverrides`` property that holds language-specific documentation data.
107-
/// - assetPrefixComponent: A path component to include in destination URLs for local assets (images, videos, downloads, etc.)
107+
/// - prettyPrint: If `true`, the encoder formats its output to make it easy to read; if `false`, the output is compact.
108+
/// - emitVariantOverrides: Whether the encoder should emit the top-level ``RenderNode/variantOverrides`` property that holds language-
109+
/// specific documentation data.
108110
/// - Returns: The new JSON encoder.
109111
public static func makeEncoder(
110112
prettyPrint: Bool = shouldPrettyPrintOutputJSON,
111-
emitVariantOverrides: Bool = true,
112-
assetPrefixComponent: String? = nil
113+
emitVariantOverrides: Bool = true
113114
) -> JSONEncoder {
114115
let encoder = JSONEncoder()
115116

@@ -124,9 +125,6 @@ public enum RenderJSONEncoder {
124125
if emitVariantOverrides {
125126
encoder.userInfo[.variantOverrides] = VariantOverrides()
126127
}
127-
if let bundleIdentifier = assetPrefixComponent {
128-
encoder.userInfo[.assetPrefixComponent] = bundleIdentifier
129-
}
130128

131129
return encoder
132130
}

Sources/SwiftDocC/Indexing/RenderIndexJSON/RenderIndex.swift

Lines changed: 5 additions & 35 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) 2022-2024 Apple Inc. and the Swift project authors
4+
Copyright (c) 2022 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
@@ -23,74 +23,45 @@ import SymbolKit
2323
/// `Sources/SwiftDocC/SwiftDocC.docc/Resources/RenderIndex.spec.json`.
2424
public struct RenderIndex: Codable, Equatable {
2525
/// The current schema version of the Index JSON spec.
26-
public static let currentSchemaVersion = SemanticVersion(major: 0, minor: 1, patch: 2)
26+
public static let currentSchemaVersion = SemanticVersion(major: 0, minor: 1, patch: 1)
2727

2828
/// The version of the RenderIndex spec that was followed when creating this index.
2929
public let schemaVersion: SemanticVersion
3030

3131
/// A mapping of interface languages to the index nodes they contain.
32-
public private(set) var interfaceLanguages: [String: [Node]]
32+
public let interfaceLanguages: [String: [Node]]
3333

3434
/// The values of the image references used in the documentation index.
3535
public private(set) var references: [String: ImageReference]
3636

37-
/// The unique identifiers of the archives that are included in the documentation index.
38-
public private(set) var includedArchiveIdentifiers: [String]
39-
4037
enum CodingKeys: CodingKey {
4138
case schemaVersion
4239
case interfaceLanguages
4340
case references
44-
case includedArchiveIdentifiers
4541
}
4642

4743
/// Creates a new render index with the given interface language to node mapping.
4844
public init(
4945
interfaceLanguages: [String: [Node]],
50-
references: [String: ImageReference] = [:],
51-
includedArchiveIdentifiers: [String]
46+
references: [String: ImageReference] = [:]
5247
) {
5348
self.schemaVersion = Self.currentSchemaVersion
5449
self.interfaceLanguages = interfaceLanguages
5550
self.references = references
56-
self.includedArchiveIdentifiers = includedArchiveIdentifiers
5751
}
5852

5953
public func encode(to encoder: Encoder) throws {
6054
var container = encoder.container(keyedBy: CodingKeys.self)
6155
try container.encode(self.schemaVersion, forKey: .schemaVersion)
6256
try container.encode(self.interfaceLanguages, forKey: .interfaceLanguages)
6357
try container.encodeIfNotEmpty(self.references, forKey: .references)
64-
try container.encodeIfNotEmpty(self.includedArchiveIdentifiers, forKey: .includedArchiveIdentifiers)
6558
}
6659

6760
public init(from decoder: Decoder) throws {
6861
let container = try decoder.container(keyedBy: CodingKeys.self)
6962
self.schemaVersion = try container.decode(SemanticVersion.self, forKey: .schemaVersion)
7063
self.interfaceLanguages = try container.decode([String : [RenderIndex.Node]].self, forKey: .interfaceLanguages)
7164
self.references = try container.decodeIfPresent([String : ImageReference].self, forKey: .references) ?? [:]
72-
self.includedArchiveIdentifiers = try container.decodeIfPresent([String].self.self, forKey: .includedArchiveIdentifiers) ?? []
73-
}
74-
75-
public mutating func merge(_ other: RenderIndex) throws {
76-
for (languageID, nodes) in other.interfaceLanguages {
77-
interfaceLanguages[languageID, default: []].append(contentsOf: nodes)
78-
}
79-
80-
try references.merge(other.references) { _, new in throw MergeError.referenceCollision(new.identifier.identifier) }
81-
82-
includedArchiveIdentifiers.append(contentsOf: other.includedArchiveIdentifiers)
83-
}
84-
85-
enum MergeError: DescribedError {
86-
case referenceCollision(String)
87-
88-
var errorDescription: String {
89-
switch self {
90-
case .referenceCollision(let reference):
91-
return "Collision merging image references. Reference \(reference.singleQuoted) exists in more than one input archive."
92-
}
93-
}
9465
}
9566
}
9667

@@ -283,8 +254,7 @@ extension RenderIndex {
283254
},
284255
uniquingKeysWith: +
285256
),
286-
references: builder.iconReferences,
287-
includedArchiveIdentifiers: [builder.bundleIdentifier]
257+
references: builder.iconReferences
288258
)
289259
}
290260
}

Sources/SwiftDocC/Model/Rendering/References/ImageReference.swift

Lines changed: 2 additions & 2 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 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
@@ -74,7 +74,7 @@ public struct ImageReference: MediaReference, URLReference, Equatable {
7474
var result = [VariantProxy]()
7575
// sort assets by URL path for deterministic sorting of images
7676
asset.variants.sorted(by: \.value.path).forEach { (key, value) in
77-
let url = value.isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent, prefixComponent: encoder.assetPrefixComponent)
77+
let url = value.isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent)
7878
result.append(VariantProxy(url: url, traits: key, svgID: asset.metadata[value]?.svgID))
7979
}
8080
try container.encode(result, forKey: .variants)

Sources/SwiftDocC/Model/Rendering/References/RenderReference.swift

Lines changed: 4 additions & 11 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 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
@@ -69,17 +69,10 @@ extension URLReference {
6969
///
7070
/// The converter that writes the built documentation to the file system is responsible for copying the referenced file to this destination.
7171
///
72-
/// - Parameters:
73-
/// - path: The path of the file.
74-
/// - prefixComponent: An optional path component to add before the path of the file.
72+
/// - Parameter path: The path of the file.
7573
/// - Returns: The destination URL for the given file path.
76-
func destinationURL(for path: String, prefixComponent: String?) -> URL {
77-
var url = Self.baseURL
78-
if let bundleName = prefixComponent {
79-
url.appendPathComponent(bundleName, isDirectory: true)
80-
}
81-
url.appendPathComponent(path, isDirectory: false)
82-
return url
74+
func destinationURL(for path: String) -> URL {
75+
return Self.baseURL.appendingPathComponent(path, isDirectory: false)
8376
}
8477
}
8578

Sources/SwiftDocC/Model/Rendering/References/VideoReference.swift

Lines changed: 2 additions & 2 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-2023 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
@@ -81,7 +81,7 @@ public struct VideoReference: MediaReference, URLReference, Equatable {
8181
// convert the data asset to a serializable object
8282
var result = [VariantProxy]()
8383
asset.variants.sorted(by: \.value.path).forEach { (key, value) in
84-
let url = value.isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent, prefixComponent: encoder.assetPrefixComponent)
84+
let url = value.isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent)
8585
result.append(VariantProxy(url: url, traits: key))
8686
}
8787
try container.encode(result, forKey: .variants)

Sources/SwiftDocC/Model/Rendering/Tutorial/References/DownloadReference.swift

Lines changed: 4 additions & 4 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-2023 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
@@ -86,7 +86,7 @@ public struct DownloadReference: RenderReference, URLReference, Equatable {
8686

8787
// Render URL
8888
if !encodeUrlVerbatim {
89-
try container.encode(renderURL(for: url, prefixComponent: encoder.assetPrefixComponent), forKey: .url)
89+
try container.encode(renderURL(for: url), forKey: .url)
9090
} else {
9191
try container.encode(url, forKey: .url)
9292
}
@@ -100,8 +100,8 @@ public struct DownloadReference: RenderReference, URLReference, Equatable {
100100
}
101101

102102
extension DownloadReference {
103-
private func renderURL(for url: URL, prefixComponent: String?) -> URL {
104-
url.isAbsoluteWebURL ? url : destinationURL(for: url.lastPathComponent, prefixComponent: prefixComponent)
103+
private func renderURL(for url: URL) -> URL {
104+
url.isAbsoluteWebURL ? url : destinationURL(for: url.lastPathComponent)
105105
}
106106
}
107107

Sources/SwiftDocC/SwiftDocC.docc/Resources/RenderIndex.spec.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "Specification of the Swift-DocC Index.json file.",
5-
"version": "0.1.2",
5+
"version": "0.1.0",
66
"title": "RenderIndex"
77
},
88
"paths": {},
@@ -33,12 +33,6 @@
3333
"$ref": "#/components/schemas/ImageRenderReference"
3434
}
3535
},
36-
"includedArchiveIdentifiers": {
37-
"type": "array",
38-
"items": {
39-
"type": "string"
40-
}
41-
}
4236
}
4337
},
4438
"Node": {

Sources/SwiftDocC/Utility/FileManagerProtocol.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ public protocol FileManagerProtocol {
5151
func contentsOfDirectory(atPath path: String) throws -> [String]
5252
func contentsOfDirectory(at url: URL, includingPropertiesForKeys keys: [URLResourceKey]?, options mask: FileManager.DirectoryEnumerationOptions) throws -> [URL]
5353

54-
/// The temporary directory for the current user.
55-
var temporaryDirectory: URL { get }
56-
5754
/// Creates a file with the specified `contents` at the specified location.
5855
///
5956
/// - Parameters:

0 commit comments

Comments
 (0)