blob: 4b08ac331a143c7b874f66e34ffa0ec7126d211b [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
Jingwen Chencda22c92020-11-23 00:22:30 -050015if [ -e ${OUT_DIR}/soong/.soong.kati_enabled ]; then
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000016 # 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
Jingwen Chencda22c92020-11-23 00:22:30 -050035 # .soong.kati_enabled. That would clobber our real out directory, so we need
36 # to run it in a different one.
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000037 OUT_DIR=${OUT_DIR}/get_build_var get_build_var "$@"
38}
39
Martin Stjernholmc4887432020-11-05 12:59:02 +000040readonly SOONG_OUT=${OUT_DIR}/soong
41mkdir -p ${SOONG_OUT}
42
43# Some Soong build rules may require this, and the failure mode if it's missing
44# is confusing (b/172548608).
45readonly BUILD_NUMBER="$(my_get_build_var BUILD_NUMBER)"
46echo -n ${BUILD_NUMBER} > ${SOONG_OUT}/build_number.txt
47
Martin Stjernholm691503e2020-05-06 22:03:26 +010048readonly PLATFORM_SDK_VERSION="$(my_get_build_var PLATFORM_SDK_VERSION)"
49readonly PLATFORM_VERSION="$(my_get_build_var PLATFORM_VERSION)"
50PLATFORM_VERSION_ALL_CODENAMES="$(my_get_build_var PLATFORM_VERSION_ALL_CODENAMES)"
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000051
52# PLATFORM_VERSION_ALL_CODENAMES is a comma separated list like O,P. We need to
53# turn this into ["O","P"].
Martin Stjernholm691503e2020-05-06 22:03:26 +010054PLATFORM_VERSION_ALL_CODENAMES="${PLATFORM_VERSION_ALL_CODENAMES/,/'","'}"
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000055PLATFORM_VERSION_ALL_CODENAMES="[\"${PLATFORM_VERSION_ALL_CODENAMES}\"]"
56
Ulya Trafimovich37eb6c92020-12-10 14:02:21 +000057# Get the list of missing <uses-library> modules and convert it to a JSON array
58# (quote module names, add comma separator and wrap in brackets).
59MISSING_USES_LIBRARIES="$(my_get_build_var INTERNAL_PLATFORM_MISSING_USES_LIBRARIES)"
60MISSING_USES_LIBRARIES="[$(echo $MISSING_USES_LIBRARIES | sed -e 's/\([^ ]\+\)/\"\1\"/g' -e 's/[ ]\+/, /g')]"
61
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000062# Logic from build/make/core/goma.mk
63if [ "${USE_GOMA}" = true ]; then
64 if [ -n "${GOMA_DIR}" ]; then
65 goma_dir="${GOMA_DIR}"
66 else
67 goma_dir="${HOME}/goma"
68 fi
69 GOMA_CC="${goma_dir}/gomacc"
70 export CC_WRAPPER="${CC_WRAPPER}${CC_WRAPPER:+ }${GOMA_CC}"
71 export CXX_WRAPPER="${CXX_WRAPPER}${CXX_WRAPPER:+ }${GOMA_CC}"
72 export JAVAC_WRAPPER="${JAVAC_WRAPPER}${JAVAC_WRAPPER:+ }${GOMA_CC}"
73else
74 USE_GOMA=false
75fi
76
Martin Stjernholm691503e2020-05-06 22:03:26 +010077readonly SOONG_VARS=${SOONG_OUT}/soong.variables
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000078
Martin Stjernholm691503e2020-05-06 22:03:26 +010079# Aml_abis: true
80# - This flag configures Soong to compile for all architectures required for
81# Mainline modules.
82# CrossHost: linux_bionic
83# CrossHostArch: x86_64
84# - Enable Bionic on host as ART needs prebuilts for it.
Martin Stjernholmed623ea2020-12-15 02:55:55 +000085# VendorVars.art_mdoule.source_build
86# - TODO(b/172480615): Change default to false when platform uses ART Module
87# prebuilts by default.
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000088cat > ${SOONG_VARS}.new << EOF
89{
Martin Stjernholmc4887432020-11-05 12:59:02 +000090 "BuildNumberFile": "build_number.txt",
91
Martin Stjernholm6f8fecd2020-12-14 15:06:22 +000092 "Platform_version_name": "${PLATFORM_VERSION}",
Martin Stjernholmc1ecc432019-11-15 15:00:31 +000093 "Platform_sdk_version": ${PLATFORM_SDK_VERSION},
94 "Platform_sdk_codename": "${PLATFORM_VERSION}",
95 "Platform_version_active_codenames": ${PLATFORM_VERSION_ALL_CODENAMES},
96
97 "DeviceName": "generic_arm64",
98 "HostArch": "x86_64",
Nicolas Geoffrayabdc8c52020-03-24 11:39:06 +000099 "HostSecondaryArch": "x86",
Nicolas Geoffray71233e42020-04-25 16:25:21 +0100100 "CrossHost": "linux_bionic",
101 "CrossHostArch": "x86_64",
Martin Stjernholmc1ecc432019-11-15 15:00:31 +0000102 "Aml_abis": true,
103
Martin Stjernholm2829f6c2020-08-11 01:41:20 +0100104 "Allow_missing_dependencies": ${SOONG_ALLOW_MISSING_DEPENDENCIES:-false},
105 "Unbundled_build": ${TARGET_BUILD_UNBUNDLED:-false},
Martin Stjernholmf3713812020-12-01 18:00:52 +0000106 "UseGoma": ${USE_GOMA},
107
108 "VendorVars": {
109 "art_module": {
Martin Stjernholmed623ea2020-12-15 02:55:55 +0000110 "source_build": "${ENABLE_ART_SOURCE_BUILD:-true}"
Martin Stjernholmf3713812020-12-01 18:00:52 +0000111 }
Ulya Trafimovich37eb6c92020-12-10 14:02:21 +0000112 },
113
114 "MissingUsesLibraries": ${MISSING_USES_LIBRARIES}
Martin Stjernholmc1ecc432019-11-15 15:00:31 +0000115}
116EOF
117
118if [ -f ${SOONG_VARS} ] && cmp -s ${SOONG_VARS} ${SOONG_VARS}.new; then
119 # Don't touch soong.variables if we don't have to, to avoid Soong rebuilding
120 # the ninja file when it isn't necessary.
121 rm ${SOONG_VARS}.new
122else
123 mv ${SOONG_VARS}.new ${SOONG_VARS}
124fi
125
Nicolas Geoffray7cad0f82020-04-28 15:53:42 +0100126# We use force building LLVM components flag (even though we actually don't
127# compile them) because we don't have bionic host prebuilts
128# for them.
Martin Stjernholm691503e2020-05-06 22:03:26 +0100129export FORCE_BUILD_LLVM_COMPONENTS=true
130
131m --skip-make "$@"