blob: 64a2962b0acdf02fe2f1c6bf9afd4026bde122e6 [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"
David Srbeckyfe1c7b42021-04-23 15:43:51 +010041# These build targets have different names on device and host.
42specific_targets="libjavacoretests libjdwp libwrapagentproperties libwrapagentpropertiesd"
43build_host="no"
44build_target="no"
David Srbecky6de68dd2021-04-27 14:47:27 +010045installclean="yes"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010046j_arg="-j$(nproc)"
Roland Levillainb8b93562015-08-20 17:49:56 +010047showcommands=
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010048make_command=
49
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010050while true; do
51 if [[ "$1" == "--host" ]]; then
David Srbeckyfe1c7b42021-04-23 15:43:51 +010052 build_host="yes"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010053 shift
54 elif [[ "$1" == "--target" ]]; then
David Srbeckyfe1c7b42021-04-23 15:43:51 +010055 build_target="yes"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010056 shift
David Srbecky6de68dd2021-04-27 14:47:27 +010057 elif [[ "$1" == "--no-installclean" ]]; then
58 installclean="no"
59 shift
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010060 elif [[ "$1" == -j* ]]; then
Nicolas Geoffray667b99e2015-05-29 12:17:06 +010061 j_arg=$1
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010062 shift
Roland Levillainb8b93562015-08-20 17:49:56 +010063 elif [[ "$1" == "--showcommands" ]]; then
64 showcommands="showcommands"
65 shift
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010066 elif [[ "$1" == "" ]]; then
67 break
Andreas Gampe0dcee912017-02-01 22:07:45 -080068 else
69 echo "Unknown options $@"
70 exit 1
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010071 fi
72done
73
David Srbeckyfe1c7b42021-04-23 15:43:51 +010074# If neither was selected, build both by default.
75if [[ $build_host == "no" ]] && [[ $build_target == "no" ]]; then
76 build_host="yes"
77 build_target="yes"
78fi
79
Andreas Gampe353d8182017-10-12 10:17:34 -070080# Allow to build successfully in master-art.
Martin Stjernholmfb2967e2020-06-12 15:12:26 +010081extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true"
Andreas Gampe353d8182017-10-12 10:17:34 -070082
Martin Stjernholm69069102020-06-16 13:26:40 +010083# Switch the build system to unbundled mode in the reduced manifest branch.
Martin Stjernholm69069102020-06-16 13:26:40 +010084if [ ! -d frameworks/base ]; then
85 extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true"
86fi
87
Martin Stjernholme2f97112020-05-21 14:59:42 +010088apexes=(
89 "com.android.art.testing"
90 "com.android.conscrypt"
91 "com.android.i18n"
92 "com.android.runtime"
93 "com.android.tzdata"
Eric Holk39d529f2021-02-17 12:48:53 -080094 "com.android.os.statsd"
Martin Stjernholme2f97112020-05-21 14:59:42 +010095)
96
David Srbeckyfe1c7b42021-04-23 15:43:51 +010097make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands $common_targets"
98if [[ $build_host == "yes" ]]; then
99 make_command+=" build-art-host-tests"
Orion Hodsonf7f85d02019-02-22 16:17:46 +0000100 make_command+=" dx-tests junit-host"
David Srbeckyfe1c7b42021-04-23 15:43:51 +0100101 for LIB in ${specific_targets} ; do
102 make_command+=" $LIB-host"
103 done
104fi
105if [[ $build_target == "yes" ]]; then
Evgeny Astigeevich069391e2018-09-05 22:40:57 +0100106 if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then
107 echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
Roland Levillainfe3e2bf2018-03-02 16:01:50 +0000108 exit 1
109 fi
David Srbeckyfe1c7b42021-04-23 15:43:51 +0100110 make_command+=" build-art-target-tests"
Nicolas Geoffrayc631a242020-08-05 15:52:31 +0100111 make_command+=" libnetd_client-target toybox sh libtombstoned_client"
Alex Light219420e2019-12-05 10:20:26 -0800112 make_command+=" debuggerd su gdbserver"
Nicolas Geoffrayc69b3f82020-06-22 12:33:38 +0000113 # vogar requires the class files for conscrypt and ICU.
114 make_command+=" conscrypt core-icu4j"
Evgeny Astigeevich069391e2018-09-05 22:40:57 +0100115 make_command+=" ${ANDROID_PRODUCT_OUT#"${ANDROID_BUILD_TOP}/"}/system/etc/public.libraries.txt"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100116 # Targets required to generate a linker configuration for device within the
117 # chroot environment. The *.libraries.txt targets are required by
Martin Stjernholmc3c7dff2020-08-05 22:40:01 +0100118 # the source linkerconfig but not included in the prebuilt one.
Victor Changd6363c12020-11-26 16:49:46 +0000119 make_command+=" linkerconfig conv_linker_config sanitizer.libraries.txt vndkcorevariant.libraries.txt"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100120 # Additional targets needed for the chroot environment.
Martin Stjernholm4bb9f672020-05-19 01:33:47 +0100121 make_command+=" event-log-tags"
122 # Needed to extract prebuilt APEXes.
123 make_command+=" deapexer"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100124 # Build/install the required APEXes.
125 make_command+=" ${apexes[*]}"
David Srbeckyfe1c7b42021-04-23 15:43:51 +0100126 make_command+=" ${specific_targets}"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +0100127fi
128
David Srbecky6de68dd2021-04-27 14:47:27 +0100129if [[ $installclean == "yes" ]]; then
130 echo "Perform installclean"
131 ANDROID_QUIET_BUILD=true build/soong/soong_ui.bash --make-mode $extra_args installclean
132fi
Andreas Gampe6c3e1a02017-11-09 10:29:32 -0800133
Nicolas Geoffrayaadc9862015-09-29 14:56:31 +0100134echo "Executing $make_command"
Nicolas Geoffraya8e8cdf2018-10-16 09:44:58 +0100135# Disable path restrictions to enable luci builds using vpython.
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000136eval "$make_command"
Roland Levillain79975902019-09-16 18:00:29 +0100137
David Srbeckyfe1c7b42021-04-23 15:43:51 +0100138if [[ $build_target == "yes" ]]; then
Martin Stjernholme2f97112020-05-21 14:59:42 +0100139 if [[ -z "${ANDROID_HOST_OUT}" ]]; then
140 echo "ANDROID_HOST_OUT environment variable is empty; using $out_dir/host/linux-x86"
141 ANDROID_HOST_OUT=$out_dir/host/linux-x86
142 fi
143
144 # Extract prebuilt APEXes.
145 debugfs=$ANDROID_HOST_OUT/bin/debugfs_static
146 for apex in ${apexes[@]}; do
147 dir="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
148 file="$ANDROID_PRODUCT_OUT/system/apex/${apex}.apex"
149 if [ -f "${file}" ]; then
150 echo "Extracting APEX file: ${apex}"
151 rm -rf $dir
152 mkdir -p $dir
153 $ANDROID_HOST_OUT/bin/deapexer --debugfs_path $debugfs extract $file $dir
154 fi
155 done
156
Nicolas Geoffrayc631a242020-08-05 15:52:31 +0100157 # Replace stub libraries with implemenation libraries: because we do chroot
158 # testing, we need to install an implementation of the libraries (and cannot
159 # rely on the one already installed on the device, if the device is post R and
160 # has it).
Martin Stjernholmf2893ad2021-03-09 17:43:59 +0000161 implementation_libs=(
162 "heapprofd_client_api.so"
163 "libartpalette-system.so"
164 "liblog.so"
165 )
Nicolas Geoffrayc631a242020-08-05 15:52:31 +0100166 if [ -d prebuilts/runtime/mainline/platform/impl ]; then
167 if [[ $TARGET_ARCH = arm* ]]; then
168 arch32=arm
169 arch64=arm64
170 else
171 arch32=x86
172 arch64=x86_64
173 fi
Martin Stjernholmf2893ad2021-03-09 17:43:59 +0000174 for so in ${implementation_libs[@]}; do
Nicolas Geoffrayc631a242020-08-05 15:52:31 +0100175 if [ -d "$ANDROID_PRODUCT_OUT/system/lib" ]; then
176 cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch32/$so $ANDROID_PRODUCT_OUT/system/lib/$so"
177 echo "Executing $cmd"
178 eval "$cmd"
179 fi
180 if [ -d "$ANDROID_PRODUCT_OUT/system/lib64" ]; then
181 cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch64/$so $ANDROID_PRODUCT_OUT/system/lib64/$so"
182 echo "Executing $cmd"
183 eval "$cmd"
184 fi
185 done
186 fi
187
Orion Hodson3a809c82020-01-03 14:53:14 +0000188 # Create canonical name -> file name symlink in the symbol directory for the
189 # Testing ART APEX.
190 #
191 # This mimics the logic from `art/Android.mk`. We made the choice not to
192 # implement this in `art/Android.mk`, as the Testing ART APEX is a test artifact
193 # that should never ship with an actual product, and we try to keep it out of
194 # standard build recipes
195 #
196 # TODO(b/141004137, b/129534335): Remove this, expose the Testing ART APEX in
197 # the `art/Android.mk` build logic, and add absence checks (e.g. in
198 # `build/make/core/main.mk`) to prevent the Testing ART APEX from ending up in a
199 # system image.
Roland Levillain79975902019-09-16 18:00:29 +0100200 target_out_unstripped="$ANDROID_PRODUCT_OUT/symbols"
201 link_name="$target_out_unstripped/apex/com.android.art"
202 link_command="mkdir -p $(dirname "$link_name") && ln -sf com.android.art.testing \"$link_name\""
203 echo "Executing $link_command"
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000204 eval "$link_command"
Orion Hodson3a809c82020-01-03 14:53:14 +0000205
206 # Temporary fix for libjavacrypto.so dependencies in libcore and jvmti tests (b/147124225).
Martin Stjernholme2f97112020-05-21 14:59:42 +0100207 conscrypt_dir="$ANDROID_PRODUCT_OUT/system/apex/com.android.conscrypt"
Orion Hodson3a809c82020-01-03 14:53:14 +0000208 conscrypt_libs="libjavacrypto.so libcrypto.so libssl.so"
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100209 if [ ! -d "${conscrypt_dir}" ]; then
210 echo -e "Missing conscrypt APEX in build output: ${conscrypt_dir}"
Orion Hodson3a809c82020-01-03 14:53:14 +0000211 exit 1
212 fi
Nicolas Geoffray81673f02020-04-22 16:43:54 +0100213 if [ ! -f "${conscrypt_dir}/javalib/conscrypt.jar" ]; then
214 echo -e "Missing conscrypt jar in build output: ${conscrypt_dir}"
215 exit 1
216 fi
Orion Hodson3a809c82020-01-03 14:53:14 +0000217 for l in lib lib64; do
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100218 if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l" ]; then
Orion Hodson3a809c82020-01-03 14:53:14 +0000219 continue
220 fi
221 for so in $conscrypt_libs; do
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100222 src="${conscrypt_dir}/${l}/${so}"
Orion Hodson3a809c82020-01-03 14:53:14 +0000223 dst="$ANDROID_PRODUCT_OUT/system/${l}/${so}"
224 if [ "${src}" -nt "${dst}" ]; then
225 cmd="cp -p \"${src}\" \"${dst}\""
226 echo "Executing $cmd"
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000227 eval "$cmd"
Orion Hodson3a809c82020-01-03 14:53:14 +0000228 fi
229 done
230 done
Martin Stjernholme2f97112020-05-21 14:59:42 +0100231
Martin Stjernholmac048ae2020-06-22 14:38:11 +0100232 # TODO(b/159355595): Ensure there is a tzdata in system to avoid warnings on
233 # stderr from Bionic.
234 if [ ! -f $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata ]; then
235 mkdir -p $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo
236 cp $ANDROID_PRODUCT_OUT/system/apex/com.android.tzdata/etc/tz/tzdata \
237 $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata
238 fi
239
Martin Stjernholm4bb9f672020-05-19 01:33:47 +0100240 # Create system symlinks for the Runtime APEX. Normally handled by
241 # installSymlinkToRuntimeApex in soong/cc/binary.go, but we have to replicate
242 # it here since we don't run the install rules for the Runtime APEX.
243 for b in linker{,_asan}{,64}; do
244 echo "Symlinking /apex/com.android.runtime/bin/$b to /system/bin"
245 ln -sf /apex/com.android.runtime/bin/$b $ANDROID_PRODUCT_OUT/system/bin/$b
246 done
Martin Stjernholmfa37ba22020-09-01 18:54:06 +0100247 for d in $ANDROID_PRODUCT_OUT/system/apex/com.android.runtime/lib{,64}/bionic; do
248 if [ -d $d ]; then
249 for p in $d/*; do
250 lib_dir=$(expr $p : '.*/\(lib[0-9]*\)/.*')
251 lib_file=$(basename $p)
252 src=/apex/com.android.runtime/${lib_dir}/bionic/${lib_file}
253 dst=$ANDROID_PRODUCT_OUT/system/${lib_dir}/${lib_file}
254 echo "Symlinking $src into /system/${lib_dir}"
255 mkdir -p $(dirname $dst)
256 ln -sf $src $dst
257 done
258 fi
Martin Stjernholm4bb9f672020-05-19 01:33:47 +0100259 done
260
Martin Stjernholme2f97112020-05-21 14:59:42 +0100261 # Create linker config files. We run linkerconfig on host to avoid problems
262 # building it statically for device in an unbundled tree.
263
Jooyung Hanf97a8592020-06-17 15:19:17 +0900264 # temporary root for linkerconfig
265 linkerconfig_root=$ANDROID_PRODUCT_OUT/art_linkerconfig_root
266
267 rm -rf $linkerconfig_root
268
269 # Linkerconfig reads files from /system/etc
270 mkdir -p $linkerconfig_root/system
271 cp -r $ANDROID_PRODUCT_OUT/system/etc $linkerconfig_root/system
272
Martin Stjernholme2f97112020-05-21 14:59:42 +0100273 # For linkerconfig to pick up the APEXes correctly we need to make them
Jooyung Hanf97a8592020-06-17 15:19:17 +0900274 # available in $linkerconfig_root/apex.
275 mkdir -p $linkerconfig_root/apex
Martin Stjernholme2f97112020-05-21 14:59:42 +0100276 for apex in ${apexes[@]}; do
277 src="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
278 if [[ $apex == com.android.art.* ]]; then
Jooyung Hanf97a8592020-06-17 15:19:17 +0900279 dst="$linkerconfig_root/apex/com.android.art"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100280 else
Jooyung Hanf97a8592020-06-17 15:19:17 +0900281 dst="$linkerconfig_root/apex/${apex}"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100282 fi
283 echo "Copying APEX directory from $src to $dst"
284 rm -rf $dst
285 cp -r $src $dst
286 done
287
Martin Stjernholm7914e892020-09-02 20:47:05 +0100288 # Linkerconfig also looks at /apex/apex-info-list.xml to check for system APEXes.
289 apex_xml_file=$linkerconfig_root/apex/apex-info-list.xml
290 echo "Creating $apex_xml_file"
291 cat <<EOF > $apex_xml_file
292<?xml version="1.0" encoding="utf-8"?>
293<apex-info-list>
294EOF
295 for apex in ${apexes[@]}; do
296 [[ $apex == com.android.art.* ]] && apex=com.android.art
297 cat <<EOF >> $apex_xml_file
298 <apex-info moduleName="${apex}" modulePath="/system/apex/${apex}.apex" preinstalledModulePath="/system/apex/${apex}.apex" versionCode="1" versionName="" isFactory="true" isActive="true">
299 </apex-info>
300EOF
301 done
302 cat <<EOF >> $apex_xml_file
303</apex-info-list>
304EOF
305
Victor Changd6363c12020-11-26 16:49:46 +0000306 system_linker_config_pb=$linkerconfig_root/system/etc/linker.config.pb
Martin Stjernholm98e9a122021-04-25 17:55:31 +0100307 # This list needs to be synced with provideLibs in system/etc/linker.config.pb
308 # in the targeted platform image.
309 # TODO(b/186649223): Create a prebuilt for it in platform-mainline-sdk.
310 system_provide_libs=(
311 heapprofd_client_api.so
312 libEGL.so
313 libGLESv1_CM.so
314 libGLESv2.so
315 libGLESv3.so
316 libOpenMAXAL.so
317 libOpenSLES.so
318 libRS.so
319 libaaudio.so
320 libadbd_auth.so
321 libadbd_fs.so
322 libamidi.so
323 libandroid.so
324 libandroid_net.so
325 libartpalette-system.so
326 libbinder_ndk.so
327 libc.so
328 libcamera2ndk.so
329 libcgrouprc.so
330 libclang_rt.asan-i686-android.so
331 libclang_rt.asan-x86_64-android.so
332 libdl.so
333 libdl_android.so
334 libft2.so
335 libincident.so
336 libjnigraphics.so
337 liblog.so
338 libm.so
339 libmediametrics.so
340 libmediandk.so
341 libnativewindow.so
342 libneuralnetworks_packageinfo.so
343 libselinux.so
344 libstdc++.so
345 libsync.so
346 libvndksupport.so
347 libvulkan.so
348 libz.so
349 )
350
Victor Changd6363c12020-11-26 16:49:46 +0000351 echo "Encoding linker.config.json to $system_linker_config_pb"
Nicolas Geoffray29ce8432020-11-27 09:50:17 +0000352 $ANDROID_HOST_OUT/bin/conv_linker_config proto -s $ANDROID_BUILD_TOP/system/core/rootdir/etc/linker.config.json -o $system_linker_config_pb
Martin Stjernholm98e9a122021-04-25 17:55:31 +0100353 $ANDROID_HOST_OUT/bin/conv_linker_config append -s $system_linker_config_pb -o $system_linker_config_pb --key "provideLibs" --value "${system_provide_libs[*]}"
Victor Changd6363c12020-11-26 16:49:46 +0000354
Jooyung Hanf97a8592020-06-17 15:19:17 +0900355 # To avoid warnings from linkerconfig when it checks following two partitions
356 mkdir -p $linkerconfig_root/product
357 mkdir -p $linkerconfig_root/system_ext
358
Martin Stjernholme2f97112020-05-21 14:59:42 +0100359 platform_version=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION)
Jooyung Hanf97a8592020-06-17 15:19:17 +0900360 linkerconfig_out=$ANDROID_PRODUCT_OUT/linkerconfig
361 echo "Generating linkerconfig in $linkerconfig_out"
362 rm -rf $linkerconfig_out
363 mkdir -p $linkerconfig_out
364 $ANDROID_HOST_OUT/bin/linkerconfig --target $linkerconfig_out --root $linkerconfig_root --vndk $platform_version
Roland Levillain79975902019-09-16 18:00:29 +0100365fi