build_kzip.bash 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.
  6. # The following environment variables affect the result:
  7. # BUILD_NUMBER build number, used to generate unique ID (will use UUID if not set)
  8. # DIST_DIR where the resulting all.kzip will be placed
  9. # KYTHE_KZIP_ENCODING proto or json (proto is default)
  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'
  14. : ${BUILD_NUMBER:=$(uuidgen)}
  15. : ${KYTHE_KZIP_ENCODING:=proto}
  16. export KYTHE_KZIP_ENCODING
  17. # The extraction might fail for some source files, so run with -k and then check that
  18. # sufficiently many files were generated.
  19. declare -r out="${OUT_DIR:-out}"
  20. # Build extraction files for C++ and Java. Build `merge_zips` which we use later.
  21. build/soong/soong_ui.bash --build-mode --all-modules --dir=$PWD -k merge_zips xref_cxx xref_java
  22. # Build extraction file for Go the files in build/{blueprint,soong} directories.
  23. declare -r abspath_out=$(realpath "${out}")
  24. declare -r go_extractor=$(realpath prebuilts/build-tools/linux-x86/bin/go_extractor)
  25. declare -r go_root=$(realpath prebuilts/go/linux-x86)
  26. declare -r vnames_path=$(realpath build/soong/vnames.go.json)
  27. declare -r source_root=$PWD
  28. for dir in blueprint soong; do
  29. (cd "build/$dir";
  30. KYTHE_ROOT_DIRECTORY="${source_root}" "$go_extractor" --goroot="$go_root" --rules="${vnames_path}" \
  31. --canonicalize_package_corpus --output "${abspath_out}/soong/build_${dir}.go.kzip" ./...
  32. )
  33. done
  34. declare -r kzip_count=$(find "$out" -name '*.kzip' | wc -l)
  35. (($kzip_count>100000)) || { printf "Too few kzip files were generated: %d\n" $kzip_count; exit 1; }
  36. # Pack
  37. # TODO(asmundak): this should be done by soong.
  38. declare -r allkzip="$BUILD_NUMBER.kzip"
  39. "$out/soong/host/linux-x86/bin/merge_zips" "$DIST_DIR/$allkzip" @<(find "$out" -name '*.kzip')