kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/release/README.md (about)

     1  *WARNING:* Kythe is alpha.  Use at your own risk.
     2  
     3  Kythe is a pluggable, (mostly) language-agnostic ecosystem for building tools
     4  that work with code.  This release contains the core set of indexers,
     5  extractors, and tools directly supported by the Kythe team.
     6  
     7  *License:* Apache Licence, Version 2.0
     8  
     9  # Contents
    10   - indexers
    11     - cxx_indexer              :: C++ indexer
    12     - go_indexer               :: Go indexer
    13     - java_indexer.jar         :: Java indexer
    14     - jvm_indexer.jar          :: JVM jar indexer
    15     - proto_indexer            :: Protocol-buffer indexer
    16     - textproto_indexer        :: Text-format protocol-buffer indexer
    17   - extractors
    18     - bazel_cxx_extractor      :: C++ extractor for Bazel extra_actions
    19     - bazel_extract_kzip       :: Generic kzip extractor for Bazel extra actions
    20     - bazel_go_extractor       :: Bazel Go extractor
    21     - bazel_java_extractor.jar :: Java extractor for Bazel extra_actions
    22     - bazel_jvm_extractor.jar  :: JVM extractor for Bazel extra_actions
    23     - bazel_proto_extractor    :: Bazel Protocol-buffer extractor
    24     - cxx_extractor            :: C++ extractor
    25     - go_extractor             :: Go extractor
    26     - javac-wrapper.sh         :: javac wrapper script for extractor
    27     - javac_extractor.jar      :: Java extractor
    28     - proto_extractor          :: Protocol-buffer extractor
    29     - textproto_extractor      :: Text-format protocol-buffer extractor
    30   - proto                      :: Protocol buffer definitions of public APIs
    31   - tools
    32     - cc_proto_metadata_plugin :: Replacement protoc plugin to generate metadata for C++
    33     - dedup_stream             :: Removes duplicates entries from a delimited stream
    34     - directory_indexer        :: Emits Kythe file nodes for some local paths
    35     - entrystream              :: Generic Kythe entry stream processor
    36     - http_server              :: HTTP server for Kythe service APIs (xrefs, filetree, graph)
    37     - kythe                    :: CLI for the service APIs exposed by http_server
    38     - kzip                     :: Utility to manipulate .kzip archives
    39     - read_entries             :: Dumps a GraphStore's contents as an entry stream
    40     - triples                  :: Converts an entry stream (or GraphStore) to N-Triples
    41     - verifier                 :: Verifies indexer outputs with source-inlined goals
    42     - write_entries            :: Writes an entry stream to a GraphStore
    43     - write_tables             :: Processes a GraphStore into efficient serving tables for http_server
    44  
    45  # Dependencies
    46   - Java JDK >=8
    47   - libuuid
    48  
    49  ## Debian Jessie Install
    50  
    51      echo "deb http://http.debian.net/debian jessie-backports main" >> /etc/apt/sources.list
    52      apt-get install openjdk-8-jdk libncurses5 libssl1.0.0
    53  
    54  # End-to-end Java Example
    55  
    56  ```
    57  # Install Kythe
    58  tar xzf kythe-v*.tar.gz
    59  rm -rf /opt/kythe
    60  mv kythe-v*/ /opt/kythe
    61  
    62  git clone https://github.com/GoogleCloudPlatform/DataflowJavaSDK.git
    63  cd DataflowJavaSDK
    64  
    65  # Setup the Java extractor's environment
    66  export REAL_JAVAC="$(which javac)"
    67  export JAVAC_EXTRACTOR_JAR=/opt/kythe/extractors/javac_extractor.jar
    68  export KYTHE_ROOT_DIRECTORY="$PWD"
    69  export KYTHE_OUTPUT_DIRECTORY="/tmp/kythe"
    70  export KYTHE_CORPUS=DataflowJavaSDK
    71  mkdir -p "$KYTHE_OUTPUT_DIRECTORY"
    72  
    73  # Force Maven to compile with extractors/javac-wrapper.sh
    74  mvn clean compile \
    75    -Dmaven.compiler.forceJavacCompilerUse=true \
    76    -Dmaven.compiler.fork=true \
    77    -Dmaven.compiler.executable=/opt/kythe/extractors/javac-wrapper.sh
    78  
    79  cd ..
    80  
    81  # Index the resulting .kzip files, deduplicate the entries, and finally store
    82  # them in a GraphStore
    83  GRAPHSTORE=/tmp/kythe_graphstore
    84  rm -rf "$GRAPHSTORE"
    85  find "$KYTHE_OUTPUT_DIRECTORY" -name '*.kzip' | \
    86    xargs -L1 java -jar /opt/kythe/indexers/java_indexer.jar | \
    87    /opt/kythe/tools/dedup_stream | \
    88    /opt/kythe/tools/write_entries --graphstore $GRAPHSTORE
    89  
    90  # Process the GraphStore into serving tables
    91  SERVING=/tmp/kythe_serving
    92  rm -rf "$SERVING"
    93  /opt/kythe/tools/write_tables --graphstore $GRAPHSTORE --out "$SERVING"
    94  
    95  # Launch Kythe's service APIs as an HTTP server listening to only local
    96  # connections on port 9898.  Using `--listen :9898` instead will allow
    97  # connections from other networked machines.
    98  /opt/kythe/tools/http_server --serving_table "$SERVING" \
    99    --listen localhost:9898
   100  
   101  # /opt/kythe/tools/kythe and /opt/kythe/tools/kwazthis can be used with the
   102  # local running server by passing the '--api=http://localhost:9898' flag.
   103  ```
   104  
   105  # Usage
   106  
   107  ## Extractors
   108  
   109  `extractors/cxx_extractor` and `extractors/javac_extractor.jar` are
   110  flag-compatible replacements for clang and javac, respectively.  Instead of
   111  performing a full compilation, they extract the compilation's full context
   112  including all file inputs and archive them in a .kzip file.
   113  
   114  Since each extractor is meant to replace a compiler, all configuration is passed
   115  by the following environment variables:
   116  
   117      KYTHE_ROOT_DIRECTORY (required): root directory of the repository being compiled.
   118          This helps the extractor correctly infer file input paths.
   119      KYTHE_OUTPUT_DIRECTORY (required): output directory for resulting .kzip
   120          files
   121      KYTHE_VNAMES: path to a JSON-encoded VNames configuration file.  See
   122          https://godoc.org/github.com/kythe/kythe/kythe/go/util/vnameutil for
   123          more details on the file's format and
   124          https://kythe.io/repo/kythe/data/vnames.json for an example.
   125      KYTHE_CORPUS: the name of the corpus for all constructed VNames (only used if
   126          KYTHE_VNAMES is unset; defaults to "kythe")
   127  
   128  `extractors/javac-wrapper.sh` is provided as one way to inject an extractor into
   129  a build system -- by wrapping each compiler command.  For instance, Maven
   130  compilations can easily be extracted by replacing `$JAVA_HOME/bin/javac` with
   131  this script and setting the following Maven options:
   132  
   133      -Dmaven.compiler.forceJavacCompilerUse=true
   134      -Dmaven.compiler.fork=true
   135      -Dmaven.compiler.executable=$JAVA_HOME/bin/javac
   136  
   137  Read `extractors/javac-wrapper.sh` for more details on its usage.
   138  
   139  `extractors/go_extractor` extracts from an existing build and doesn't build any
   140  code itself. `-i` needs to be passed to the build to ensure that '-a' is
   141  preserved. See the Examples for usage.
   142  
   143  ### Examples:
   144  
   145      export KYTHE_ROOT_DIRECTORY="$PWD"
   146      export KYTHE_OUTPUT_DIRECTORY=/tmp/kythe
   147  
   148      mkdir -p "$KYTHE_OUTPUT_DIRECTORY"
   149  
   150      java -Xbootclasspath/p:third_party/javac/javac*.jar \
   151        -jar extractors/javac_extractor.jar \
   152        -cp "${$(find third_party -name '*.jar' -printf '%p:')%:}" \
   153        $(find src/main -name '*.java')
   154  
   155      extractors/cxx_extractor -Ithird_party/include some.cc
   156  
   157      cd $GOPATH/src
   158      # Build the tests along with the package.
   159      go test -i github.com/MyOrg/my-package
   160      $KYTHE_ROOT_DIRECTORY/extractors/go_extractor github.com/MyOrg/my-package \
   161        --output $KYTHE_OUTPUT_DIRECTORY/extracted.kzip
   162  
   163  ## Indexers
   164  
   165  `indexers/cxx_indexer`, `indexers/go_indexer`, and `indexers/java_indexer.jar`
   166  analyze the .kzip files produced by the extractors and emit a stream of protobuf
   167  wire-encoded facts (entries) that conform to https://kythe.io/schema. The output
   168  stream can be processed by many of the accompanying binaries in the `tools/` directory.
   169  
   170  ### Examples
   171  
   172      java -jar indexers/java_indexer.jar \
   173        /tmp/kythe/065c7a9a0789d09b73d74b0ca17cfcec6643d69a6218d095d19a770b10dffdf9.kzip \
   174        > java.entries
   175  
   176      indexers/cxx_indexer \
   177        /tmp/kythe/579d266e5914257a9bd4458eb9b218690280ae15123d642025f224d10f64e6f3.kzip \
   178        > cxx.entries
   179  
   180      indexers/go_indexer \
   181        /tmp/kythe/579d266e5914257a9bd4458eb9b218690280ae15123d642025f224d10f64e6f3.kzip \
   182        > go.entries