Skip to content

Commit 70a8a0d

Browse files
authored
Create new target for common code (#1331)
* Extract the SourceLanguage type to a new "Common" target * Keep public type alias to moved SourceLanguage type * Use Swift 6 language mode in new target * Add "DocC" prefix to new common target
1 parent 4864758 commit 70a8a0d

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

Package.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ let package = Package(
4343
.target(
4444
name: "SwiftDocC",
4545
dependencies: [
46+
.target(name: "DocCCommon"),
4647
.product(name: "Markdown", package: "swift-markdown"),
4748
.product(name: "SymbolKit", package: "swift-docc-symbolkit"),
4849
.product(name: "CLMDB", package: "swift-lmdb"),
@@ -55,6 +56,7 @@ let package = Package(
5556
name: "SwiftDocCTests",
5657
dependencies: [
5758
.target(name: "SwiftDocC"),
59+
.target(name: "DocCCommon"),
5860
.target(name: "SwiftDocCTestUtilities"),
5961
],
6062
resources: [
@@ -70,6 +72,7 @@ let package = Package(
7072
name: "SwiftDocCUtilities",
7173
dependencies: [
7274
.target(name: "SwiftDocC"),
75+
.target(name: "DocCCommon"),
7376
.product(name: "NIOHTTP1", package: "swift-nio", condition: .when(platforms: [.macOS, .iOS, .linux, .android])),
7477
.product(name: "ArgumentParser", package: "swift-argument-parser")
7578
],
@@ -81,6 +84,7 @@ let package = Package(
8184
dependencies: [
8285
.target(name: "SwiftDocCUtilities"),
8386
.target(name: "SwiftDocC"),
87+
.target(name: "DocCCommon"),
8488
.target(name: "SwiftDocCTestUtilities"),
8589
],
8690
resources: [
@@ -95,6 +99,7 @@ let package = Package(
9599
name: "SwiftDocCTestUtilities",
96100
dependencies: [
97101
.target(name: "SwiftDocC"),
102+
.target(name: "DocCCommon"),
98103
.product(name: "SymbolKit", package: "swift-docc-symbolkit"),
99104
],
100105
swiftSettings: swiftSettings
@@ -109,6 +114,25 @@ let package = Package(
109114
exclude: ["CMakeLists.txt"],
110115
swiftSettings: swiftSettings
111116
),
117+
118+
// A few common types and core functionality that's useable by all other targets.
119+
.target(
120+
name: "DocCCommon",
121+
dependencies: [
122+
// This target shouldn't have any local dependencies so that all other targets can depend on it.
123+
// We can add dependencies on SymbolKit and Markdown here but they're not needed yet.
124+
],
125+
swiftSettings: [.swiftLanguageMode(.v6)]
126+
),
127+
128+
.testTarget(
129+
name: "DocCCommonTests",
130+
dependencies: [
131+
.target(name: "DocCCommon"),
132+
.target(name: "SwiftDocCTestUtilities"),
133+
],
134+
swiftSettings: [.swiftLanguageMode(.v6)]
135+
),
112136

113137
// Test app for SwiftDocCUtilities
114138
.executableTarget(
File renamed without changes.

Sources/SwiftDocC/Model/SourceLanguage.swift renamed to Sources/DocCCommon/SourceLanguage.swift

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

4-
Copyright (c) 2021-2023 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
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

1111
/// A programming language.
12-
public struct SourceLanguage: Hashable, Codable, Comparable {
12+
public struct SourceLanguage: Hashable, Codable, Comparable, Sendable {
1313
/// The display name of the programming language.
1414
public var name: String
1515
/// A globally unique identifier for the language.
@@ -132,7 +132,7 @@ public struct SourceLanguage: Hashable, Codable, Comparable {
132132
public static let metal = SourceLanguage(name: "Metal", id: "metal")
133133

134134
/// The list of programming languages that are known to DocC.
135-
public static var knownLanguages: [SourceLanguage] = [.swift, .objectiveC, .javaScript, .data, .metal]
135+
public static let knownLanguages: [SourceLanguage] = [.swift, .objectiveC, .javaScript, .data, .metal]
136136

137137
enum CodingKeys: CodingKey {
138138
case name
@@ -157,7 +157,9 @@ public struct SourceLanguage: Hashable, Codable, Comparable {
157157

158158
try container.encode(self.name, forKey: SourceLanguage.CodingKeys.name)
159159
try container.encode(self.id, forKey: SourceLanguage.CodingKeys.id)
160-
try container.encodeIfNotEmpty(self.idAliases, forKey: SourceLanguage.CodingKeys.idAliases)
160+
if !self.idAliases.isEmpty {
161+
try container.encode(self.idAliases, forKey: SourceLanguage.CodingKeys.idAliases)
162+
}
161163
try container.encode(self.linkDisambiguationID, forKey: SourceLanguage.CodingKeys.linkDisambiguationID)
162164
}
163165

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2025 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
public import DocCCommon
12+
13+
public typealias SourceLanguage = DocCCommon.SourceLanguage

Tests/SwiftDocCTests/Model/SourceLanguageTests.swift renamed to Tests/DocCCommonTests/SourceLanguageTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
@testable import SwiftDocC
11+
import DocCCommon
1212
import XCTest
1313

1414
class SourceLanguageTests: XCTestCase {

0 commit comments

Comments
 (0)