blob: c1d09f751807b4196d04990ee25824fca476be25 [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; }
19
Sasha Smundakcb86c3c2019-08-08 12:51:15 -070020# The extraction might fail for some source files, so run with -k
Sasha Smundaka1e178f2019-09-24 11:57:58 -070021OUT_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 -070022
23# We build with -k, so check that we have generated at least 100K files
24# (the actual number is 180K+)
25declare -r kzip_count=$(find $OUT_DIR -name '*.kzip' | wc -l)
26(($kzip_count>100000)) || { printf "Too few kzip files were generated: %d\n" $kzip_count; exit 1; }
27
28# Pack
29# TODO(asmundak): this should be done by soong.
30declare -r allkzip=all.kzip
Sasha Smundaka1e178f2019-09-24 11:57:58 -070031"$OUT_DIR/soong/host/linux-x86/bin/merge_zips" "$DIST_DIR/$allkzip" @<(find $OUT_DIR -name '*.kzip')
Sasha Smundak69ee7b02019-09-23 19:13:37 -070032echo "${BUILD_NUMBER:-$(uuidgen)}" >"$DIST_DIR/revision.txt"