Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 1 | # /bin/bash -uv |
| 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: |
| 7 | # TARGET_PRODUCT target device name, e.g., 'aosp_blueline' |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 8 | # TARGET_BUILD_VARIANT variant, e.g., `userdebug` |
Sasha Smundak | a1e178f | 2019-09-24 11:57:58 -0700 | [diff] [blame] | 9 | # OUT_DIR absolute path where the build is happening ($PWD/out if not specified}) |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 10 | # DIST_DIR where the resulting all.kzip will be placed |
Sasha Smundak | 69ee7b0 | 2019-09-23 19:13:37 -0700 | [diff] [blame] | 11 | # XREF_CORPUS source code repository URI, e.g., 'android.googlesource.com/platform/superproject' |
| 12 | # BUILD_NUMBER build number, used to generate unique ID (will use UUID if not set) |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 13 | |
Sasha Smundak | a1e178f | 2019-09-24 11:57:58 -0700 | [diff] [blame] | 14 | # If OUT_DIR is not set, the build will use out/ as output directory, which is |
| 15 | # a relative path. Make it absolute, otherwise the indexer will not know that it |
| 16 | # contains only generated files. |
| 17 | : ${OUT_DIR:=$PWD/out} |
| 18 | [[ "$OUT_DIR" =~ ^/ ]] || { echo "$OUT_DIR is not an absolute path"; exit 1; } |
Sasha Smundak | 114d966 | 2019-09-26 14:54:19 -0700 | [diff] [blame^] | 19 | : ${BUILD_NUMBER:=$(uuidgen)} |
Sasha Smundak | a1e178f | 2019-09-24 11:57:58 -0700 | [diff] [blame] | 20 | |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 21 | # The extraction might fail for some source files, so run with -k |
Sasha Smundak | a1e178f | 2019-09-24 11:57:58 -0700 | [diff] [blame] | 22 | OUT_DIR=$OUT_DIR build/soong/soong_ui.bash --build-mode --all-modules --dir=$PWD -k merge_zips xref_cxx xref_java |
Sasha Smundak | cb86c3c | 2019-08-08 12:51:15 -0700 | [diff] [blame] | 23 | |
| 24 | # We build with -k, so check that we have generated at least 100K files |
| 25 | # (the actual number is 180K+) |
| 26 | declare -r kzip_count=$(find $OUT_DIR -name '*.kzip' | wc -l) |
| 27 | (($kzip_count>100000)) || { printf "Too few kzip files were generated: %d\n" $kzip_count; exit 1; } |
| 28 | |
| 29 | # Pack |
| 30 | # TODO(asmundak): this should be done by soong. |
Sasha Smundak | 114d966 | 2019-09-26 14:54:19 -0700 | [diff] [blame^] | 31 | declare -r allkzip="$BUILD_NUMBER.kzip" |
Sasha Smundak | a1e178f | 2019-09-24 11:57:58 -0700 | [diff] [blame] | 32 | "$OUT_DIR/soong/host/linux-x86/bin/merge_zips" "$DIST_DIR/$allkzip" @<(find $OUT_DIR -name '*.kzip') |
Sasha Smundak | 114d966 | 2019-09-26 14:54:19 -0700 | [diff] [blame^] | 33 | |