1#!/bin/bash -e
2
3# Non exhaustive list of modules where we want prebuilts. More can be added as
4# needed.
5MAINLINE_MODULES=(
6  com.android.art.debug
7  com.android.art.release
8  com.android.art.testing
9  com.android.conscrypt
10  com.android.runtime
11  com.android.tzdata
12  com.android.i18n
13)
14
15# List of SDKs and module exports we know of.
16MODULES_SDK_AND_EXPORTS=(
17  art-module-sdk
18  art-module-test-exports
19  conscrypt-module-sdk
20  conscrypt-module-test-exports
21  conscrypt-module-host-exports
22  runtime-module-sdk
23  runtime-module-host-exports
24  i18n-module-test-exports
25  i18n-module-sdk
26  platform-mainline-sdk
27)
28
29# List of libraries installed on the platform that are needed for ART chroot
30# testing.
31PLATFORM_LIBRARIES=(
32  liblog
33  libartpalette-system
34)
35
36# We want to create apex modules for all supported architectures.
37PRODUCTS=(
38  aosp_arm
39  aosp_arm64
40  aosp_x86
41  aosp_x86_64
42)
43
44if [ ! -e "build/make/core/Makefile" ]; then
45  echo "$0 must be run from the top of the tree"
46  exit 1
47fi
48
49echo_and_run() {
50  echo "$*"
51  "$@"
52}
53
54OUT_DIR=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT= get_build_var OUT_DIR)
55DIST_DIR=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT= get_build_var DIST_DIR)
56
57for product in "${PRODUCTS[@]}"; do
58  echo_and_run build/soong/soong_ui.bash --make-mode $@ \
59    TARGET_PRODUCT=${product} \
60    ${MAINLINE_MODULES[@]} \
61    ${PLATFORM_LIBRARIES[@]}
62
63  PRODUCT_OUT=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT=${product} get_build_var PRODUCT_OUT)
64  TARGET_ARCH=$(source build/envsetup.sh > /dev/null; TARGET_PRODUCT=${product} get_build_var TARGET_ARCH)
65  rm -rf ${DIST_DIR}/${TARGET_ARCH}/
66  mkdir -p ${DIST_DIR}/${TARGET_ARCH}/
67  for module in "${MAINLINE_MODULES[@]}"; do
68    echo_and_run cp ${PWD}/${PRODUCT_OUT}/system/apex/${module}.apex ${DIST_DIR}/${TARGET_ARCH}/
69  done
70  for library in "${PLATFORM_LIBRARIES[@]}"; do
71    echo_and_run cp ${PWD}/${PRODUCT_OUT}/system/lib/${library}.so ${DIST_DIR}/${TARGET_ARCH}/
72  done
73done
74
75# Create multi-archs SDKs in a different out directory. The multi-arch script
76# uses Soong in --skip-make mode which cannot use the same directory as normal
77# mode with make.
78export OUT_DIR=${OUT_DIR}/aml
79echo_and_run build/soong/scripts/build-aml-prebuilts.sh ${MODULES_SDK_AND_EXPORTS[@]}
80
81rm -rf ${DIST_DIR}/mainline-sdks
82echo_and_run cp -R ${OUT_DIR}/soong/mainline-sdks ${DIST_DIR}
83