|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (c) 2022, Apple Inc. All rights reserved. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without modification, |
| 6 | +# are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | +# list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer in the documentation and/or |
| 13 | +# other materials provided with the distribution. |
| 14 | +# |
| 15 | +# 3. Neither the name of the copyright holder(s) nor the names of any contributors |
| 16 | +# may be used to endorse or promote products derived from this software without |
| 17 | +# specific prior written permission. No license is granted to the trademarks of |
| 18 | +# the copyright holders even if such marks are included in this software. |
| 19 | +# |
| 20 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 24 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 27 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 28 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | + |
| 31 | +# A `realpath` alternative using the default C implementation. |
| 32 | +filepath() { |
| 33 | + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" |
| 34 | +} |
| 35 | + |
| 36 | +# First get the absolute path to this file so we can get the absolute file path to the Swift-DocC root source dir. |
| 37 | +PROJECT_ROOT="$(dirname $(dirname $(filepath $0)))" |
| 38 | +DOCS_DIR="$PROJECT_ROOT/.build/swift-docc" |
| 39 | +SGFS_DIR="$DOCS_DIR/symbol-graph-files" |
| 40 | +TEMP_WORKSPACE_DIR="$DOCS_DIR/temporary-workspace-holding-directory" |
| 41 | + |
| 42 | +DOCC_CMD=convert |
| 43 | +OUTPUT_PATH="$DOCS_DIR/ParseServerSwift.doccarchive" |
| 44 | +HOSTING_BASE_PATH="" |
| 45 | +PUBLISH="NO" |
| 46 | + |
| 47 | +# Process command line arguments |
| 48 | +OUTPUT_PATH_PROCESSED=0 |
| 49 | +HOSTING_BASE_PATH_PROCESSED=0 |
| 50 | +while test $# -gt 0; do |
| 51 | + case "$1" in |
| 52 | + --help) |
| 53 | + echo "Usage: $(basename $0) [<output-path>] [<hosting-base-path>] [--preview] [--publish] [--help]" |
| 54 | + echo |
| 55 | + echo "Builds ParseServerSwift and generates or previews the Swift-DocC documentation." |
| 56 | + echo |
| 57 | + echo " --preview: Starts a preview server after generating documentation." |
| 58 | + echo " --publish: Configures the documentation build for publishing on GitHub pages." |
| 59 | + echo |
| 60 | + exit 0 |
| 61 | + ;; |
| 62 | + --preview) |
| 63 | + DOCC_CMD=preview |
| 64 | + shift |
| 65 | + ;; |
| 66 | + --publish) |
| 67 | + PUBLISH="YES" |
| 68 | + shift |
| 69 | + ;; |
| 70 | + *) |
| 71 | + if [ ${OUTPUT_PATH_PROCESSED} -eq 0 ]; then |
| 72 | + OUTPUT_PATH="$1" |
| 73 | + OUTPUT_PATH_PROCESSED=1 |
| 74 | + elif [ ${HOSTING_BASE_PATH_PROCESSED} -eq 0 ]; then |
| 75 | + HOSTING_BASE_PATH="$1" |
| 76 | + HOSTING_BASE_PATH_PROCESSED=1 |
| 77 | + else |
| 78 | + echo "Unrecognised argument \"$1\"" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + ;; |
| 82 | + esac |
| 83 | + shift |
| 84 | +done |
| 85 | + |
| 86 | +if [ "$PUBLISH" = "YES" ]; then |
| 87 | + if [ ${HOSTING_BASE_PATH_PROCESSED} -eq 0 ]; then |
| 88 | + echo "A hosting base path must be provided if the '--publish' flag is passed." |
| 89 | + echo "See '--help' for details." |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | +fi |
| 93 | + |
| 94 | +# Create the output directory for the symbol graphs if needed. |
| 95 | +mkdir -p "$DOCS_DIR" |
| 96 | +mkdir -p "$SGFS_DIR" |
| 97 | +rm -f $SGFS_DIR/*.* |
| 98 | + |
| 99 | +cd "$PROJECT_ROOT" |
| 100 | + |
| 101 | +# Temporarily move the Xcode workspace aside so that xcodebuild uses the Swift package directly |
| 102 | +mkdir "$TEMP_WORKSPACE_DIR" |
| 103 | +mv Parse.xcworkspace "$TEMP_WORKSPACE_DIR/Parse.xcworkspace" |
| 104 | + |
| 105 | +xcodebuild clean build -scheme ParseServerSwift\ \(iOS\) \ |
| 106 | + -destination generic/platform=iOS \ |
| 107 | + OTHER_SWIFT_FLAGS="-emit-symbol-graph -emit-symbol-graph-dir '$SGFS_DIR'" | xcpretty |
| 108 | + |
| 109 | +mv "$TEMP_WORKSPACE_DIR/Parse.xcworkspace" ./Parse.xcworkspace |
| 110 | +rm -r "$TEMP_WORKSPACE_DIR" |
| 111 | + |
| 112 | +# Pretty print DocC JSON output so that it can be consistently diffed between commits |
| 113 | +export DOCC_JSON_PRETTYPRINT="YES" |
| 114 | + |
| 115 | +# By default pass the --index flag so we produce a full DocC archive. |
| 116 | +EXTRA_DOCC_FLAGS="--index" |
| 117 | + |
| 118 | +# If building for publishing, don't pass the --index flag but pass additional flags for |
| 119 | +# static hosting configuration. |
| 120 | +if [ "$PUBLISH" = "YES" ]; then |
| 121 | + EXTRA_DOCC_FLAGS="--transform-for-static-hosting --hosting-base-path Parse-Swift/$HOSTING_BASE_PATH" |
| 122 | +fi |
| 123 | + |
| 124 | +# Handle the case where a DocC catalog does not exist in the ParseServerSwift repo |
| 125 | +if [ -d Sources/ParseServerSwift/Documentation.docc ]; then |
| 126 | + # The DocC catalog exists, so pass it to the docc invocation. |
| 127 | + DOCC_CMD="$DOCC_CMD Sources/ParseServerSwift/Documentation.docc" |
| 128 | +fi |
| 129 | + |
| 130 | +xcrun docc $DOCC_CMD \ |
| 131 | + --additional-symbol-graph-dir "$SGFS_DIR" \ |
| 132 | + --output-path "$OUTPUT_PATH" $EXTRA_DOCC_FLAGS \ |
| 133 | + --fallback-display-name ParseServerSwift \ |
| 134 | + --fallback-bundle-identifier edu.uky.cs.netreconlab.ParseServerSwift \ |
| 135 | + --fallback-bundle-version 1.0.0 |
| 136 | + |
| 137 | +if [[ "$DOCC_CMD" == "convert"* ]]; then |
| 138 | + echo |
| 139 | + echo "Generated DocC archive at: $OUTPUT_PATH" |
| 140 | +fi |
| 141 | + |
0 commit comments