blob: ec6ff5d383d6e54ab2472accb67b9a88fdeb764b [file] [log] [blame]
Roland Levillain72f67742019-03-06 15:48:08 +00001#! /bin/bash
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +01002#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Orion Hodson44ab2cd2019-10-08 10:17:05 +010017set -e
18
Martin Stjernholmfa37ba22020-09-01 18:54:06 +010019shopt -s failglob
20
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010021if [ ! -d art ]; then
22 echo "Script needs to be run at the root of the android tree"
23 exit 1
24fi
25
Nicolas Geoffrayc631a242020-08-05 15:52:31 +010026TARGET_ARCH=$(source build/envsetup.sh > /dev/null; get_build_var TARGET_ARCH)
Colin Crosse0ef0a82017-07-27 21:29:18 +000027
Fredrik Roubertad9c4a32016-11-11 19:28:18 -080028# Logic for setting out_dir from build/make/core/envsetup.mk:
29if [[ -z $OUT_DIR ]]; then
30 if [[ -z $OUT_DIR_COMMON_BASE ]]; then
31 out_dir=out
32 else
33 out_dir=${OUT_DIR_COMMON_BASE}/${PWD##*/}
34 fi
35else
36 out_dir=${OUT_DIR}
37fi
38
Nicolas Geoffray4b29f382015-10-07 09:28:52 +010039java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES
Alex Light761ee212020-02-19 20:47:43 +000040common_targets="vogar core-tests apache-harmony-jdwp-tests-hostdex jsr166-tests libartpalette-system mockito-target"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010041mode="target"
42j_arg="-j$(nproc)"
Roland Levillainb8b93562015-08-20 17:49:56 +010043showcommands=
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010044make_command=
45
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010046while true; do
47 if [[ "$1" == "--host" ]]; then
48 mode="host"
49 shift
50 elif [[ "$1" == "--target" ]]; then
51 mode="target"
52 shift
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010053 elif [[ "$1" == -j* ]]; then
Nicolas Geoffray667b99e2015-05-29 12:17:06 +010054 j_arg=$1
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010055 shift
Roland Levillainb8b93562015-08-20 17:49:56 +010056 elif [[ "$1" == "--showcommands" ]]; then
57 showcommands="showcommands"
58 shift
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010059 elif [[ "$1" == "" ]]; then
60 break
Andreas Gampe0dcee912017-02-01 22:07:45 -080061 else
62 echo "Unknown options $@"
63 exit 1
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010064 fi
65done
66
Andreas Gampe353d8182017-10-12 10:17:34 -070067# Allow to build successfully in master-art.
Martin Stjernholmfb2967e2020-06-12 15:12:26 +010068extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true"
Andreas Gampe353d8182017-10-12 10:17:34 -070069
Martin Stjernholm69069102020-06-16 13:26:40 +010070# Switch the build system to unbundled mode in the reduced manifest branch.
71# TODO(b/159109002): Clean this up.
72if [ ! -d frameworks/base ]; then
73 extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true"
74fi
75
Martin Stjernholme2f97112020-05-21 14:59:42 +010076apexes=(
77 "com.android.art.testing"
78 "com.android.conscrypt"
79 "com.android.i18n"
80 "com.android.runtime"
81 "com.android.tzdata"
82)
83
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010084if [[ $mode == "host" ]]; then
Alex Light92fc2c02019-07-30 16:15:29 -070085 make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-host-tests $common_targets"
Orion Hodsonf7f85d02019-02-22 16:17:46 +000086 make_command+=" dx-tests junit-host"
Andreas Gampe6c3e1a02017-11-09 10:29:32 -080087 mode_suffix="-host"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010088elif [[ $mode == "target" ]]; then
Evgeny Astigeevich069391e2018-09-05 22:40:57 +010089 if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then
90 echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
Roland Levillainfe3e2bf2018-03-02 16:01:50 +000091 exit 1
92 fi
Alex Light92fc2c02019-07-30 16:15:29 -070093 make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-target-tests $common_targets"
Nicolas Geoffrayc631a242020-08-05 15:52:31 +010094 make_command+=" libnetd_client-target toybox sh libtombstoned_client"
Alex Light219420e2019-12-05 10:20:26 -080095 make_command+=" debuggerd su gdbserver"
Nicolas Geoffrayc69b3f82020-06-22 12:33:38 +000096 # vogar requires the class files for conscrypt and ICU.
97 make_command+=" conscrypt core-icu4j"
Evgeny Astigeevich069391e2018-09-05 22:40:57 +010098 make_command+=" ${ANDROID_PRODUCT_OUT#"${ANDROID_BUILD_TOP}/"}/system/etc/public.libraries.txt"
Martin Stjernholme2f97112020-05-21 14:59:42 +010099 # Targets required to generate a linker configuration for device within the
100 # chroot environment. The *.libraries.txt targets are required by
Martin Stjernholmc3c7dff2020-08-05 22:40:01 +0100101 # the source linkerconfig but not included in the prebuilt one.
102 make_command+=" linkerconfig sanitizer.libraries.txt vndkcorevariant.libraries.txt"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100103 # Additional targets needed for the chroot environment.
Martin Stjernholm4bb9f672020-05-19 01:33:47 +0100104 make_command+=" event-log-tags"
105 # Needed to extract prebuilt APEXes.
106 make_command+=" deapexer"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100107 # Build/install the required APEXes.
108 make_command+=" ${apexes[*]}"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +0100109fi
110
Andreas Gampe6c3e1a02017-11-09 10:29:32 -0800111mode_specific_libraries="libjavacoretests libjdwp libwrapagentproperties libwrapagentpropertiesd"
112for LIB in ${mode_specific_libraries} ; do
113 make_command+=" $LIB${mode_suffix}"
114done
115
116
Nicolas Geoffrayaadc9862015-09-29 14:56:31 +0100117echo "Executing $make_command"
Nicolas Geoffraya8e8cdf2018-10-16 09:44:58 +0100118# Disable path restrictions to enable luci builds using vpython.
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000119eval "$make_command"
Roland Levillain79975902019-09-16 18:00:29 +0100120
Roland Levillain79975902019-09-16 18:00:29 +0100121if [[ $mode == "target" ]]; then
Martin Stjernholme2f97112020-05-21 14:59:42 +0100122 if [[ -z "${ANDROID_HOST_OUT}" ]]; then
123 echo "ANDROID_HOST_OUT environment variable is empty; using $out_dir/host/linux-x86"
124 ANDROID_HOST_OUT=$out_dir/host/linux-x86
125 fi
126
127 # Extract prebuilt APEXes.
128 debugfs=$ANDROID_HOST_OUT/bin/debugfs_static
129 for apex in ${apexes[@]}; do
130 dir="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
131 file="$ANDROID_PRODUCT_OUT/system/apex/${apex}.apex"
132 if [ -f "${file}" ]; then
133 echo "Extracting APEX file: ${apex}"
134 rm -rf $dir
135 mkdir -p $dir
136 $ANDROID_HOST_OUT/bin/deapexer --debugfs_path $debugfs extract $file $dir
137 fi
138 done
139
Nicolas Geoffrayc631a242020-08-05 15:52:31 +0100140 # Replace stub libraries with implemenation libraries: because we do chroot
141 # testing, we need to install an implementation of the libraries (and cannot
142 # rely on the one already installed on the device, if the device is post R and
143 # has it).
144 implementation_libs="libartpalette-system.so"
145 if [ -d prebuilts/runtime/mainline/platform/impl ]; then
146 if [[ $TARGET_ARCH = arm* ]]; then
147 arch32=arm
148 arch64=arm64
149 else
150 arch32=x86
151 arch64=x86_64
152 fi
153 for so in $implementation_libs; do
154 if [ -d "$ANDROID_PRODUCT_OUT/system/lib" ]; then
155 cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch32/$so $ANDROID_PRODUCT_OUT/system/lib/$so"
156 echo "Executing $cmd"
157 eval "$cmd"
158 fi
159 if [ -d "$ANDROID_PRODUCT_OUT/system/lib64" ]; then
160 cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch64/$so $ANDROID_PRODUCT_OUT/system/lib64/$so"
161 echo "Executing $cmd"
162 eval "$cmd"
163 fi
164 done
165 fi
166
Orion Hodson3a809c82020-01-03 14:53:14 +0000167 # Create canonical name -> file name symlink in the symbol directory for the
168 # Testing ART APEX.
169 #
170 # This mimics the logic from `art/Android.mk`. We made the choice not to
171 # implement this in `art/Android.mk`, as the Testing ART APEX is a test artifact
172 # that should never ship with an actual product, and we try to keep it out of
173 # standard build recipes
174 #
175 # TODO(b/141004137, b/129534335): Remove this, expose the Testing ART APEX in
176 # the `art/Android.mk` build logic, and add absence checks (e.g. in
177 # `build/make/core/main.mk`) to prevent the Testing ART APEX from ending up in a
178 # system image.
Roland Levillain79975902019-09-16 18:00:29 +0100179 target_out_unstripped="$ANDROID_PRODUCT_OUT/symbols"
180 link_name="$target_out_unstripped/apex/com.android.art"
181 link_command="mkdir -p $(dirname "$link_name") && ln -sf com.android.art.testing \"$link_name\""
182 echo "Executing $link_command"
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000183 eval "$link_command"
Orion Hodson3a809c82020-01-03 14:53:14 +0000184
185 # Temporary fix for libjavacrypto.so dependencies in libcore and jvmti tests (b/147124225).
Martin Stjernholme2f97112020-05-21 14:59:42 +0100186 conscrypt_dir="$ANDROID_PRODUCT_OUT/system/apex/com.android.conscrypt"
Orion Hodson3a809c82020-01-03 14:53:14 +0000187 conscrypt_libs="libjavacrypto.so libcrypto.so libssl.so"
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100188 if [ ! -d "${conscrypt_dir}" ]; then
189 echo -e "Missing conscrypt APEX in build output: ${conscrypt_dir}"
Orion Hodson3a809c82020-01-03 14:53:14 +0000190 exit 1
191 fi
Nicolas Geoffray81673f02020-04-22 16:43:54 +0100192 if [ ! -f "${conscrypt_dir}/javalib/conscrypt.jar" ]; then
193 echo -e "Missing conscrypt jar in build output: ${conscrypt_dir}"
194 exit 1
195 fi
Orion Hodson3a809c82020-01-03 14:53:14 +0000196 for l in lib lib64; do
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100197 if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l" ]; then
Orion Hodson3a809c82020-01-03 14:53:14 +0000198 continue
199 fi
200 for so in $conscrypt_libs; do
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100201 src="${conscrypt_dir}/${l}/${so}"
Orion Hodson3a809c82020-01-03 14:53:14 +0000202 dst="$ANDROID_PRODUCT_OUT/system/${l}/${so}"
203 if [ "${src}" -nt "${dst}" ]; then
204 cmd="cp -p \"${src}\" \"${dst}\""
205 echo "Executing $cmd"
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000206 eval "$cmd"
Orion Hodson3a809c82020-01-03 14:53:14 +0000207 fi
208 done
209 done
Martin Stjernholme2f97112020-05-21 14:59:42 +0100210
Martin Stjernholmac048ae2020-06-22 14:38:11 +0100211 # TODO(b/159355595): Ensure there is a tzdata in system to avoid warnings on
212 # stderr from Bionic.
213 if [ ! -f $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata ]; then
214 mkdir -p $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo
215 cp $ANDROID_PRODUCT_OUT/system/apex/com.android.tzdata/etc/tz/tzdata \
216 $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata
217 fi
218
Martin Stjernholm4bb9f672020-05-19 01:33:47 +0100219 # Create system symlinks for the Runtime APEX. Normally handled by
220 # installSymlinkToRuntimeApex in soong/cc/binary.go, but we have to replicate
221 # it here since we don't run the install rules for the Runtime APEX.
222 for b in linker{,_asan}{,64}; do
223 echo "Symlinking /apex/com.android.runtime/bin/$b to /system/bin"
224 ln -sf /apex/com.android.runtime/bin/$b $ANDROID_PRODUCT_OUT/system/bin/$b
225 done
Martin Stjernholmfa37ba22020-09-01 18:54:06 +0100226 for d in $ANDROID_PRODUCT_OUT/system/apex/com.android.runtime/lib{,64}/bionic; do
227 if [ -d $d ]; then
228 for p in $d/*; do
229 lib_dir=$(expr $p : '.*/\(lib[0-9]*\)/.*')
230 lib_file=$(basename $p)
231 src=/apex/com.android.runtime/${lib_dir}/bionic/${lib_file}
232 dst=$ANDROID_PRODUCT_OUT/system/${lib_dir}/${lib_file}
233 echo "Symlinking $src into /system/${lib_dir}"
234 mkdir -p $(dirname $dst)
235 ln -sf $src $dst
236 done
237 fi
Martin Stjernholm4bb9f672020-05-19 01:33:47 +0100238 done
239
Martin Stjernholme2f97112020-05-21 14:59:42 +0100240 # Create linker config files. We run linkerconfig on host to avoid problems
241 # building it statically for device in an unbundled tree.
242
Jooyung Hanf97a8592020-06-17 15:19:17 +0900243 # temporary root for linkerconfig
244 linkerconfig_root=$ANDROID_PRODUCT_OUT/art_linkerconfig_root
245
246 rm -rf $linkerconfig_root
247
248 # Linkerconfig reads files from /system/etc
249 mkdir -p $linkerconfig_root/system
250 cp -r $ANDROID_PRODUCT_OUT/system/etc $linkerconfig_root/system
251
Martin Stjernholme2f97112020-05-21 14:59:42 +0100252 # For linkerconfig to pick up the APEXes correctly we need to make them
Jooyung Hanf97a8592020-06-17 15:19:17 +0900253 # available in $linkerconfig_root/apex.
254 mkdir -p $linkerconfig_root/apex
Martin Stjernholme2f97112020-05-21 14:59:42 +0100255 for apex in ${apexes[@]}; do
256 src="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
257 if [[ $apex == com.android.art.* ]]; then
Jooyung Hanf97a8592020-06-17 15:19:17 +0900258 dst="$linkerconfig_root/apex/com.android.art"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100259 else
Jooyung Hanf97a8592020-06-17 15:19:17 +0900260 dst="$linkerconfig_root/apex/${apex}"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100261 fi
262 echo "Copying APEX directory from $src to $dst"
263 rm -rf $dst
264 cp -r $src $dst
265 done
266
Jooyung Hanf97a8592020-06-17 15:19:17 +0900267 # To avoid warnings from linkerconfig when it checks following two partitions
268 mkdir -p $linkerconfig_root/product
269 mkdir -p $linkerconfig_root/system_ext
270
Martin Stjernholme2f97112020-05-21 14:59:42 +0100271 platform_version=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION)
Jooyung Hanf97a8592020-06-17 15:19:17 +0900272 linkerconfig_out=$ANDROID_PRODUCT_OUT/linkerconfig
273 echo "Generating linkerconfig in $linkerconfig_out"
274 rm -rf $linkerconfig_out
275 mkdir -p $linkerconfig_out
276 $ANDROID_HOST_OUT/bin/linkerconfig --target $linkerconfig_out --root $linkerconfig_root --vndk $platform_version
Roland Levillain79975902019-09-16 18:00:29 +0100277fi