blob: c9c5ff7d5e09f1da1d3dafae9b5b15f8c515378d [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
Jeffrey van Gogh16adda22016-08-23 15:22:36 -070013 echo Usage: $0 \<out_dir\> [gcs_bucket]
Jeffrey van Gogh0c624852016-08-01 16:10:07 -070014 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
Jeffrey van Gogh16adda22016-08-23 15:22:36 -070022TARGETS="$(cat tools/base/bazel/build_targets)"
Jeffrey van Gogh0c624852016-08-01 16:10:07 -070023
24# Build all targets and run the kythe extractor via extra_actions.
25bazel build \
26 --experimental_action_listener=${EAL} -- ${TARGETS}
27
28# Find all generated kythe index files.
29KINDEXES=$(find bazel-out/local-fastbuild/extra_actions/ \
30 -name *.kindex -exec realpath {} \;)
31
32# For each kythe index file run the java index to generate kythe
33# entries.
34cd "${OUT_ENTRIES}"
35for KINDEX in ${KINDEXES}; do
36 ENTRIES="$(basename "${KINDEX}").entries"
37 if [ ! -f "${ENTRIES}" ]; then
38 java -jar "${KYTHE_ROOT}/indexers/java_indexer.jar" \
39 "${KINDEX}" > "${ENTRIES}"
40 fi
41done;
Jeffrey van Gogh16adda22016-08-23 15:22:36 -070042
43GSBUCKET="$2"
44if [ -n "${GSBUCKET}" ]; then
45 TIMESTAMP=$(date +'%s')
46 gsutil -m cp "${OUT_ENTRIES}/*" "${GSBUCKET}/${TIMESTAMP}/"
47fi