blob: ccd6bad028c1f9ef9efbfac08430215020c034cc [file] [log] [blame]
Sasha Smundak65143642019-09-26 20:14:28 -07001#! /bin/bash -uv
Sasha Smundakcb86c3c2019-08-08 12:51:15 -07002#
3# Build kzip files (source files for the indexing pipeline) for the given configuration,
4# merge them and place the resulting all.kzip into $DIST_DIR.
5# It is assumed that the current directory is the top of the source tree.
Sasha Smundak69ee7b02019-09-23 19:13:37 -07006# The following environment variables affect the result:
Sasha Smundak69ee7b02019-09-23 19:13:37 -07007# BUILD_NUMBER build number, used to generate unique ID (will use UUID if not set)
Sasha Smundak65143642019-09-26 20:14:28 -07008# DIST_DIR where the resulting all.kzip will be placed
9# OUT_DIR output directory (out if not specified})
10# TARGET_BUILD_VARIANT variant, e.g., `userdebug`
11# TARGET_PRODUCT target device name, e.g., 'aosp_blueline'
12# XREF_CORPUS source code repository URI, e.g., 'android.googlesource.com/platform/superproject'
Sasha Smundakcb86c3c2019-08-08 12:51:15 -070013
Sasha Smundak114d9662019-09-26 14:54:19 -070014: ${BUILD_NUMBER:=$(uuidgen)}
Sasha Smundaka1e178f2019-09-24 11:57:58 -070015
Sasha Smundak65143642019-09-26 20:14:28 -070016# The extraction might fail for some source files, so run with -k and then check that
17# sufficiently many files were generated.
Sasha Smundak65143642019-09-26 20:14:28 -070018declare -r out="${OUT_DIR:-out}"
Sasha Smundakca540882019-12-20 14:25:50 -080019# Build extraction files for C++ and Java. Build `merge_zips` which we use later.
20build/soong/soong_ui.bash --build-mode --all-modules --dir=$PWD -k merge_zips xref_cxx xref_java
21#Build extraction file for Go files in build/soong directory.
22(cd build/soong;
23 ../../prebuilts/build-tools/linux-x86/bin/go_extractor \
24 --goroot="${PWD}/../../prebuilts/go/linux-x86" \
25 --rules=vnames.go.json \
26 --canonicalize_package_corpus \
27 --output "${out}/soong/all.go.kzip" \
28 ./... )
29
Sasha Smundak65143642019-09-26 20:14:28 -070030declare -r kzip_count=$(find "$out" -name '*.kzip' | wc -l)
Sasha Smundakcb86c3c2019-08-08 12:51:15 -070031(($kzip_count>100000)) || { printf "Too few kzip files were generated: %d\n" $kzip_count; exit 1; }
32
33# Pack
34# TODO(asmundak): this should be done by soong.
Sasha Smundak114d9662019-09-26 14:54:19 -070035declare -r allkzip="$BUILD_NUMBER.kzip"
Sasha Smundak65143642019-09-26 20:14:28 -070036"$out/soong/host/linux-x86/bin/merge_zips" "$DIST_DIR/$allkzip" @<(find "$out" -name '*.kzip')
Sasha Smundak114d9662019-09-26 14:54:19 -070037