kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/docs/schema/example-go.sh (about)

     1  #!/bin/bash -e
     2  set -o pipefail
     3  
     4  # Copyright 2016 The Kythe Authors. All rights reserved.
     5  #
     6  # Licensed under the Apache License, Version 2.0 (the "License");
     7  # you may not use this file except in compliance with the License.
     8  # You may obtain a copy of the License at
     9  #
    10  #   http://www.apache.org/licenses/LICENSE-2.0
    11  #
    12  # Unless required by applicable law or agreed to in writing, software
    13  # distributed under the License is distributed on an "AS IS" BASIS,
    14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  # See the License for the specific language governing permissions and
    16  # limitations under the License.
    17  
    18  # This script verifies and formats a single Kythe example, which is expected
    19  # to be piped in on standard input from example.sh.
    20  #
    21  # The script assumes its working directory is the schema output directory and
    22  # requires the following environment variables:
    23  #   TMP
    24  #   LANGUAGE
    25  #   LABEL
    26  #   GO_INDEXER_BIN
    27  #   VERIFIER_BIN
    28  #   SHASUM_TOOL
    29  #   SHOWGRAPH
    30  
    31  readonly PKGDIR="$TMP/pkg"
    32  readonly SRCFILE="$PKGDIR/example.go"
    33  mkdir "$PKGDIR"
    34  cat > "$SRCFILE"
    35  
    36  readonly ENTRIES="$TMP/example.entries"
    37  GOCACHE="$TMP/gocache" \
    38    "$GO_INDEXER_BIN" --package kythe/schema "$SRCFILE" > "$ENTRIES"
    39  "$VERIFIER_BIN" --nocheck_for_singletons --use_file_nodes < "$ENTRIES"
    40  
    41  trap 'error FORMAT' ERR
    42  readonly EXAMPLE_ID=$($SHASUM_TOOL "$SRCFILE" | cut -c 1-64)
    43  
    44  if [[ -n "$DIV_STYLE" ]] ; then
    45    echo "<div style=\"${DIV_STYLE}\">"
    46  else
    47    echo "<div>"
    48  fi
    49  
    50  echo "<h5 id=\"_${LABEL}\">${LABEL}"
    51  
    52  if [[ "${SHOWGRAPH}" == 1 ]] ; then
    53    "$VERIFIER_BIN" --nocheck_for_singletons --use_file_nodes --graphviz \
    54      < "$ENTRIES" > "$TMP/${EXAMPLE_ID}.dot"
    55    dot -Tsvg -o "${EXAMPLE_ID}.svg" "$TMP/${EXAMPLE_ID}.dot"
    56    echo "(<a href=\"${EXAMPLE_ID}.svg\" target=\"_blank\">${LANGUAGE}</a>)</h5>"
    57  else
    58    echo " (${LANGUAGE})</h5>"
    59  fi
    60  
    61  source-highlight --failsafe --output=STDOUT --src-lang go -i "$SRCFILE"
    62  echo "</div>"