blob: a328cf424447ce3e6ed1edc68edf0cbf5d0b0798 [file] [log] [blame]
Jeffrey van Gogh0c624852016-08-01 16:10:07 -07001#!/bin/bash -e
2
3# Bazel build target for running kythe extractor as an extra_action
4# to create kythe index files as a side effect of running the build.
5EAL=//prebuilts/tools/linux-x86_64/kythe/extractors:extract_kindex
6
7# Path to the kyth binaries.
8KYTHE_ROOT="$(readlink -f prebuilts/tools/linux-x86_64/kythe)"
9
10# Get the output path for the kythe artifacts.
11OUT="$1"
12if [ -z "${OUT}" ]; then
13 echo Usage: $0 \<out_dir\>
14 echo e.g. $0 $HOME/studio_kythe
15 echo
16 echo $0 must be launched from the root of the studio branch.
17 exit 1
18fi
19OUT_ENTRIES="${OUT}/entries"
20mkdir -p "${OUT_ENTRIES}"
21
22#TODO: read from file
23TARGETS="//prebuilts/studio/... \
24 //prebuilts/tools/common/... \
25 //tools/adt/idea/... \
26 //tools/analytics-library/... \
27 //tools/base/... \
28 //tools/data-binding/... \
29 //tools/idea/... \
30 //tools/sherpa/..."
31
32# Build all targets and run the kythe extractor via extra_actions.
33bazel build \
34 --experimental_action_listener=${EAL} -- ${TARGETS}
35
36# Find all generated kythe index files.
37KINDEXES=$(find bazel-out/local-fastbuild/extra_actions/ \
38 -name *.kindex -exec realpath {} \;)
39
40# For each kythe index file run the java index to generate kythe
41# entries.
42cd "${OUT_ENTRIES}"
43for KINDEX in ${KINDEXES}; do
44 ENTRIES="$(basename "${KINDEX}").entries"
45 if [ ! -f "${ENTRIES}" ]; then
46 java -jar "${KYTHE_ROOT}/indexers/java_indexer.jar" \
47 "${KINDEX}" > "${ENTRIES}"
48 fi
49done;