Skip to content

Commit 1dbfd9e

Browse files
committed
Add DocC to SwiftSyntax
1 parent e657dc0 commit 1dbfd9e

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

Package.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if let parserLibSearchPath = ProcessInfo.processInfo.environment["SWIFT_SYNTAX_P
3737

3838
let package = Package(
3939
name: "SwiftSyntax",
40+
defaultLocalization: "en",
4041
products: [
4142
.library(name: "SwiftSyntax", type: .static, targets: ["SwiftSyntax"]),
4243
.library(name: "SwiftSyntaxParser", type: .static, targets: ["SwiftSyntaxParser"]),
@@ -143,3 +144,10 @@ let package = Package(
143144
),
144145
]
145146
)
147+
148+
// SwiftPM command plugins are only supported by Swift version 5.6 and later.
149+
#if swift(>=5.6)
150+
package.dependencies += [
151+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
152+
]
153+
#endif
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# ``SwiftSyntax``
2+
3+
SwiftSyntax is a set of Swift bindings for the
4+
[libSyntax](https://github.com/apple/swift/tree/main/lib/Syntax) library. It
5+
allows Swift tools to parse, inspect, generate, and transform Swift source
6+
code.
7+
8+
Its API is designed for performance-critical applications. It uses value types almost exclusively and aims to avoid existential conversions where possible.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2022 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 Swift project authors
10+
#
11+
# Updates the GitHub Pages documentation site thats published from the 'docs'
12+
# subdirectory in the 'gh-pages' branch of this repository.
13+
#
14+
# This script should be run by someone with commit access to the 'gh-pages' branch
15+
# at a regular frequency so that the documentation content on the GitHub Pages site
16+
# is up-to-date with the content in this repo.
17+
#
18+
19+
set -eu
20+
21+
# A `realpath` alternative using the default C implementation.
22+
filepath() {
23+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
24+
}
25+
26+
SWIFT_SYNTAX_ROOT="$(dirname $(dirname $(filepath $0)))"
27+
28+
SWIFT_SYNTAX_BUILD_DIR="$SWIFT_SYNTAX_ROOT"/.build/swift-syntax-gh-pages-build
29+
SWIFT_SYNTAX_BUILDER_OUTPUT_DIR="$SWIFT_SYNTAX_BUILD_DIR"/swift-syntax-builder-docs
30+
31+
mkdir -p "$SWIFT_SYNTAX_BUILDER_OUTPUT_DIR"
32+
33+
# Set current directory to the repository root
34+
cd "$SWIFT_SYNTAX_ROOT"
35+
36+
# Use git worktree to checkout the gh-pages branch of this repository in a gh-pages sub-directory
37+
git fetch
38+
git worktree add --checkout gh-pages origin/gh-pages
39+
40+
# Pretty print DocC JSON output so that it can be consistently diffed between commits
41+
export DOCC_JSON_PRETTYPRINT="YES"
42+
43+
# Generate documentation for the 'SwiftSyntax' target and output it
44+
# to the /docs subdirectory in the gh-pages worktree directory.
45+
swift package \
46+
--allow-writing-to-directory "$SWIFT_SYNTAX_ROOT/gh-pages/docs" \
47+
generate-documentation \
48+
--target SwiftSyntax \
49+
--disable-indexing \
50+
--transform-for-static-hosting \
51+
--hosting-base-path swift-syntax \
52+
--output-path "$SWIFT_SYNTAX_ROOT/gh-pages/docs"
53+
54+
# Generate documentation for the 'SwiftSyntaxBuilder' target and output it
55+
# to a temporary output directory in the .build directory.
56+
swift package \
57+
--allow-writing-to-directory "$SWIFT_SYNTAX_BUILD_DIR" \
58+
generate-documentation \
59+
--target SwiftSyntaxBuilder \
60+
--disable-indexing \
61+
--transform-for-static-hosting \
62+
--hosting-base-path swift-syntax \
63+
--output-path "$SWIFT_SYNTAX_BUILDER_OUTPUT_DIR"
64+
65+
# Merge the SwiftSyntaxBuilder docs into the primary SwiftSyntax docs
66+
cp -R "$SWIFT_SYNTAX_BUILDER_OUTPUT_DIR"/* "$SWIFT_SYNTAX_ROOT/gh-pages/docs/"
67+
68+
# Save the current commit we've just built documentation from in a variable
69+
CURRENT_COMMIT_HASH=`git rev-parse --short HEAD`
70+
71+
# Commit and push our changes to the gh-pages branch
72+
cd gh-pages
73+
git add docs
74+
75+
if [ -n "$(git status --porcelain)" ]; then
76+
echo "Documentation changes found. Commiting the changes to the 'gh-pages' branch and pushing to origin."
77+
git commit -m "Update GitHub Pages documentation site to $CURRENT_COMMIT_HASH"
78+
git push origin HEAD:gh-pages
79+
else
80+
# No changes found, nothing to commit.
81+
echo "No documentation changes found."
82+
fi
83+
84+
# Delete the git worktree we created
85+
cd ..
86+
git worktree remove gh-pages

0 commit comments

Comments
 (0)