Skip to content

Commit dd50d0d

Browse files
authored
Add include inherited docs option to symbol graph generation (#9132)
* Use this option from the dump symbol graph command to set the swift build build setting * Add this option to the symbol graph generation option from command plugins * Update the test conditions to better reflect the required toolchain version
1 parent 14c3d61 commit dd50d0d

File tree

9 files changed

+43
-6
lines changed

9 files changed

+43
-6
lines changed

Sources/Commands/PackageCommands/DumpCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ struct DumpSymbolGraph: AsyncSwiftCommand {
6060
BuildOutput.SymbolGraphOptions(
6161
prettyPrint: prettyPrint,
6262
minimumAccessLevel: .accessLevel(minimumAccessLevel),
63+
includeInheritedDocs: !skipInheritedDocs,
6364
includeSynthesized: !skipSynthesizedMembers,
6465
includeSPI: includeSPISymbols,
6566
emitExtensionBlocks: extensionBlockSymbolBehavior != .omitExtensionBlockSymbols,
66-
// TODO skip inherited docs
6767
)
6868
), .buildPlan])
6969

Sources/Commands/Utilities/PluginDelegate.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ final class PluginDelegate: PluginInvocationDelegate {
443443
case .open:
444444
symbolGraphExtractor.minimumAccessLevel = .open
445445
}
446-
symbolGraphExtractor.skipInheritedDocs = true
446+
symbolGraphExtractor.skipInheritedDocs = !options.includeInheritedDocs
447447
symbolGraphExtractor.includeSPISymbols = options.includeSPI
448448
symbolGraphExtractor.emitExtensionBlockSymbols = options.emitExtensionBlocks
449449

@@ -489,6 +489,7 @@ extension BuildOutput {
489489
static func symbolGraph(_ options: PluginInvocationSymbolGraphOptions) -> BuildOutput {
490490
return .symbolGraph(SymbolGraphOptions(
491491
minimumAccessLevel: .accessLevel(options.minimumAccessLevel),
492+
includeInheritedDocs: options.includeInheritedDocs,
492493
includeSynthesized: options.includeSynthesized,
493494
includeSPI: options.includeSPI,
494495
emitExtensionBlocks: options.emitExtensionBlocks
@@ -497,7 +498,7 @@ extension BuildOutput {
497498
}
498499

499500
fileprivate extension BuildOutput.SymbolGraphAccessLevel {
500-
fileprivate static func accessLevel(_ accessLevel: PluginInvocationSymbolGraphOptions.AccessLevel) -> BuildOutput.SymbolGraphAccessLevel {
501+
static func accessLevel(_ accessLevel: PluginInvocationSymbolGraphOptions.AccessLevel) -> BuildOutput.SymbolGraphAccessLevel {
501502
return switch accessLevel {
502503
case .private:
503504
.private

Sources/PackagePlugin/PackageManagerProxy.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ public struct PackageManager {
293293
case `private`, `fileprivate`, `internal`, `package`, `public`, open
294294
}
295295

296+
/// A Boolean value that indicates whether to include inherited docs from class or protocol members.
297+
public var includeInheritedDocs: Bool
298+
296299
/// A Boolean value that indicates whether to include synthesized members.
297300
public var includeSynthesized: Bool
298301

@@ -305,16 +308,19 @@ public struct PackageManager {
305308
/// Creates a new set of options for returning the symbol graph for a target.
306309
/// - Parameters:
307310
/// - minimumAccessLevel: The minimum access level of symbols to return.
311+
/// - includeInheritedDocs: A Boolean value that indicates whether to include inheirted docs from protocol or class members.
308312
/// - includeSynthesized: A Boolean value that indicates whether to include synthesized members.
309313
/// - includeSPI: A Boolean value that indicates whether to include symbols marked as SPI.
310314
/// - emitExtensionBlocks: A Boolean value that indicates whether to emit symbols for extensions to external types.
311315
public init(
312316
minimumAccessLevel: AccessLevel = .public,
317+
includeInheritedDocs: Bool = true,
313318
includeSynthesized: Bool = false,
314319
includeSPI: Bool = false,
315320
emitExtensionBlocks: Bool = false
316321
) {
317322
self.minimumAccessLevel = minimumAccessLevel
323+
self.includeInheritedDocs = includeInheritedDocs
318324
self.includeSynthesized = includeSynthesized
319325
self.includeSPI = includeSPI
320326
self.emitExtensionBlocks = emitExtensionBlocks
@@ -507,6 +513,7 @@ extension PackageManager.TestResult.TestTarget.TestCase.Test.Result {
507513
extension PluginToHostMessage.SymbolGraphOptions {
508514
fileprivate init(_ options: PackageManager.SymbolGraphOptions) {
509515
self.minimumAccessLevel = .init(options.minimumAccessLevel)
516+
self.includeInheritedDocs = options.includeInheritedDocs
510517
self.includeSynthesized = options.includeSynthesized
511518
self.includeSPI = options.includeSPI
512519
self.emitExtensionBlocks = options.emitExtensionBlocks

Sources/PackagePlugin/PluginMessages.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ enum PluginToHostMessage: Codable {
398398
enum AccessLevel: String, Codable {
399399
case `private`, `fileprivate`, `internal`, `package`, `public`, `open`
400400
}
401+
var includeInheritedDocs: Bool? = true
401402
var includeSynthesized: Bool
402403
var includeSPI: Bool
403404
var emitExtensionBlocks: Bool

Sources/SPMBuildCore/BuildSystem/BuildSystem.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,22 @@ public enum BuildOutput: Equatable {
4545
public struct SymbolGraphOptions: Equatable {
4646
public var prettyPrint: Bool
4747
public var minimumAccessLevel: SymbolGraphAccessLevel
48+
public var includeInheritedDocs: Bool
4849
public var includeSynthesized: Bool
4950
public var includeSPI: Bool
5051
public var emitExtensionBlocks: Bool
5152

5253
public init(
5354
prettyPrint: Bool = false,
5455
minimumAccessLevel: SymbolGraphAccessLevel,
56+
includeInheritedDocs: Bool,
5557
includeSynthesized: Bool,
5658
includeSPI: Bool,
5759
emitExtensionBlocks: Bool
5860
) {
5961
self.prettyPrint = prettyPrint
6062
self.minimumAccessLevel = minimumAccessLevel
63+
self.includeInheritedDocs = includeInheritedDocs
6164
self.includeSynthesized = includeSynthesized
6265
self.includeSPI = includeSPI
6366
self.emitExtensionBlocks = emitExtensionBlocks

Sources/SPMBuildCore/Plugins/PluginInvocation.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ public struct PluginInvocationSymbolGraphOptions {
954954
public enum AccessLevel: String {
955955
case `private`, `fileprivate`, `internal`, `package`, `public`, `open`
956956
}
957+
public var includeInheritedDocs: Bool
957958
public var includeSynthesized: Bool
958959
public var includeSPI: Bool
959960
public var emitExtensionBlocks: Bool
@@ -1219,6 +1220,7 @@ fileprivate extension HostToPluginMessage.TestResult.TestTarget.TestCase.Test.Re
12191220
fileprivate extension PluginInvocationSymbolGraphOptions {
12201221
init(_ options: PluginToHostMessage.SymbolGraphOptions) {
12211222
self.minimumAccessLevel = .init(options.minimumAccessLevel)
1223+
self.includeInheritedDocs = options.includeInheritedDocs ?? true
12221224
self.includeSynthesized = options.includeSynthesized
12231225
self.includeSPI = options.includeSPI
12241226
self.emitExtensionBlocks = options.emitExtensionBlocks

Sources/SwiftBuildSupport/SwiftBuildSystem.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,10 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
905905
settings["DOCC_EXTRACT_EXTENSION_SYMBOLS"] = "YES"
906906
}
907907

908+
if !symbolGraphOptions.includeInheritedDocs {
909+
settings["DOCC_SKIP_INHERITED_DOCS"] = "YES"
910+
}
911+
908912
if !symbolGraphOptions.includeSynthesized {
909913
settings["DOCC_SKIP_SYNTHESIZED_MEMBERS"] = "YES"
910914
}

Tests/CommandsTests/PackageCommandTests.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6025,8 +6025,13 @@ struct PackageCommandTests {
60256025
? context.package.targets
60266026
: try context.package.targets(named: targetNames)
60276027
for target in targets {
6028+
#if compiler(>=6.3)
6029+
let symbolGraph = try packageManager.getSymbolGraph(for: target,
6030+
options: .init(minimumAccessLevel: .public, includeInheritedDocs: false))
6031+
#else
60286032
let symbolGraph = try packageManager.getSymbolGraph(for: target,
60296033
options: .init(minimumAccessLevel: .public))
6034+
#endif
60306035
print("\\(target.name): \\(symbolGraph.directoryPath)")
60316036
}
60326037
}
@@ -6083,8 +6088,15 @@ struct PackageCommandTests {
60836088
}
60846089
}
60856090
} when: {
6086-
(ProcessInfo.hostOperatingSystem == .windows && data.buildSystem == .swiftbuild)
6087-
|| !CiEnvironment.runningInSmokeTestPipeline
6091+
let shouldSkip: Bool = (ProcessInfo.hostOperatingSystem == .windows && data.buildSystem == .swiftbuild)
6092+
|| !CiEnvironment.runningInSmokeTestPipeline
6093+
6094+
#if compiler(>=6.3)
6095+
return shouldSkip
6096+
#else
6097+
// Symbol graph generation options are only available in 6.3 toolchain or later for swift build
6098+
return shouldSkip || data.buildSystem == .swiftbuild
6099+
#endif
60886100
}
60896101
}
60906102

Tests/FunctionalTests/TraitTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,14 @@ struct TraitTests {
591591
}
592592
}
593593
} when: {
594-
!CiEnvironment.runningInSmokeTestPipeline
594+
let shouldSkip = !CiEnvironment.runningInSmokeTestPipeline
595+
596+
#if compiler(>=6.3)
597+
return shouldSkip
598+
#else
599+
// Symbol graph generation options are only available in 6.3 toolchain or later for swift build
600+
return shouldSkip || buildSystem == .swiftbuild
601+
#endif
595602
}
596603
}
597604

0 commit comments

Comments
 (0)