Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 1 | #! /bin/bash -uv |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 2 | # |
| 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 Smundak | 69ee7b0 | 2019-09-23 19:13:37 -0700 | [diff] [blame] | 6 | # The following environment variables affect the result: |
Sasha Smundak | 69ee7b0 | 2019-09-23 19:13:37 -0700 | [diff] [blame] | 7 | # BUILD_NUMBER build number, used to generate unique ID (will use UUID if not set) |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 8 | # DIST_DIR where the resulting all.kzip will be placed |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 9 | # KYTHE_KZIP_ENCODING proto or json (proto is default) |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 10 | # OUT_DIR output directory (out if not specified}) |
| 11 | # TARGET_BUILD_VARIANT variant, e.g., `userdebug` |
| 12 | # TARGET_PRODUCT target device name, e.g., 'aosp_blueline' |
| 13 | # XREF_CORPUS source code repository URI, e.g., 'android.googlesource.com/platform/superproject' |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 14 | |
Sasha Smundak | 114d966 | 2019-09-26 14:54:19 -0700 | [diff] [blame] | 15 | : ${BUILD_NUMBER:=$(uuidgen)} |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 16 | : ${KYTHE_KZIP_ENCODING:=proto} |
Sasha Smundak | f77ee74 | 2020-01-22 14:41:01 -0800 | [diff] [blame] | 17 | export KYTHE_KZIP_ENCODING |
Sasha Smundak | a1e178f | 2019-09-24 11:57:58 -0700 | [diff] [blame] | 18 | |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 19 | # The extraction might fail for some source files, so run with -k and then check that |
| 20 | # sufficiently many files were generated. |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 21 | declare -r out="${OUT_DIR:-out}" |
Sasha Smundak | b8f46cd | 2020-02-25 11:15:25 -0800 | [diff] [blame] | 22 | |
Sasha Smundak | ca54088 | 2019-12-20 14:25:50 -0800 | [diff] [blame] | 23 | # Build extraction files for C++ and Java. Build `merge_zips` which we use later. |
| 24 | build/soong/soong_ui.bash --build-mode --all-modules --dir=$PWD -k merge_zips xref_cxx xref_java |
Sasha Smundak | b8f46cd | 2020-02-25 11:15:25 -0800 | [diff] [blame] | 25 | |
| 26 | # Build extraction file for Go the files in build/{blueprint,soong} directories. |
Sasha Smundak | 17c42bd | 2019-12-27 15:29:05 -0800 | [diff] [blame] | 27 | declare -r abspath_out=$(realpath "${out}") |
Sasha Smundak | facb360 | 2020-01-14 17:01:03 -0800 | [diff] [blame] | 28 | declare -r go_extractor=$(realpath prebuilts/build-tools/linux-x86/bin/go_extractor) |
| 29 | declare -r go_root=$(realpath prebuilts/go/linux-x86) |
Sasha Smundak | b8f46cd | 2020-02-25 11:15:25 -0800 | [diff] [blame] | 30 | declare -r vnames_path=$(realpath build/soong/vnames.go.json) |
| 31 | declare -r source_root=$PWD |
Sasha Smundak | facb360 | 2020-01-14 17:01:03 -0800 | [diff] [blame] | 32 | for dir in blueprint soong; do |
| 33 | (cd "build/$dir"; |
Sasha Smundak | b8f46cd | 2020-02-25 11:15:25 -0800 | [diff] [blame] | 34 | KYTHE_ROOT_DIRECTORY="${source_root}" "$go_extractor" --goroot="$go_root" --rules="${vnames_path}" \ |
| 35 | --canonicalize_package_corpus --output "${abspath_out}/soong/build_${dir}.go.kzip" ./... |
Sasha Smundak | facb360 | 2020-01-14 17:01:03 -0800 | [diff] [blame] | 36 | ) |
| 37 | done |
Sasha Smundak | ca54088 | 2019-12-20 14:25:50 -0800 | [diff] [blame] | 38 | |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 39 | declare -r kzip_count=$(find "$out" -name '*.kzip' | wc -l) |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 40 | (($kzip_count>100000)) || { printf "Too few kzip files were generated: %d\n" $kzip_count; exit 1; } |
| 41 | |
| 42 | # Pack |
| 43 | # TODO(asmundak): this should be done by soong. |
Sasha Smundak | 114d966 | 2019-09-26 14:54:19 -0700 | [diff] [blame] | 44 | declare -r allkzip="$BUILD_NUMBER.kzip" |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 45 | "$out/soong/host/linux-x86/bin/merge_zips" "$DIST_DIR/$allkzip" @<(find "$out" -name '*.kzip') |
Sasha Smundak | 114d966 | 2019-09-26 14:54:19 -0700 | [diff] [blame] | 46 | |