Skip to content

Commit 8018224

Browse files
authored
Merge pull request #2096 from ahoppen/ahoppen/verify-documentation
Add subcommand to swift-syntax-dev-utils to verify that documentation builds without errors or warnings
2 parents 44f6968 + 31be298 commit 8018224

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public let PATTERN_NODES: [Node] = [
212212
213213
### Examples
214214
215-
``WildcardPattern`` matches and ignores any value.
215+
``WildcardPatternSyntax`` matches and ignores any value.
216216
For example `_` in the example:
217217
218218
```swift

Sources/SwiftParser/ParseSourceFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extension Parser {
117117
/// Parse the source code in the given buffer as Swift source file with support
118118
/// for incremental parsing.
119119
///
120-
/// See doc comments in ``Parser/parseIncrementally(source:parseTransition:)-4kn2k``
120+
/// See doc comments in ``Parser/parseIncrementally(source:parseTransition:)-dj0z``
121121
public static func parseIncrementally(
122122
source: UnsafeBufferPointer<UInt8>,
123123
maximumNestingLevel: Int? = nil,

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4238,7 +4238,7 @@ public struct WhileStmtSyntax: StmtSyntaxProtocol, SyntaxHashable, _LeafStmtSynt
42384238
///
42394239
/// ### Examples
42404240
///
4241-
/// ``WildcardPattern`` matches and ignores any value.
4241+
/// ``WildcardPatternSyntax`` matches and ignores any value.
42424242
/// For example `_` in the example:
42434243
///
42444244
/// ```swift

SwiftSyntaxDevUtils/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PackageDescription
66
let package = Package(
77
name: "swift-syntax-dev-utils",
88
platforms: [
9-
.macOS(.v10_15)
9+
.macOS(.v13)
1010
],
1111
products: [
1212
.executable(name: "swift-syntax-dev-utils", targets: ["swift-syntax-dev-utils"])

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/SwiftSyntaxDevUtils.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct SwiftSyntaxDevUtils: ParsableCommand {
2929
Format.self,
3030
GenerateSourceCode.self,
3131
Test.self,
32+
VerifyDocumentation.self,
3233
VerifySourceCode.self,
3334
]
3435
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import ArgumentParser
14+
import Foundation
15+
import RegexBuilder
16+
17+
struct VerifyDocumentation: ParsableCommand {
18+
static var configuration: CommandConfiguration {
19+
CommandConfiguration(
20+
abstract: "Verify that the docc documentation builds without warnings or errors."
21+
)
22+
}
23+
24+
@Flag(help: "Enable verbose logging.")
25+
var verbose: Bool = false
26+
27+
func targetsInSwiftPackageIndexManifest() throws -> [String] {
28+
let extractTargetRegex = Regex {
29+
#/^ - /#
30+
Capture(ZeroOrMore(.word))
31+
#/$/#
32+
}
33+
let spiYmlFile = Paths.packageDir.appendingPathComponent(".spi.yml")
34+
let spiYmlFileContents = try String(contentsOf: spiYmlFile)
35+
return
36+
spiYmlFileContents
37+
.components(separatedBy: "\n")
38+
.filter({ !$0.matches(of: extractTargetRegex).isEmpty })
39+
.map { $0.replacing(extractTargetRegex) { $0.1 } }
40+
.sorted()
41+
}
42+
43+
func run() throws {
44+
for target in try targetsInSwiftPackageIndexManifest() {
45+
try buildDocumentation(product: target)
46+
}
47+
}
48+
49+
func buildDocumentation(product: String) throws {
50+
guard let xcodebuildExec = try? Paths.xcodebuildExec else {
51+
return
52+
}
53+
logSection("Building documentation for \(product)")
54+
try ProcessRunner(
55+
executableURL: xcodebuildExec,
56+
arguments: [
57+
"docbuild",
58+
"-workspace",
59+
Paths.packageDir.path,
60+
"-scheme",
61+
product,
62+
"-destination", "platform=macOS",
63+
"OTHER_DOCC_FLAGS='--warnings-as-errors'",
64+
]
65+
).run(captureStdout: false, captureStderr: false, verbose: self.verbose)
66+
}
67+
}

0 commit comments

Comments
 (0)