Jeffrey van Gogh | 0c62485 | 2016-08-01 16:10:07 -0700 | [diff] [blame] | 1 | #!/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. |
| 5 | EAL=//prebuilts/tools/linux-x86_64/kythe/extractors:extract_kindex |
| 6 | |
| 7 | # Path to the kyth binaries. |
| 8 | KYTHE_ROOT="$(readlink -f prebuilts/tools/linux-x86_64/kythe)" |
| 9 | |
| 10 | # Get the output path for the kythe artifacts. |
| 11 | OUT="$1" |
| 12 | if [ -z "${OUT}" ]; then |
Jeffrey van Gogh | 16adda2 | 2016-08-23 15:22:36 -0700 | [diff] [blame^] | 13 | echo Usage: $0 \<out_dir\> [gcs_bucket] |
Jeffrey van Gogh | 0c62485 | 2016-08-01 16:10:07 -0700 | [diff] [blame] | 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 |
| 18 | fi |
| 19 | OUT_ENTRIES="${OUT}/entries" |
| 20 | mkdir -p "${OUT_ENTRIES}" |
| 21 | |
Jeffrey van Gogh | 16adda2 | 2016-08-23 15:22:36 -0700 | [diff] [blame^] | 22 | TARGETS="$(cat tools/base/bazel/build_targets)" |
Jeffrey van Gogh | 0c62485 | 2016-08-01 16:10:07 -0700 | [diff] [blame] | 23 | |
| 24 | # Build all targets and run the kythe extractor via extra_actions. |
| 25 | bazel build \ |
| 26 | --experimental_action_listener=${EAL} -- ${TARGETS} |
| 27 | |
| 28 | # Find all generated kythe index files. |
| 29 | KINDEXES=$(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. |
| 34 | cd "${OUT_ENTRIES}" |
| 35 | for 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 |
| 41 | done; |
Jeffrey van Gogh | 16adda2 | 2016-08-23 15:22:36 -0700 | [diff] [blame^] | 42 | |
| 43 | GSBUCKET="$2" |
| 44 | if [ -n "${GSBUCKET}" ]; then |
| 45 | TIMESTAMP=$(date +'%s') |
| 46 | gsutil -m cp "${OUT_ENTRIES}/*" "${GSBUCKET}/${TIMESTAMP}/" |
| 47 | fi |