blob: 607654bd5cd60b05bf2c81e7b126a1952e5cb041 [file] [log] [blame]
Sasha Smundakcb86c3c2019-08-08 12:51:15 -07001# /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 Smundak69ee7b02019-09-23 19:13:37 -07006# The following environment variables affect the result:
7# TARGET_PRODUCT target device name, e.g., 'aosp_blueline'
Sasha Smundakcb86c3c2019-08-08 12:51:15 -07008# TARGET_BUILD_VARIANT variant, e.g., `userdebug`
Sasha Smundaka1e178f2019-09-24 11:57:58 -07009# OUT_DIR absolute path where the build is happening ($PWD/out if not specified})
Sasha Smundakcb86c3c2019-08-08 12:51:15 -070010# DIST_DIR where the resulting all.kzip will be placed
Sasha Smundak69ee7b02019-09-23 19:13:37 -070011# 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 Smundakcb86c3c2019-08-08 12:51:15 -070013
Sasha Smundaka1e178f2019-09-24 11:57:58 -070014# 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 Smundak114d9662019-09-26 14:54:19 -070019: ${BUILD_NUMBER:=$(uuidgen)}
Sasha Smundaka1e178f2019-09-24 11:57:58 -070020
Sasha Smundakcb86c3c2019-08-08 12:51:15 -070021# The extraction might fail for some source files, so run with -k
Sasha Smundaka1e178f2019-09-24 11:57:58 -070022OUT_DIR=$OUT_DIR build/soong/soong_ui.bash --build-mode --all-modules --dir=$PWD -k merge_zips xref_cxx xref_java
Sasha Smundakcb86c3c2019-08-08 12:51:15 -070023
24# We build with -k, so check that we have generated at least 100K files
25# (the actual number is 180K+)
26declare -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 Smundak114d9662019-09-26 14:54:19 -070031declare -r allkzip="$BUILD_NUMBER.kzip"
Sasha Smundaka1e178f2019-09-24 11:57:58 -070032"$OUT_DIR/soong/host/linux-x86/bin/merge_zips" "$DIST_DIR/$allkzip" @<(find $OUT_DIR -name '*.kzip')
Sasha Smundak114d9662019-09-26 14:54:19 -070033