From 0018dcaef542b55c16cc1f509840f63b64213912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Fri, 14 Nov 2025 17:52:20 +0100 Subject: [PATCH 1/2] 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 --- Package.swift | 24 +++++++++++++++++++ .../CMakeLists.txt | 0 .../Model => DocCCommon}/SourceLanguage.swift | 10 ++++---- .../SwiftDocC/Utility/CommonTypeExports.swift | 13 ++++++++++ .../SourceLanguageTests.swift | 2 +- 5 files changed, 44 insertions(+), 5 deletions(-) rename Sources/{SwiftDocCUtilities => CommandLine}/CMakeLists.txt (100%) rename Sources/{SwiftDocC/Model => DocCCommon}/SourceLanguage.swift (95%) create mode 100644 Sources/SwiftDocC/Utility/CommonTypeExports.swift rename Tests/{SwiftDocCTests/Model => DocCCommonTests}/SourceLanguageTests.swift (96%) diff --git a/Package.swift b/Package.swift index 9ad6fa6d7a..3ceb324be8 100644 --- a/Package.swift +++ b/Package.swift @@ -43,6 +43,7 @@ let package = Package( .target( name: "SwiftDocC", dependencies: [ + .target(name: "DocCCommon"), .product(name: "Markdown", package: "swift-markdown"), .product(name: "SymbolKit", package: "swift-docc-symbolkit"), .product(name: "CLMDB", package: "swift-lmdb"), @@ -55,6 +56,7 @@ let package = Package( name: "SwiftDocCTests", dependencies: [ .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .target(name: "SwiftDocCTestUtilities"), ], resources: [ @@ -70,6 +72,7 @@ let package = Package( name: "SwiftDocCUtilities", dependencies: [ .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .product(name: "NIOHTTP1", package: "swift-nio", condition: .when(platforms: [.macOS, .iOS, .linux, .android])), .product(name: "ArgumentParser", package: "swift-argument-parser") ], @@ -81,6 +84,7 @@ let package = Package( dependencies: [ .target(name: "SwiftDocCUtilities"), .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .target(name: "SwiftDocCTestUtilities"), ], resources: [ @@ -95,6 +99,7 @@ let package = Package( name: "SwiftDocCTestUtilities", dependencies: [ .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .product(name: "SymbolKit", package: "swift-docc-symbolkit"), ], swiftSettings: swiftSettings @@ -109,6 +114,25 @@ let package = Package( exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), + + // A few common types and core functionality that's useable by all other targets. + .target( + name: "DocCCommon", + dependencies: [ + // This target shouldn't have any local dependencies so that all other targets can depend on it. + // We can add dependencies on SymbolKit and Markdown here but they're not needed yet. + ], + swiftSettings: [.swiftLanguageMode(.v6)] + ), + + .testTarget( + name: "DocCCommonTests", + dependencies: [ + .target(name: "DocCCommon"), + .target(name: "SwiftDocCTestUtilities"), + ], + swiftSettings: [.swiftLanguageMode(.v6)] + ), // Test app for SwiftDocCUtilities .executableTarget( diff --git a/Sources/SwiftDocCUtilities/CMakeLists.txt b/Sources/CommandLine/CMakeLists.txt similarity index 100% rename from Sources/SwiftDocCUtilities/CMakeLists.txt rename to Sources/CommandLine/CMakeLists.txt diff --git a/Sources/SwiftDocC/Model/SourceLanguage.swift b/Sources/DocCCommon/SourceLanguage.swift similarity index 95% rename from Sources/SwiftDocC/Model/SourceLanguage.swift rename to Sources/DocCCommon/SourceLanguage.swift index 2866213456..4483219757 100644 --- a/Sources/SwiftDocC/Model/SourceLanguage.swift +++ b/Sources/DocCCommon/SourceLanguage.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2023 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 @@ -9,7 +9,7 @@ */ /// A programming language. -public struct SourceLanguage: Hashable, Codable, Comparable { +public struct SourceLanguage: Hashable, Codable, Comparable, Sendable { /// The display name of the programming language. public var name: String /// A globally unique identifier for the language. @@ -132,7 +132,7 @@ public struct SourceLanguage: Hashable, Codable, Comparable { public static let metal = SourceLanguage(name: "Metal", id: "metal") /// The list of programming languages that are known to DocC. - public static var knownLanguages: [SourceLanguage] = [.swift, .objectiveC, .javaScript, .data, .metal] + public static let knownLanguages: [SourceLanguage] = [.swift, .objectiveC, .javaScript, .data, .metal] enum CodingKeys: CodingKey { case name @@ -157,7 +157,9 @@ public struct SourceLanguage: Hashable, Codable, Comparable { try container.encode(self.name, forKey: SourceLanguage.CodingKeys.name) try container.encode(self.id, forKey: SourceLanguage.CodingKeys.id) - try container.encodeIfNotEmpty(self.idAliases, forKey: SourceLanguage.CodingKeys.idAliases) + if !self.idAliases.isEmpty { + try container.encode(self.idAliases, forKey: SourceLanguage.CodingKeys.idAliases) + } try container.encode(self.linkDisambiguationID, forKey: SourceLanguage.CodingKeys.linkDisambiguationID) } diff --git a/Sources/SwiftDocC/Utility/CommonTypeExports.swift b/Sources/SwiftDocC/Utility/CommonTypeExports.swift new file mode 100644 index 0000000000..7194a5c125 --- /dev/null +++ b/Sources/SwiftDocC/Utility/CommonTypeExports.swift @@ -0,0 +1,13 @@ +/* + This source file is part of the Swift.org open source project + + Copyright (c) 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 + See https://swift.org/CONTRIBUTORS.txt for Swift project authors +*/ + +public import DocCCommon + +public typealias SourceLanguage = DocCCommon.SourceLanguage diff --git a/Tests/SwiftDocCTests/Model/SourceLanguageTests.swift b/Tests/DocCCommonTests/SourceLanguageTests.swift similarity index 96% rename from Tests/SwiftDocCTests/Model/SourceLanguageTests.swift rename to Tests/DocCCommonTests/SourceLanguageTests.swift index 734c5c7a1d..d63b6dcaac 100644 --- a/Tests/SwiftDocCTests/Model/SourceLanguageTests.swift +++ b/Tests/DocCCommonTests/SourceLanguageTests.swift @@ -8,7 +8,7 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors */ -@testable import SwiftDocC +import DocCCommon import XCTest class SourceLanguageTests: XCTestCase { From 7b520c35f72071fe8bb100fac0dc99c9c3e48edb Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 17 Nov 2025 12:45:50 -0800 Subject: [PATCH 2/2] 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. --- Sources/CMakeLists.txt | 1 + Sources/DocCCommon/CMakeLists.txt | 11 +++++++ Sources/SwiftDocC/CMakeLists.txt | 30 ++++++++++--------- .../CMakeLists.txt | 0 4 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 Sources/DocCCommon/CMakeLists.txt rename Sources/{CommandLine => SwiftDocCUtilities}/CMakeLists.txt (100%) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 8f8e806655..840812426a 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -7,6 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] +add_subdirectory(DocCCommon) add_subdirectory(SwiftDocC) add_subdirectory(SwiftDocCUtilities) add_subdirectory(docc) diff --git a/Sources/DocCCommon/CMakeLists.txt b/Sources/DocCCommon/CMakeLists.txt new file mode 100644 index 0000000000..a393257167 --- /dev/null +++ b/Sources/DocCCommon/CMakeLists.txt @@ -0,0 +1,11 @@ +#[[ +This source file is part of the Swift open source project + +Copyright © 2014 - 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 +#]] + +add_library(DocCCommon STATIC + SourceLanguage.swift) diff --git a/Sources/SwiftDocC/CMakeLists.txt b/Sources/SwiftDocC/CMakeLists.txt index 6a54c8c802..c5e6ef0e26 100644 --- a/Sources/SwiftDocC/CMakeLists.txt +++ b/Sources/SwiftDocC/CMakeLists.txt @@ -10,13 +10,13 @@ See https://swift.org/LICENSE.txt for license information add_library(SwiftDocC Benchmark/Benchmark.swift Benchmark/BenchmarkResults.swift + Benchmark/Metrics.swift Benchmark/Metrics/Duration.swift Benchmark/Metrics/ExternalTopicsHash.swift Benchmark/Metrics/OutputSize.swift Benchmark/Metrics/PeakMemory.swift Benchmark/Metrics/TopicAnchorHash.swift Benchmark/Metrics/TopicGraphHash.swift - Benchmark/Metrics.swift "Catalog Processing/GeneratedCurationWriter.swift" Checker/Checker.swift Checker/Checkers/AbstractContainsFormattedTextOnly.swift @@ -198,16 +198,16 @@ add_library(SwiftDocC Model/Rendering/RenderContentCompiler.swift Model/Rendering/RenderContentConvertible.swift Model/Rendering/RenderContext.swift + Model/Rendering/RenderNode.Tag.swift + Model/Rendering/RenderNode.swift + Model/Rendering/RenderNodeTranslator.swift + Model/Rendering/RenderNodeVariant.swift Model/Rendering/RenderNode/AnyMetadata.swift Model/Rendering/RenderNode/CodableContentSection.swift Model/Rendering/RenderNode/CodableRenderReference.swift Model/Rendering/RenderNode/CodableRenderSection.swift Model/Rendering/RenderNode/RenderMetadata.swift Model/Rendering/RenderNode/RenderNode+Codable.swift - Model/Rendering/RenderNode.swift - Model/Rendering/RenderNode.Tag.swift - Model/Rendering/RenderNodeTranslator.swift - Model/Rendering/RenderNodeVariant.swift Model/Rendering/RenderReferenceStore.swift Model/Rendering/RenderSection.swift Model/Rendering/RenderSectionTranslator/AttributesSectionTranslator.swift @@ -238,22 +238,22 @@ add_library(SwiftDocC Model/Rendering/Symbol/PossibleValuesRenderSection.swift Model/Rendering/Symbol/PropertiesRenderSection.swift Model/Rendering/Symbol/PropertyListDetailsRenderSection.swift - Model/Rendering/Symbol/RelationshipsRenderSection.swift Model/Rendering/Symbol/RESTBodyRenderSection.swift Model/Rendering/Symbol/RESTEndpointRenderSection.swift Model/Rendering/Symbol/RESTExampleRenderSection.swift Model/Rendering/Symbol/RESTParametersRenderSection.swift Model/Rendering/Symbol/RESTResponseRenderSection.swift + Model/Rendering/Symbol/RelationshipsRenderSection.swift Model/Rendering/Symbol/SampleDownloadSection.swift Model/Rendering/Symbol/TaskGroupRenderSection.swift Model/Rendering/TopicsSectionStyle.swift + "Model/Rendering/Tutorial Article/TutorialArticleSection.swift" Model/Rendering/Tutorial/LineHighlighter.swift Model/Rendering/Tutorial/References/DownloadReference.swift Model/Rendering/Tutorial/References/XcodeRequirementReference.swift Model/Rendering/Tutorial/Sections/IntroRenderSection.swift Model/Rendering/Tutorial/Sections/TutorialAssessmentsRenderSection.swift Model/Rendering/Tutorial/Sections/TutorialSectionsRenderSection.swift - "Model/Rendering/Tutorial Article/TutorialArticleSection.swift" "Model/Rendering/Tutorials Overview/Resources/RenderTile.swift" "Model/Rendering/Tutorials Overview/Sections/CallToActionSection.swift" "Model/Rendering/Tutorials Overview/Sections/ContentAndMediaGroupSection.swift" @@ -299,7 +299,6 @@ add_library(SwiftDocC Model/Semantics/Parameter.swift Model/Semantics/Return.swift Model/Semantics/Throw.swift - Model/SourceLanguage.swift Model/TaskGroup.swift Semantics/Abstracted.swift Semantics/Article/Article.swift @@ -358,11 +357,11 @@ add_library(SwiftDocC Semantics/Options/TopicsVisualStyle.swift Semantics/Redirect.swift Semantics/Redirected.swift + Semantics/ReferenceResolver.swift Semantics/Reference/Links.swift Semantics/Reference/Row.swift Semantics/Reference/Small.swift Semantics/Reference/TabNavigator.swift - Semantics/ReferenceResolver.swift Semantics/Semantic.swift Semantics/SemanticAnalyzer.swift Semantics/Snippets/Snippet.swift @@ -381,6 +380,8 @@ add_library(SwiftDocC Semantics/Technology/Volume/Volume.swift Semantics/Timed.swift Semantics/Titled.swift + Semantics/TutorialArticle/Stack.swift + Semantics/TutorialArticle/TutorialArticle.swift Semantics/Tutorial/Assessments/Assessments.swift "Semantics/Tutorial/Assessments/Multiple Choice/Choice/Choice.swift" "Semantics/Tutorial/Assessments/Multiple Choice/Choice/Justification.swift" @@ -391,8 +392,6 @@ add_library(SwiftDocC Semantics/Tutorial/Tasks/TutorialSection.swift Semantics/Tutorial/Tutorial.swift Semantics/Tutorial/XcodeRequirement.swift - Semantics/TutorialArticle/Stack.swift - Semantics/TutorialArticle/TutorialArticle.swift Semantics/Visitor/SemanticVisitor.swift Semantics/Walker/SemanticWalker.swift Semantics/Walker/Walkers/SemanticTreeDumper.swift @@ -402,6 +401,7 @@ add_library(SwiftDocC Utility/Checksum.swift Utility/Collection+ConcurrentPerform.swift Utility/CollectionChanges.swift + Utility/CommonTypeExports.swift Utility/DataStructures/BidirectionalMap.swift Utility/DataStructures/GroupedSequence.swift Utility/DispatchGroup+Async.swift @@ -440,14 +440,14 @@ add_library(SwiftDocC Utility/Graphs/DirectedGraph+Paths.swift Utility/Graphs/DirectedGraph+Traversal.swift Utility/Graphs/DirectedGraph.swift - Utility/Language/EnglishLanguage.swift - Utility/Language/NativeLanguage.swift - Utility/ListItemUpdatable.swift Utility/LMDB/LMDB+Database.swift Utility/LMDB/LMDB+Environment.swift Utility/LMDB/LMDB+Error.swift Utility/LMDB/LMDB+Transaction.swift Utility/LMDB/LMDB.swift + Utility/Language/EnglishLanguage.swift + Utility/Language/NativeLanguage.swift + Utility/ListItemUpdatable.swift Utility/LogHandle.swift Utility/MarkupExtensions/AnyLink.swift Utility/MarkupExtensions/BlockDirectiveExtensions.swift @@ -463,6 +463,8 @@ add_library(SwiftDocC Utility/Synchronization.swift Utility/ValidatedURL.swift Utility/Version.swift) +target_link_libraries(SwiftDocC PRIVATE + DocCCommon) target_link_libraries(SwiftDocC PUBLIC SwiftMarkdown::Markdown DocC::SymbolKit diff --git a/Sources/CommandLine/CMakeLists.txt b/Sources/SwiftDocCUtilities/CMakeLists.txt similarity index 100% rename from Sources/CommandLine/CMakeLists.txt rename to Sources/SwiftDocCUtilities/CMakeLists.txt