tweaks to kythe indexing for Android Studio
-tool to generate vnames with googleplex-android corpus name
-uses root to map to the project name from manifest
-update vnames.json with that tool
-use tools/base/bazel/build_targets for targets to process
-add option to kythe build script to save entries to gcs
this location will be used by code search to pick up data
Change-Id: I1627b221b7c4b146d1278d067abda8db329fec20
diff --git a/linux-x86_64/kythe/studio/build_studio_kythe.sh b/linux-x86_64/kythe/studio/build_studio_kythe.sh
index a328cf4..c9c5ff7 100755
--- a/linux-x86_64/kythe/studio/build_studio_kythe.sh
+++ b/linux-x86_64/kythe/studio/build_studio_kythe.sh
@@ -10,7 +10,7 @@
# Get the output path for the kythe artifacts.
OUT="$1"
if [ -z "${OUT}" ]; then
- echo Usage: $0 \<out_dir\>
+ echo Usage: $0 \<out_dir\> [gcs_bucket]
echo e.g. $0 $HOME/studio_kythe
echo
echo $0 must be launched from the root of the studio branch.
@@ -19,15 +19,7 @@
OUT_ENTRIES="${OUT}/entries"
mkdir -p "${OUT_ENTRIES}"
-#TODO: read from file
-TARGETS="//prebuilts/studio/... \
- //prebuilts/tools/common/... \
- //tools/adt/idea/... \
- //tools/analytics-library/... \
- //tools/base/... \
- //tools/data-binding/... \
- //tools/idea/... \
- //tools/sherpa/..."
+TARGETS="$(cat tools/base/bazel/build_targets)"
# Build all targets and run the kythe extractor via extra_actions.
bazel build \
@@ -47,3 +39,9 @@
"${KINDEX}" > "${ENTRIES}"
fi
done;
+
+GSBUCKET="$2"
+if [ -n "${GSBUCKET}" ]; then
+ TIMESTAMP=$(date +'%s')
+ gsutil -m cp "${OUT_ENTRIES}/*" "${GSBUCKET}/${TIMESTAMP}/"
+fi
\ No newline at end of file
diff --git a/linux-x86_64/kythe/studio/manifest2vname.py b/linux-x86_64/kythe/studio/manifest2vname.py
new file mode 100755
index 0000000..a238acb
--- /dev/null
+++ b/linux-x86_64/kythe/studio/manifest2vname.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Tool to generate vnames.json file for kythe from Android repo
+manifest. Needs to be run from repo root."""
+
+import xml.etree.ElementTree
+import json
+
+doc = xml.etree.ElementTree.parse('.repo/manifests/default.xml')
+manifest = doc.getroot()
+# fallback patterns to be added to tail of vnames.json
+tail = json.loads("""[
+ {
+ "pattern": "bazel-out/[^/]+/(.*)",
+ "vname": {
+ "corpus": "googleplex-android",
+ "root": "GENERATED/studio/bazel",
+ "path": "@1@"
+ }
+ },
+ {
+ "pattern": "(.*)",
+ "vname": {
+ "corpus": "googleplex-android",
+ "path": "@1@"
+ }
+ }
+]
+""")
+
+vnames = []
+# manifest xml contains <project path="" name=""> tags
+# we convert these into vname patterns that kythe understands.
+for project in manifest.findall('project'):
+ node = {}
+ node['pattern'] = "%s/(.*)" % project.get('path')
+ vname = {}
+ vname['corpus'] = 'googleplex-android'
+ vname['root'] = project.get('name')
+ vname['path'] = '@1@'
+ node['vname'] = vname
+ vnames.append(node);
+
+# add fallback vname patterns to end of json list.
+vnames.extend(tail)
+
+# print the json vnames list to stdout
+# can be used for debugging or pipe to vnames.json.
+print(json.dumps(vnames, indent=2, separators=(',', ':')))