blob: 4b08ac331a143c7b874f66e34ffa0ec7126d211b [file] [log] [blame]
Pete Bentley237de412021-01-29 15:14:42 +00001#!/bin/bash -e
2
3# 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
13export OUT_DIR=${OUT_DIR:-out}
14
15if [ -e ${OUT_DIR}/soong/.soong.kati_enabled ]; 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.
21 AML_OUT_DIR=out/aml
22 echo "Avoiding in-make OUT_DIR '${OUT_DIR}' - building in '${AML_OUT_DIR}' instead"
23 OUT_DIR=${AML_OUT_DIR}
24fi
25
26if [ ! -e "build/envsetup.sh" ]; then
27 echo "$0 must be run from the top of the tree"
28 exit 1
29fi
30
31source 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.kati_enabled. That would clobber our real out directory, so we need
36 # to run it in a different one.
37 OUT_DIR=${OUT_DIR}/get_build_var get_build_var "$@"
38}
39
40readonly 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
48readonly 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)"
51
52# PLATFORM_VERSION_ALL_CODENAMES is a comma separated list like O,P. We need to
53# turn this into ["O","P"].
54PLATFORM_VERSION_ALL_CODENAMES="${PLATFORM_VERSION_ALL_CODENAMES/,/'","'}"
55PLATFORM_VERSION_ALL_CODENAMES="[\"${PLATFORM_VERSION_ALL_CODENAMES}\"]"
56
57# 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
62# 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
77readonly SOONG_VARS=${SOONG_OUT}/soong.variables
78
79# 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.
85# VendorVars.art_mdoule.source_build
86# - TODO(b/172480615): Change default to false when platform uses ART Module
87# prebuilts by default.
88cat > ${SOONG_VARS}.new << EOF
89{
90 "BuildNumberFile": "build_number.txt",
91
92 "Platform_version_name": "${PLATFORM_VERSION}",
93 "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",
99 "HostSecondaryArch": "x86",
100 "CrossHost": "linux_bionic",
101 "CrossHostArch": "x86_64",
102 "Aml_abis": true,
103
104 "Allow_missing_dependencies": ${SOONG_ALLOW_MISSING_DEPENDENCIES:-false},
105 "Unbundled_build": ${TARGET_BUILD_UNBUNDLED:-false},
106 "UseGoma": ${USE_GOMA},
107
108 "VendorVars": {
109 "art_module": {
110 "source_build": "${ENABLE_ART_SOURCE_BUILD:-true}"
111 }
112 },
113
114 "MissingUsesLibraries": ${MISSING_USES_LIBRARIES}
115}
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
126# 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.
129export FORCE_BUILD_LLVM_COMPONENTS=true
130
131m --skip-make "$@"