2019-09-27 05:14:28 +02:00
|
|
|
#! /bin/bash -uv
|
2019-08-08 21:51:15 +02:00
|
|
|
#
|
|
|
|
# Build kzip files (source files for the indexing pipeline) for the given configuration,
|
|
|
|
# merge them and place the resulting all.kzip into $DIST_DIR.
|
|
|
|
# It is assumed that the current directory is the top of the source tree.
|
2019-09-24 04:13:37 +02:00
|
|
|
# The following environment variables affect the result:
|
2019-09-27 05:14:28 +02:00
|
|
|
# BUILD_NUMBER build number, used to generate unique ID (will use UUID if not set)
|
2021-05-06 01:04:34 +02:00
|
|
|
# SUPERPROJECT_SHA superproject sha, used to generate unique id (will use BUILD_NUMBER if not set)
|
2021-05-18 01:31:47 +02:00
|
|
|
# SUPERPROJECT_REVISION superproject revision, used for unique id if defined as a sha
|
|
|
|
# KZIP_NAME name of the output file (will use SUPERPROJECT_REVISION|SUPERPROJECT_SHA|BUILD_NUMBER|UUID if not set)
|
2019-08-08 21:51:15 +02:00
|
|
|
# DIST_DIR where the resulting all.kzip will be placed
|
2020-01-10 02:34:23 +01:00
|
|
|
# KYTHE_KZIP_ENCODING proto or json (proto is default)
|
2021-02-16 19:39:40 +01:00
|
|
|
# KYTHE_JAVA_SOURCE_BATCH_SIZE maximum number of the Java source files in a compilation unit
|
2019-09-27 05:14:28 +02:00
|
|
|
# OUT_DIR output directory (out if not specified})
|
|
|
|
# TARGET_BUILD_VARIANT variant, e.g., `userdebug`
|
|
|
|
# TARGET_PRODUCT target device name, e.g., 'aosp_blueline'
|
2019-09-24 04:13:37 +02:00
|
|
|
# XREF_CORPUS source code repository URI, e.g., 'android.googlesource.com/platform/superproject'
|
2019-08-08 21:51:15 +02:00
|
|
|
|
2021-05-18 01:31:47 +02:00
|
|
|
# If the SUPERPROJECT_REVISION is defined as a sha, use this as the default value if no
|
|
|
|
# SUPERPROJECT_SHA is specified.
|
|
|
|
if [[ $SUPERPROJECT_REVISION =~ [0-9a-f]{40} ]]; then
|
|
|
|
: ${KZIP_NAME:=${SUPERPROJECT_REVISION:-}}
|
|
|
|
fi
|
|
|
|
|
|
|
|
: ${KZIP_NAME:=${SUPERPROJECT_SHA:-}}
|
|
|
|
: ${KZIP_NAME:=${BUILD_NUMBER:-}}
|
|
|
|
: ${KZIP_NAME:=$(uuidgen)}
|
|
|
|
|
2021-02-16 19:39:40 +01:00
|
|
|
: ${KYTHE_JAVA_SOURCE_BATCH_SIZE:=500}
|
2020-01-10 02:34:23 +01:00
|
|
|
: ${KYTHE_KZIP_ENCODING:=proto}
|
2021-03-09 01:29:31 +01:00
|
|
|
: ${XREF_CORPUS:?should be set}
|
2021-02-16 19:39:40 +01:00
|
|
|
export KYTHE_JAVA_SOURCE_BATCH_SIZE KYTHE_KZIP_ENCODING
|
2019-09-24 20:57:58 +02:00
|
|
|
|
2019-09-27 05:14:28 +02:00
|
|
|
# The extraction might fail for some source files, so run with -k and then check that
|
|
|
|
# sufficiently many files were generated.
|
|
|
|
declare -r out="${OUT_DIR:-out}"
|
2020-02-25 20:15:25 +01:00
|
|
|
|
2019-12-20 23:25:50 +01:00
|
|
|
# Build extraction files for C++ and Java. Build `merge_zips` which we use later.
|
|
|
|
build/soong/soong_ui.bash --build-mode --all-modules --dir=$PWD -k merge_zips xref_cxx xref_java
|
2020-02-25 20:15:25 +01:00
|
|
|
|
|
|
|
# Build extraction file for Go the files in build/{blueprint,soong} directories.
|
2019-12-28 00:29:05 +01:00
|
|
|
declare -r abspath_out=$(realpath "${out}")
|
2020-01-15 02:01:03 +01:00
|
|
|
declare -r go_extractor=$(realpath prebuilts/build-tools/linux-x86/bin/go_extractor)
|
|
|
|
declare -r go_root=$(realpath prebuilts/go/linux-x86)
|
2020-02-25 20:15:25 +01:00
|
|
|
declare -r source_root=$PWD
|
2021-03-09 01:29:31 +01:00
|
|
|
|
|
|
|
# TODO(asmundak): Until b/182183061 is fixed, default corpus has to be specified
|
|
|
|
# in the rules file. Generate this file on the fly with corpus value set from the
|
|
|
|
# environment variable.
|
2020-01-15 02:01:03 +01:00
|
|
|
for dir in blueprint soong; do
|
|
|
|
(cd "build/$dir";
|
2021-03-09 01:29:31 +01:00
|
|
|
KYTHE_ROOT_DIRECTORY="${source_root}" "$go_extractor" --goroot="$go_root" \
|
|
|
|
--rules=<(printf '[{"pattern": "(.*)","vname": {"path": "@1@", "corpus":"%s"}}]' "${XREF_CORPUS}") \
|
2020-02-25 20:15:25 +01:00
|
|
|
--canonicalize_package_corpus --output "${abspath_out}/soong/build_${dir}.go.kzip" ./...
|
2020-01-15 02:01:03 +01:00
|
|
|
)
|
|
|
|
done
|
2019-12-20 23:25:50 +01:00
|
|
|
|
2019-09-27 05:14:28 +02:00
|
|
|
declare -r kzip_count=$(find "$out" -name '*.kzip' | wc -l)
|
2019-08-08 21:51:15 +02:00
|
|
|
(($kzip_count>100000)) || { printf "Too few kzip files were generated: %d\n" $kzip_count; exit 1; }
|
|
|
|
|
|
|
|
# Pack
|
|
|
|
# TODO(asmundak): this should be done by soong.
|
2021-05-18 01:31:47 +02:00
|
|
|
declare -r allkzip="$KZIP_NAME.kzip"
|
2019-09-27 05:14:28 +02:00
|
|
|
"$out/soong/host/linux-x86/bin/merge_zips" "$DIST_DIR/$allkzip" @<(find "$out" -name '*.kzip')
|
2019-09-26 23:54:19 +02:00
|
|
|
|