-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental flag for skipping synthesized symbols (#28)
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
1 parent
6a8f81a
commit 9b12589
Showing
12 changed files
with
185 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
IntegrationTests/Tests/DocCConvertSynthesizedSymbolsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
IntegrationTests/Tests/Fixtures/PackageWithConformanceSymbols/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
...ixtures/PackageWithConformanceSymbols/Sources/PackageWithConformanceSymbols/FooTest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Sources/SwiftDocCPluginUtilities/PluginFlags/SkipSynthesizedSymbolsFlag.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Tests/SwiftDocCPluginUtilitiesTests/PluginFlags/SkipSynthesizedSymbolsFlagTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
) | ||
} | ||
} |