Skip to content

Commit

Permalink
Add experimental flag for skipping synthesized symbols (#28)
Browse files Browse the repository at this point in the history
Adds support for the generation of DocC archives without synthesized
symbols by passing a new, experimental, plugin flag
`--experimental-skip-synthesized-symbols`.

Enabling this flag does not transform or post-process any of the passed
arguments but overrides the default value of
`symbolGraphOptions.includeSynthesized` that is provided to SwiftPM to false.
  • Loading branch information
sofiaromorales authored Mar 13, 2023
1 parent 6a8f81a commit 9b12589
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 7 deletions.
1 change: 1 addition & 0 deletions IntegrationTests/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let package = Package(
.copy("Fixtures/MixedTargets"),
.copy("Fixtures/TargetWithDocCCatalog"),
.copy("Fixtures/PackageWithSnippets"),
.copy("Fixtures/PackageWithConformanceSymbols"),
.copy("Fixtures/LibraryTargetWithExtensionSymbols"),
]
),
Expand Down
49 changes: 49 additions & 0 deletions IntegrationTests/Tests/DocCConvertSynthesizedSymbolsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 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

import XCTest

final class DocCConvertSynthesizedSymbolsTests: ConcurrencyRequiringTestCase {
func testGenerateDocumentationWithSkipSynthesizedSymbolsEnabled() throws {
let result = try swiftPackage(
"generate-documentation", "--experimental-skip-synthesized-symbols",
workingDirectory: try setupTemporaryDirectoryForFixture(named: "PackageWithConformanceSymbols")
)

result.assertExitStatusEquals(0)
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
XCTAssertEqual(
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
[
"documentation/packagewithconformancesymbols.json",
"packagewithconformancesymbols/foo.json"
]
)
}

func testGenerateDocumentationWithSynthesizedSymbols() throws {
let result = try swiftPackage(
"generate-documentation",
workingDirectory: try setupTemporaryDirectoryForFixture(named: "PackageWithConformanceSymbols")
)

result.assertExitStatusEquals(0)
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
XCTAssertEqual(
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
[
"documentation/packagewithconformancesymbols.json",
"packagewithconformancesymbols/foo.json",
"foo/equatable-implementations.json",
"foo/!=(_:_:).json"
]
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// swift-tools-version: 5.6
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 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

import Foundation
import PackageDescription

let package = Package(
name: "PackageWithConformanceSymbols",
targets: [
.target(name: "PackageWithConformanceSymbols")
]
)

// We only expect 'swift-docc-plugin' to be a sibling when this package
// is running as part of a test.
//
// This allows the package to compile outside of tests for easier
// test development.
if FileManager.default.fileExists(atPath: "../swift-docc-plugin") {
package.dependencies += [
.package(path: "../swift-docc-plugin"),
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 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 struct Foo: Hashable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ extension PackageManager {
#else
print("warning: detected '--include-extended-types' option, which is incompatible with your swift version (required: 5.8)")
#endif
case .skipSynthesizedSymbols:
symbolGraphOptions.includeSynthesized = false
default:
fatalError("error: unknown PluginFlag (\(customSymbolGraphOption.parsedValues.joined(separator: ", "))) detected in symbol graph generation - please create an issue at https://github.com/apple/swift-docc-plugin")
}
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftDocCPluginUtilities/HelpInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum HelpInformation {

var supportedPluginFlags = [
PluginFlag.disableIndex,
PluginFlag.skipSynthesizedSymbols
]

// stops 'not mutated' warning for Swift 5.7 and lower
Expand Down
6 changes: 4 additions & 2 deletions Sources/SwiftDocCPluginUtilities/ParsedArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ public struct ParsedArguments {

private static let argumentsTransformers: [ArgumentsTransforming] = [
PluginFlag.disableIndex,
PluginFlag.extendedTypes
PluginFlag.extendedTypes,
PluginFlag.skipSynthesizedSymbols
]
}

Expand All @@ -201,7 +202,8 @@ private extension ParsedArguments {
switch self {
case .dumpSymbolGraph:
return [
PluginFlag.extendedTypes
PluginFlag.extendedTypes,
PluginFlag.skipSynthesizedSymbols
]
case .docc:
return []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 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

extension PluginFlag {
/// Exclude synthesized symbols from the generated documentation.
///
/// `--experimental-skip-synthesized-symbols` produces a DocC archive without compiler synthesized symbols.
static let skipSynthesizedSymbols = PluginFlag(
parsedValues: [
"--experimental-skip-synthesized-symbols"
],
abstract: "Exclude synthesized symbols from the generated documentation",
description: """
Experimental feature that produces a DocC archive without compiler synthesized symbols.
""",
argumentTransformation: { $0 }
)

}
10 changes: 8 additions & 2 deletions Tests/SwiftDocCPluginUtilitiesTests/HelpInformationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ final class HelpInformationTests: XCTestCase {
--product <product> Generate documentation for the specified product.
--disable-indexing, --no-indexing
Disable indexing for the produced DocC archive.
Produces a DocC archive that is best-suited for hosting online but incompatible with Xcode.\(includeExtendedTypesSection)
Produces a DocC archive that is best-suited for hosting online but incompatible with Xcode.
--experimental-skip-synthesized-symbols
Exclude synthesized symbols from the generated documentation
Experimental feature that produces a DocC archive without compiler synthesized symbols.\(includeExtendedTypesSection)
DOCC OPTIONS:
--platform <platform> Set the current release version of a platform.
Expand Down Expand Up @@ -128,7 +131,10 @@ final class HelpInformationTests: XCTestCase {
--product <product> Preview documentation for the specified product.
--disable-indexing, --no-indexing
Disable indexing for the produced DocC archive.
Produces a DocC archive that is best-suited for hosting online but incompatible with Xcode.\(includeExtendedTypesSection)
Produces a DocC archive that is best-suited for hosting online but incompatible with Xcode.
--experimental-skip-synthesized-symbols
Exclude synthesized symbols from the generated documentation
Experimental feature that produces a DocC archive without compiler synthesized symbols.\(includeExtendedTypesSection)
DOCC OPTIONS:
--platform <platform> Set the current release version of a platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ final class ParsedArgumentsTests: XCTestCase {
}

func testDocCArgumentsWithDumpSymbolGraphArguments() {
let dumpSymbolGraphArguments = ParsedArguments(["--include-extended-types"])
let dumpSymbolGraphArguments = ParsedArguments(["--include-extended-types", "--experimental-skip-synthesized-symbols"])

let doccArguments = dumpSymbolGraphArguments.doccArguments(
action: .convert,
Expand All @@ -456,12 +456,13 @@ final class ParsedArgumentsTests: XCTestCase {
)

XCTAssertFalse(doccArguments.contains("--include-extended-types"))
XCTAssertFalse(doccArguments.contains("--experimental-skip-synthesized-symbols"))
}

func testDumpSymbolGraphArguments() {
let dumpSymbolGraphArguments = ParsedArguments(["--include-extended-types"])
let dumpSymbolGraphArguments = ParsedArguments(["--include-extended-types", "--experimental-skip-synthesized-symbols"])

XCTAssertEqual(dumpSymbolGraphArguments.symbolGraphArguments, [.extendedTypes])
XCTAssertEqual(dumpSymbolGraphArguments.symbolGraphArguments, [.extendedTypes, .skipSynthesizedSymbols])
}

func testDumpSymbolGraphArgumentsWithDocCArguments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,34 @@ final class PluginFlagTests: XCTestCase {
]
)
}

func testEquatableConformance() {
let examplePluginFlag1 = PluginFlag(
parsedValues: ["--example1", "--other-example1"],
abstract: "",
description: "",
argumentTransformation: { $0 }
)
let examplePluginFlag2 = PluginFlag(
parsedValues: ["--example2", "--other-example2"],
abstract: "",
description: "",
argumentTransformation: { $0 }
)
let examplePluginFlag3 = PluginFlag(
parsedValues: ["--example1", "--other-example1"],
abstract: "abstract",
description: "description",
argumentTransformation: { $0 }
)
let examplePluginFlag4 = PluginFlag(
parsedValues: ["--example"],
abstract: "",
description: "",
argumentTransformation: { $0 }
)
XCTAssertNotEqual(examplePluginFlag1, examplePluginFlag2)
XCTAssertNotEqual(examplePluginFlag1, examplePluginFlag4)
XCTAssertEqual(examplePluginFlag1, examplePluginFlag3)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 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

import Foundation
@testable import SwiftDocCPluginUtilities
import XCTest

final class SkipSynthesizedSymbolsFlagTests: XCTestCase {
func testNotTransformExistingFlagsWhenPresent() {
XCTAssertEqual(
PluginFlag.skipSynthesizedSymbols.transform(
["--index", "--other-flag"]
),
["--index", "--other-flag"]
)
}
}

0 comments on commit 9b12589

Please sign in to comment.