File: generate-docs.sh

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (94 lines) | stat: -rwxr-xr-x 3,234 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
#===----------------------------------------------------------------------
#
# This source file is part of the Swift Collections open source project
#
# Copyright (c) 2022 - 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
#
#===----------------------------------------------------------------------

set -eu

shopt -s nullglob
cd "$(dirname $0)/.."

if [ "$(uname)" = "Darwin" ]; then
    swift="xcrun swift"
    export DOCC_HTML_DIR="$(dirname $(xcrun --find docc))/../share/docc/render"
else
    swift="swift"
fi

build_dir="$(mktemp -d "/tmp/$(basename $0).XXXXX")"
echo "Build directory: $build_dir"

output_dir_base=/tmp/foo

rm -rf "$output_dir_base"

components="\
    BitCollections DequeModule HeapModule OrderedCollections \
    HashTreeCollections"

if [ $# -eq 0 ]; then
    targets="Collections $components"
else
    targets="$@"
fi

for target in $targets; do
    if [ "$target" = "Collections" ]; then
        # Update extensions under Collections.docc
        rm -rf Sources/Collections/Collections.docc/Extensions/*.md
        for component in $components; do
            for file in Sources/"$component"/"$component".docc/Extensions/*.md; do
                output="Sources/Collections/Collections.docc/Extensions/$(basename $file)"
                blurb="<!-- DO NOT EDIT THIS FILE; IT'S AUTOMATICALLY GENERATED -->"
                sed 's?^# ``[^/]*/\(.*\)``?# ``Collections/\1``\n\n'"$blurb"'\n?' "$file" > "$output"
            done
        done
    fi

    mkdir -p "$build_dir/$target/build"
    mkdir -p "$build_dir/$target/symbol-graphs"
    mkdir -p "$build_dir/$target/docc"
    $swift build --target "$target" \
           --build-path "$build_dir/$target/build" \
           -Xswiftc -emit-symbol-graph \
           -Xswiftc -emit-symbol-graph-dir \
           -Xswiftc "$build_dir/$target/symbol-graphs"

    # Prevent DocC from getting confused by too much data :-/
    cp \
        "$build_dir/$target/symbol-graphs/$target.symbols.json" \
        "$build_dir/$target/docc"
    extrafile="$build_dir/$target/symbol-graphs/${target}@Swift.symbols.json"
    if [ -r "$extrafile" ]; then
        cp "$extrafile" "$build_dir/$target/docc"
    fi

    mkdir -p "$output_dir_base/$target"
    xcrun docc convert \
          --analyze \
          --fallback-display-name "$target" \
          --fallback-bundle-identifier "org.swift.swift-collections.$target" \
          --fallback-bundle-version 1.1.0 \
          --default-code-listing-language swift \
          --additional-symbol-graph-dir "$build_dir/$target/docc" \
          --transform-for-static-hosting \
          --output-path "$output_dir_base/$target" \
          --hosting-base-path "/swift-collections/$target" \
          "Sources/$target/$target.docc"
done

if [ $# -eq 1 ]; then
    module="$1"
    xcrun docc preview "Sources/$module/$module.docc" \
          --fallback-display-name "Swift Collections" \
          --fallback-bundle-identifier "org.swift.swift-collections.$module" \
          --fallback-bundle-version 1.1.0 \
          --additional-symbol-graph-dir "$build_dir/$module/docc"
fi