Skip to content

Commit 0894c06

Browse files
[6.3] Create shared target for common code (#1371)
* 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 rdar://165757025 * build: move incorrect file movement (#1356) The SwiftDocCUtilities directory was renamed to CommandLine, and then renamed again. When The second rename occurred, the file was not restored. --------- Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
1 parent c2f10af commit 0894c06

File tree

7 files changed

+72
-19
lines changed

7 files changed

+72
-19
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(

Sources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception
77
See https://swift.org/LICENSE.txt for license information
88
#]]
99

10+
add_subdirectory(DocCCommon)
1011
add_subdirectory(SwiftDocC)
1112
add_subdirectory(SwiftDocCUtilities)
1213
add_subdirectory(docc)

Sources/DocCCommon/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright © 2014 - 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+
#]]
9+
10+
add_library(DocCCommon STATIC
11+
SourceLanguage.swift)

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

Sources/SwiftDocC/CMakeLists.txt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ See https://swift.org/LICENSE.txt for license information
1010
add_library(SwiftDocC
1111
Benchmark/Benchmark.swift
1212
Benchmark/BenchmarkResults.swift
13+
Benchmark/Metrics.swift
1314
Benchmark/Metrics/Duration.swift
1415
Benchmark/Metrics/ExternalTopicsHash.swift
1516
Benchmark/Metrics/OutputSize.swift
1617
Benchmark/Metrics/PeakMemory.swift
1718
Benchmark/Metrics/TopicAnchorHash.swift
1819
Benchmark/Metrics/TopicGraphHash.swift
19-
Benchmark/Metrics.swift
2020
"Catalog Processing/GeneratedCurationWriter.swift"
2121
Checker/Checker.swift
2222
Checker/Checkers/AbstractContainsFormattedTextOnly.swift
@@ -198,16 +198,16 @@ add_library(SwiftDocC
198198
Model/Rendering/RenderContentCompiler.swift
199199
Model/Rendering/RenderContentConvertible.swift
200200
Model/Rendering/RenderContext.swift
201+
Model/Rendering/RenderNode.Tag.swift
202+
Model/Rendering/RenderNode.swift
203+
Model/Rendering/RenderNodeTranslator.swift
204+
Model/Rendering/RenderNodeVariant.swift
201205
Model/Rendering/RenderNode/AnyMetadata.swift
202206
Model/Rendering/RenderNode/CodableContentSection.swift
203207
Model/Rendering/RenderNode/CodableRenderReference.swift
204208
Model/Rendering/RenderNode/CodableRenderSection.swift
205209
Model/Rendering/RenderNode/RenderMetadata.swift
206210
Model/Rendering/RenderNode/RenderNode+Codable.swift
207-
Model/Rendering/RenderNode.swift
208-
Model/Rendering/RenderNode.Tag.swift
209-
Model/Rendering/RenderNodeTranslator.swift
210-
Model/Rendering/RenderNodeVariant.swift
211211
Model/Rendering/RenderReferenceStore.swift
212212
Model/Rendering/RenderSection.swift
213213
Model/Rendering/RenderSectionTranslator/AttributesSectionTranslator.swift
@@ -238,22 +238,22 @@ add_library(SwiftDocC
238238
Model/Rendering/Symbol/PossibleValuesRenderSection.swift
239239
Model/Rendering/Symbol/PropertiesRenderSection.swift
240240
Model/Rendering/Symbol/PropertyListDetailsRenderSection.swift
241-
Model/Rendering/Symbol/RelationshipsRenderSection.swift
242241
Model/Rendering/Symbol/RESTBodyRenderSection.swift
243242
Model/Rendering/Symbol/RESTEndpointRenderSection.swift
244243
Model/Rendering/Symbol/RESTExampleRenderSection.swift
245244
Model/Rendering/Symbol/RESTParametersRenderSection.swift
246245
Model/Rendering/Symbol/RESTResponseRenderSection.swift
246+
Model/Rendering/Symbol/RelationshipsRenderSection.swift
247247
Model/Rendering/Symbol/SampleDownloadSection.swift
248248
Model/Rendering/Symbol/TaskGroupRenderSection.swift
249249
Model/Rendering/TopicsSectionStyle.swift
250+
"Model/Rendering/Tutorial Article/TutorialArticleSection.swift"
250251
Model/Rendering/Tutorial/LineHighlighter.swift
251252
Model/Rendering/Tutorial/References/DownloadReference.swift
252253
Model/Rendering/Tutorial/References/XcodeRequirementReference.swift
253254
Model/Rendering/Tutorial/Sections/IntroRenderSection.swift
254255
Model/Rendering/Tutorial/Sections/TutorialAssessmentsRenderSection.swift
255256
Model/Rendering/Tutorial/Sections/TutorialSectionsRenderSection.swift
256-
"Model/Rendering/Tutorial Article/TutorialArticleSection.swift"
257257
"Model/Rendering/Tutorials Overview/Resources/RenderTile.swift"
258258
"Model/Rendering/Tutorials Overview/Sections/CallToActionSection.swift"
259259
"Model/Rendering/Tutorials Overview/Sections/ContentAndMediaGroupSection.swift"
@@ -299,7 +299,6 @@ add_library(SwiftDocC
299299
Model/Semantics/Parameter.swift
300300
Model/Semantics/Return.swift
301301
Model/Semantics/Throw.swift
302-
Model/SourceLanguage.swift
303302
Model/TaskGroup.swift
304303
Semantics/Abstracted.swift
305304
Semantics/Article/Article.swift
@@ -358,11 +357,11 @@ add_library(SwiftDocC
358357
Semantics/Options/TopicsVisualStyle.swift
359358
Semantics/Redirect.swift
360359
Semantics/Redirected.swift
360+
Semantics/ReferenceResolver.swift
361361
Semantics/Reference/Links.swift
362362
Semantics/Reference/Row.swift
363363
Semantics/Reference/Small.swift
364364
Semantics/Reference/TabNavigator.swift
365-
Semantics/ReferenceResolver.swift
366365
Semantics/Semantic.swift
367366
Semantics/SemanticAnalyzer.swift
368367
Semantics/Snippets/Snippet.swift
@@ -381,6 +380,8 @@ add_library(SwiftDocC
381380
Semantics/Technology/Volume/Volume.swift
382381
Semantics/Timed.swift
383382
Semantics/Titled.swift
383+
Semantics/TutorialArticle/Stack.swift
384+
Semantics/TutorialArticle/TutorialArticle.swift
384385
Semantics/Tutorial/Assessments/Assessments.swift
385386
"Semantics/Tutorial/Assessments/Multiple Choice/Choice/Choice.swift"
386387
"Semantics/Tutorial/Assessments/Multiple Choice/Choice/Justification.swift"
@@ -391,8 +392,6 @@ add_library(SwiftDocC
391392
Semantics/Tutorial/Tasks/TutorialSection.swift
392393
Semantics/Tutorial/Tutorial.swift
393394
Semantics/Tutorial/XcodeRequirement.swift
394-
Semantics/TutorialArticle/Stack.swift
395-
Semantics/TutorialArticle/TutorialArticle.swift
396395
Semantics/Visitor/SemanticVisitor.swift
397396
Semantics/Walker/SemanticWalker.swift
398397
Semantics/Walker/Walkers/SemanticTreeDumper.swift
@@ -402,6 +401,7 @@ add_library(SwiftDocC
402401
Utility/Checksum.swift
403402
Utility/Collection+ConcurrentPerform.swift
404403
Utility/CollectionChanges.swift
404+
Utility/CommonTypeExports.swift
405405
Utility/DataStructures/BidirectionalMap.swift
406406
Utility/DataStructures/GroupedSequence.swift
407407
Utility/DispatchGroup+Async.swift
@@ -440,14 +440,14 @@ add_library(SwiftDocC
440440
Utility/Graphs/DirectedGraph+Paths.swift
441441
Utility/Graphs/DirectedGraph+Traversal.swift
442442
Utility/Graphs/DirectedGraph.swift
443-
Utility/Language/EnglishLanguage.swift
444-
Utility/Language/NativeLanguage.swift
445-
Utility/ListItemUpdatable.swift
446443
Utility/LMDB/LMDB+Database.swift
447444
Utility/LMDB/LMDB+Environment.swift
448445
Utility/LMDB/LMDB+Error.swift
449446
Utility/LMDB/LMDB+Transaction.swift
450447
Utility/LMDB/LMDB.swift
448+
Utility/Language/EnglishLanguage.swift
449+
Utility/Language/NativeLanguage.swift
450+
Utility/ListItemUpdatable.swift
451451
Utility/LogHandle.swift
452452
Utility/MarkupExtensions/AnyLink.swift
453453
Utility/MarkupExtensions/BlockDirectiveExtensions.swift
@@ -463,6 +463,8 @@ add_library(SwiftDocC
463463
Utility/Synchronization.swift
464464
Utility/ValidatedURL.swift
465465
Utility/Version.swift)
466+
target_link_libraries(SwiftDocC PRIVATE
467+
DocCCommon)
466468
target_link_libraries(SwiftDocC PUBLIC
467469
SwiftMarkdown::Markdown
468470
DocC::SymbolKit
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)