-
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.
Fix a bug where targets with multiple dependencies was only passed on…
…e dependency (#98) * Refine command line argument types to define flag/option specific names This means that flag/option specific API can leverage types instead of including "flag" or "option" in the API's name. This also means that a named option requires a value to create an argument. Co-authored-by: Sofía Rodríguez <[email protected]> * Support defining an option that supports an array of values. Also, define `--dependency` as an array-of-values option. Co-authored-by: Sofía Rodríguez <[email protected]> * Fix a logic bug where an alternate argument spellings with common prefixes would sometimes not extract a value. * Move the inverse names configuration into CommandLineArgument.Flag * Add integration test that verifies that targets are passed all their dependencies * Use the CommandLineArguments type to construct the merge arguments * Print the 'docc merge' call when the `--verbose` flag is passed * Fix an unrelated code warning in Swift 5.7 * Fix an unrelated code warning and avoid undefined behavior in snippet-extract * Correctly document updated parameters Co-authored-by: Sofía Rodríguez <[email protected]> * Fix other unrelated documentation warnings --------- Co-authored-by: Sofía Rodríguez <[email protected]>
- Loading branch information
1 parent
300ee6c
commit 85e4bb4
Showing
18 changed files
with
571 additions
and
150 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
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,99 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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 CombinedDocumentationTests: ConcurrencyRequiringTestCase { | ||
func testCombinedDocumentation() throws { | ||
#if compiler(>=6.0) | ||
let result = try swiftPackage( | ||
"generate-documentation", | ||
"--enable-experimental-combined-documentation", | ||
"--verbose", // Necessary to see the 'docc convert' calls in the log and verify their parameters. | ||
workingDirectory: try setupTemporaryDirectoryForFixture(named: "TargetsWithDependencies") | ||
) | ||
|
||
result.assertExitStatusEquals(0) | ||
let outputArchives = result.referencedDocCArchives | ||
XCTAssertEqual(outputArchives.count, 1) | ||
XCTAssertEqual(outputArchives.map(\.lastPathComponent), [ | ||
"TargetsWithDependencies.doccarchive", | ||
]) | ||
|
||
// Verify that the combined archive contains all target's documentation | ||
|
||
let combinedArchiveURL = try XCTUnwrap(outputArchives.first) | ||
let combinedDataDirectoryContents = try filesIn(.dataSubdirectory, of: combinedArchiveURL) | ||
.map(\.relativePath) | ||
.sorted() | ||
|
||
XCTAssertEqual(combinedDataDirectoryContents, [ | ||
"documentation.json", | ||
"documentation/innerfirst.json", | ||
"documentation/innerfirst/somethingpublic.json", | ||
"documentation/innersecond.json", | ||
"documentation/innersecond/somethingpublic.json", | ||
"documentation/nestedinner.json", | ||
"documentation/nestedinner/somethingpublic.json", | ||
"documentation/outer.json", | ||
"documentation/outer/somethingpublic.json", | ||
]) | ||
|
||
// Verify that each 'docc convert' call was passed the expected dependencies | ||
|
||
let doccConvertCalls = result.standardOutput | ||
.components(separatedBy: .newlines) | ||
.filter { line in | ||
line.hasPrefix("docc invocation: '") && line.utf8.contains("docc convert ".utf8) | ||
}.map { line in | ||
line.trimmingCharacters(in: CharacterSet(charactersIn: "'")) | ||
.components(separatedBy: .whitespaces) | ||
.drop(while: { $0 != "convert" }) | ||
} | ||
|
||
XCTAssertEqual(doccConvertCalls.count, 4) | ||
|
||
func extractDependencyArchives(targetName: String, file: StaticString = #filePath, line: UInt = #line) throws -> [String] { | ||
let arguments = try XCTUnwrap( | ||
doccConvertCalls.first(where: { $0.contains(["--fallback-display-name", targetName]) }), | ||
file: file, line: line | ||
) | ||
var dependencyPaths: [URL] = [] | ||
|
||
var remaining = arguments[...] | ||
while !remaining.isEmpty { | ||
remaining = remaining.drop(while: { $0 != "--dependency" }).dropFirst(/* the '--dependency' element */) | ||
if let path = remaining.popFirst() { | ||
dependencyPaths.append(URL(fileURLWithPath: path)) | ||
} | ||
} | ||
|
||
return dependencyPaths.map { $0.lastPathComponent }.sorted() | ||
} | ||
// Outer | ||
// ├─ InnerFirst | ||
// ╰─ InnerSecond | ||
// ╰─ NestedInner | ||
|
||
XCTAssertEqual(try extractDependencyArchives(targetName: "Outer"), [ | ||
"InnerFirst.doccarchive", | ||
"InnerSecond.doccarchive", | ||
], "The outer target has depends on both inner targets") | ||
|
||
XCTAssertEqual(try extractDependencyArchives(targetName: "InnerFirst"), [], "The first inner target has no dependencies") | ||
|
||
XCTAssertEqual(try extractDependencyArchives(targetName: "InnerSecond"), [ | ||
"NestedInner.doccarchive", | ||
], "The second inner target has depends on the nested inner target") | ||
|
||
XCTAssertEqual(try extractDependencyArchives(targetName: "NestedInner"), [], "The nested inner target has no dependencies") | ||
#else | ||
XCTSkip("This test requires a Swift-DocC version that support the link-dependencies feature") | ||
#endif | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
IntegrationTests/Tests/Fixtures/TargetsWithDependencies/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,42 @@ | ||
// swift-tools-version: 5.7 | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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: "TargetsWithDependencies", | ||
targets: [ | ||
// Outer | ||
// ├─ InnerFirst | ||
// ╰─ InnerSecond | ||
// ╰─ NestedInner | ||
.target(name: "Outer", dependencies: [ | ||
"InnerFirst", | ||
"InnerSecond", | ||
]), | ||
.target(name: "InnerFirst"), | ||
.target(name: "InnerSecond", dependencies: [ | ||
"NestedInner" | ||
]), | ||
.target(name: "NestedInner"), | ||
] | ||
) | ||
|
||
// 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"), | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
IntegrationTests/Tests/Fixtures/TargetsWithDependencies/Sources/InnerFirst/SomeFile.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,13 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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 | ||
|
||
/// This is a public struct and should be included in the documentation for this library. | ||
public struct SomethingPublic {} | ||
|
||
/// This is an internal struct and should not be included in the documentation for this library. | ||
struct SomethingInternal {} |
13 changes: 13 additions & 0 deletions
13
IntegrationTests/Tests/Fixtures/TargetsWithDependencies/Sources/InnerSecond/SomeFile.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,13 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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 | ||
|
||
/// This is a public struct and should be included in the documentation for this library. | ||
public struct SomethingPublic {} | ||
|
||
/// This is an internal struct and should not be included in the documentation for this library. | ||
struct SomethingInternal {} |
13 changes: 13 additions & 0 deletions
13
IntegrationTests/Tests/Fixtures/TargetsWithDependencies/Sources/NestedInner/SomeFile.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,13 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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 | ||
|
||
/// This is a public struct and should be included in the documentation for this library. | ||
public struct SomethingPublic {} | ||
|
||
/// This is an internal struct and should not be included in the documentation for this library. | ||
struct SomethingInternal {} |
13 changes: 13 additions & 0 deletions
13
IntegrationTests/Tests/Fixtures/TargetsWithDependencies/Sources/Outer/SomeFile.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,13 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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 | ||
|
||
/// This is a public struct and should be included in the documentation for this library. | ||
public struct SomethingPublic {} | ||
|
||
/// This is an internal struct and should not be included in the documentation for this library. | ||
struct SomethingInternal {} |
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
Oops, something went wrong.