blob: ef5565de3b31d4cc8b795fd0f0c05e913dd77ba7 [file] [log] [blame]
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001#!/bin/bash -e
2
Martin Stjernholm691503e2020-05-06 22:03:26 +01003# This is a wrapper around "m" that builds the given modules in multi-arch mode
4# for all architectures supported by Mainline modules. The make (kati) stage is
5# skipped, so the build targets in the arguments can only be Soong modules or
6# intermediate output files - make targets and normal installed paths are not
7# supported.
8#
9# This script is typically used with "sdk" or "module_export" modules, which
10# Soong will install in $OUT_DIR/soong/mainline-sdks (cf
11# PathForMainlineSdksInstall in android/paths.go).
12
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000013export OUT_DIR=${OUT_DIR:-out}
14
15if [ -e ${OUT_DIR}/soong/.soong.in_make ]; then
16 # If ${OUT_DIR} has been created without --skip-make, Soong will create an
17 # ${OUT_DIR}/soong/build.ninja that leaves out many targets which are
18 # expected to be supplied by the .mk files, and that might cause errors in
19 # "m --skip-make" below. We therefore default to a different out dir
20 # location in that case.
Martin Stjernholm691503e2020-05-06 22:03:26 +010021 AML_OUT_DIR=out/aml
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000022 echo "Avoiding in-make OUT_DIR '${OUT_DIR}' - building in '${AML_OUT_DIR}' instead"
23 OUT_DIR=${AML_OUT_DIR}
24fi
25
Martin Stjernholm691503e2020-05-06 22:03:26 +010026if [ ! -e "build/envsetup.sh" ]; then
27 echo "$0 must be run from the top of the tree"
28 exit 1
29fi
30
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000031source build/envsetup.sh
32
33my_get_build_var() {
34 # get_build_var will run Soong in normal in-make mode where it creates
35 # .soong.in_make. That would clobber our real out directory, so we need to
36 # run it in a different one.
37 OUT_DIR=${OUT_DIR}/get_build_var get_build_var "$@"
38}
39
Martin Stjernholm691503e2020-05-06 22:03:26 +010040readonly PLATFORM_SDK_VERSION="$(my_get_build_var PLATFORM_SDK_VERSION)"
41readonly PLATFORM_VERSION="$(my_get_build_var PLATFORM_VERSION)"
42PLATFORM_VERSION_ALL_CODENAMES="$(my_get_build_var PLATFORM_VERSION_ALL_CODENAMES)"
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000043
44# PLATFORM_VERSION_ALL_CODENAMES is a comma separated list like O,P. We need to
45# turn this into ["O","P"].
Martin Stjernholm691503e2020-05-06 22:03:26 +010046PLATFORM_VERSION_ALL_CODENAMES="${PLATFORM_VERSION_ALL_CODENAMES/,/'","'}"
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000047PLATFORM_VERSION_ALL_CODENAMES="[\"${PLATFORM_VERSION_ALL_CODENAMES}\"]"
48
49# Logic from build/make/core/goma.mk
50if [ "${USE_GOMA}" = true ]; then
51 if [ -n "${GOMA_DIR}" ]; then
52 goma_dir="${GOMA_DIR}"
53 else
54 goma_dir="${HOME}/goma"
55 fi
56 GOMA_CC="${goma_dir}/gomacc"
57 export CC_WRAPPER="${CC_WRAPPER}${CC_WRAPPER:+ }${GOMA_CC}"
58 export CXX_WRAPPER="${CXX_WRAPPER}${CXX_WRAPPER:+ }${GOMA_CC}"
59 export JAVAC_WRAPPER="${JAVAC_WRAPPER}${JAVAC_WRAPPER:+ }${GOMA_CC}"
60else
61 USE_GOMA=false
62fi
63
Martin Stjernholm691503e2020-05-06 22:03:26 +010064readonly SOONG_OUT=${OUT_DIR}/soong
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000065mkdir -p ${SOONG_OUT}
Martin Stjernholm691503e2020-05-06 22:03:26 +010066readonly SOONG_VARS=${SOONG_OUT}/soong.variables
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000067
Martin Stjernholm691503e2020-05-06 22:03:26 +010068# Aml_abis: true
69# - This flag configures Soong to compile for all architectures required for
70# Mainline modules.
71# CrossHost: linux_bionic
72# CrossHostArch: x86_64
73# - Enable Bionic on host as ART needs prebuilts for it.
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000074cat > ${SOONG_VARS}.new << EOF
75{
76 "Platform_sdk_version": ${PLATFORM_SDK_VERSION},
77 "Platform_sdk_codename": "${PLATFORM_VERSION}",
78 "Platform_version_active_codenames": ${PLATFORM_VERSION_ALL_CODENAMES},
79
80 "DeviceName": "generic_arm64",
81 "HostArch": "x86_64",
Nicolas Geoffrayabdc8c52020-03-24 11:39:06 +000082 "HostSecondaryArch": "x86",
Nicolas Geoffray71233e42020-04-25 16:25:21 +010083 "CrossHost": "linux_bionic",
84 "CrossHostArch": "x86_64",
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000085 "Aml_abis": true,
86
Martin Stjernholm2829f6c2020-08-11 01:41:20 +010087 "Allow_missing_dependencies": ${SOONG_ALLOW_MISSING_DEPENDENCIES:-false},
88 "Unbundled_build": ${TARGET_BUILD_UNBUNDLED:-false},
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000089 "UseGoma": ${USE_GOMA}
90}
91EOF
92
93if [ -f ${SOONG_VARS} ] && cmp -s ${SOONG_VARS} ${SOONG_VARS}.new; then
94 # Don't touch soong.variables if we don't have to, to avoid Soong rebuilding
95 # the ninja file when it isn't necessary.
96 rm ${SOONG_VARS}.new
97else
98 mv ${SOONG_VARS}.new ${SOONG_VARS}
99fi
100
Nicolas Geoffray7cad0f82020-04-28 15:53:42 +0100101# We use force building LLVM components flag (even though we actually don't
102# compile them) because we don't have bionic host prebuilts
103# for them.
Martin Stjernholm691503e2020-05-06 22:03:26 +0100104export FORCE_BUILD_LLVM_COMPONENTS=true
105
106m --skip-make "$@"