1#! /bin/bash 2# 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 17set -e 18 19export LC_ALL=C # Generic simple locale 20 21. "$(dirname $0)/buildbot-utils.sh" 22 23shopt -s failglob 24 25if [ ! -d art ]; then 26 msgerror "Script needs to be run at the root of the Android tree" 27 exit 1 28fi 29 30# Logic for setting out_dir from build/make/core/envsetup.mk: 31if [[ -z $OUT_DIR ]]; then 32 if [[ -z $OUT_DIR_COMMON_BASE ]]; then 33 out_dir=out 34 else 35 out_dir=${OUT_DIR_COMMON_BASE}/${PWD##*/} 36 fi 37else 38 out_dir=${OUT_DIR} 39fi 40 41# On master-art, we need to copy ART-local riscv64 prebuilts for conscrypt and 42# statsd into their own repositories, as mainline doesn't support riscv64 yet. 43# Android.bp file changes are stored as patch files which need to be applied 44# afterwards. 45# 46# TODO(b/286551985): Remove this after riscv64 support is added to mainline. 47if [[ $TARGET_ARCH = "riscv64" && ! ( -d frameworks/base ) ]]; then 48 msginfo "Copying prebuilt dependencies for riscv64" 49 cp -u -r prebuilts/runtime/mainline/local_riscv64/prebuilts/module_sdk/conscrypt \ 50 prebuilts/module_sdk 51 cp -u -r prebuilts/runtime/mainline/local_riscv64/prebuilts/module_sdk/StatsD \ 52 prebuilts/module_sdk 53 for patch_file in $(find prebuilts/module_sdk -name Android.bp.patch) ; do 54 bp_file=${patch_file%.patch} 55 # Only apply the patches if they haven't been applied already. Assume the 56 # patch files contain the bug number, and look for that. 57 if grep -q b/286551985 $bp_file ; then 58 msginfo "Patch for riscv64 already present in $bp_file" 59 else 60 patch -f $bp_file < $patch_file 61 fi 62 done 63fi 64 65java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES 66common_targets="vogar core-tests core-ojtests apache-harmony-jdwp-tests-hostdex jsr166-tests mockito-target" 67# These build targets have different names on device and host. 68specific_targets="libjavacoretests libwrapagentproperties libwrapagentpropertiesd" 69build_host="no" 70build_target="no" 71installclean="no" 72skip_run_tests_build="no" 73j_arg="-j$(nproc)" 74showcommands= 75make_command= 76 77while true; do 78 if [[ "$1" == "--host" ]]; then 79 build_host="yes" 80 shift 81 elif [[ "$1" == "--target" ]]; then 82 build_target="yes" 83 shift 84 elif [[ "$1" == "--installclean" ]]; then 85 installclean="yes" 86 shift 87 elif [[ "$1" == "--skip-run-tests-build" ]]; then 88 skip_run_tests_build="yes" 89 shift 90 elif [[ "$1" == -j* ]]; then 91 j_arg=$1 92 shift 93 elif [[ "$1" == "--showcommands" ]]; then 94 showcommands="showcommands" 95 shift 96 elif [[ "$1" == "--dist" ]]; then 97 common_targets="$common_targets dist" 98 shift 99 elif [[ "$1" == "" ]]; then 100 break 101 else 102 msgerror "Unknown options: $@" 103 exit 1 104 fi 105done 106 107# If neither was selected, build both by default. 108if [[ $build_host == "no" ]] && [[ $build_target == "no" ]]; then 109 build_host="yes" 110 build_target="yes" 111fi 112 113if [ -d frameworks/base ]; then 114 # In full manifest branches, build the implementation libraries from source 115 # instead of using prebuilts. 116 common_targets="$common_targets" 117else 118 # Necessary to build successfully in master-art. 119 extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true" 120 # Switch the build system to unbundled mode in the reduced manifest branch. 121 extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true" 122fi 123 124apexes=( 125 "com.android.art.testing" 126 "com.android.conscrypt" 127 "com.android.i18n" 128 "com.android.runtime" 129 "com.android.tzdata" 130 "art_fake_com.android.os.statsd" 131) 132 133override_apex_name() { 134 if [[ $1 == "com.android.art.testing" ]]; then 135 echo "com.android.art" 136 elif [[ $1 == "art_fake_com.android.os.statsd" ]]; then 137 echo "com.android.os.statsd" 138 else 139 echo $1 140 fi 141} 142 143make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands $common_targets" 144if [[ $build_host == "yes" ]]; then 145 make_command+=" build-art-host-gtests" 146 test $skip_run_tests_build == "yes" || make_command+=" build-art-host-run-tests" 147 make_command+=" dx-tests junit-host libjdwp-host" 148 for LIB in ${specific_targets} ; do 149 make_command+=" $LIB-host" 150 done 151fi 152if [[ $build_target == "yes" ]]; then 153 if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then 154 msgerror 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?' 155 exit 1 156 fi 157 make_command+=" build-art-target-gtests" 158 test $skip_run_tests_build == "yes" || make_command+=" build-art-target-run-tests" 159 make_command+=" debuggerd sh su toybox" 160 make_command+=" libartpalette_fake art_fake_heapprofd_client_api" 161 # Runtime dependencies in the platform. 162 # These are built to go into system/lib(64) to be dlopen'ed. 163 # "libnetd_client.so" is used by bionic to perform network operations, which 164 # is needed in Libcore tests. 165 make_command+=" libnetd_client-target" 166 # Stubs for other APEX SDKs, for use by vogar. Referenced from DEVICE_JARS in 167 # external/vogar/src/vogar/ModeId.java. 168 # Note these go into out/target/common/obj/JAVA_LIBRARIES which isn't removed 169 # by "m installclean". 170 make_command+=" i18n.module.public.api.stubs conscrypt.module.public.api.stubs" 171 # Targets required to generate a linker configuration for device within the 172 # chroot environment. The *.libraries.txt targets are required by 173 # the source linkerconfig but not included in the prebuilt one. 174 make_command+=" linkerconfig conv_linker_config sanitizer.libraries.txt llndk.libraries.txt" 175 # Additional targets needed for the chroot environment. 176 make_command+=" event-log-tags" 177 # Needed to extract prebuilt APEXes. 178 make_command+=" deapexer" 179 # Needed to generate the primary boot image for testing. 180 make_command+=" generate-boot-image" 181 # Build/install the required APEXes. 182 make_command+=" ${apexes[*]}" 183 make_command+=" ${specific_targets}" 184 185 # Although the simulator is run on the host, we reuse the target build to 186 # build the target run tests on the host. 187 if [[ -n "${ART_USE_SIMULATOR}" ]]; then 188 # Build any simulator specific components, such as a target boot image, on 189 # the host. 190 make_command+=" build-art-simulator" 191 fi 192fi 193 194if [[ $installclean == "yes" ]]; then 195 msginfo "Perform installclean" 196 ANDROID_QUIET_BUILD=true build/soong/soong_ui.bash --make-mode $extra_args installclean 197 # The common java library directory is not cleaned up by installclean. Do that 198 # explicitly to not overcache them in incremental builds. 199 rm -rf $java_libraries_dir 200else 201 msgwarning "Missing --installclean argument to buildbot-build.sh" 202 msgwarning "This is usually ok, but may cause rare odd failures." 203 echo "" 204fi 205 206msginfo "Executing" "$make_command" 207# Disable path restrictions to enable luci builds using vpython. 208eval "$make_command" 209 210if [[ $build_target == "yes" ]]; then 211 if [[ -z "${ANDROID_HOST_OUT}" ]]; then 212 msgwarning "ANDROID_HOST_OUT environment variable is empty; using $out_dir/host/linux-x86" 213 ANDROID_HOST_OUT=$out_dir/host/linux-x86 214 fi 215 216 # Use fake implementations to prevent chroot tests from talking to the platform (e.g., through 217 # libartpalette). 218 for l in lib lib64; do 219 if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l/art_fake" ]; then 220 continue 221 fi 222 for lib in libartpalette-system heapprofd_client_api; do 223 cmd="cp -p \"$ANDROID_PRODUCT_OUT/system/$l/art_fake/$lib.so\" \"$ANDROID_PRODUCT_OUT/system/$l/$lib.so\"" 224 msginfo "Executing" "$cmd" 225 eval "$cmd" 226 done 227 done 228 229 # Extract prebuilt APEXes. 230 debugfs=$ANDROID_HOST_OUT/bin/debugfs_static 231 fsckerofs=$ANDROID_HOST_OUT/bin/fsck.erofs 232 for apex in ${apexes[@]}; do 233 dir="$ANDROID_PRODUCT_OUT/system/apex/${apex}" 234 apexbase="$ANDROID_PRODUCT_OUT/system/apex/${apex}" 235 unset file 236 if [ -f "${apexbase}.apex" ]; then 237 file="${apexbase}.apex" 238 elif [ -f "${apexbase}.capex" ]; then 239 file="${apexbase}.capex" 240 fi 241 if [ -n "${file}" ]; then 242 msginfo "Extracting APEX file:" "${file}" 243 rm -rf $dir 244 mkdir -p $dir 245 $ANDROID_HOST_OUT/bin/deapexer --debugfs_path $debugfs --fsckerofs_path $fsckerofs \ 246 extract $file $dir 247 fi 248 done 249 250 # Create canonical name -> file name symlink in the symbol directory for the 251 # Testing ART APEX. 252 # 253 # This mimics the logic from `art/Android.mk`. We made the choice not to 254 # implement this in `art/Android.mk`, as the Testing ART APEX is a test artifact 255 # that should never ship with an actual product, and we try to keep it out of 256 # standard build recipes 257 # 258 # TODO(b/141004137, b/129534335): Remove this, expose the Testing ART APEX in 259 # the `art/Android.mk` build logic, and add absence checks (e.g. in 260 # `build/make/core/main.mk`) to prevent the Testing ART APEX from ending up in a 261 # system image. 262 target_out_unstripped="$ANDROID_PRODUCT_OUT/symbols" 263 link_name="$target_out_unstripped/apex/com.android.art" 264 link_command="mkdir -p $(dirname "$link_name") && ln -sf com.android.art.testing \"$link_name\"" 265 msginfo "Executing" "$link_command" 266 eval "$link_command" 267 268 # Temporary fix for libjavacrypto.so dependencies in libcore and jvmti tests (b/147124225). 269 conscrypt_dir="$ANDROID_PRODUCT_OUT/system/apex/com.android.conscrypt" 270 conscrypt_libs="libjavacrypto.so libcrypto.so libssl.so" 271 if [ ! -d "${conscrypt_dir}" ]; then 272 msgerror "Missing conscrypt APEX in build output: ${conscrypt_dir}" 273 exit 1 274 fi 275 if [ ! -f "${conscrypt_dir}/javalib/conscrypt.jar" ]; then 276 msgerror "Missing conscrypt jar in build output: ${conscrypt_dir}" 277 exit 1 278 fi 279 for l in lib lib64; do 280 if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l" ]; then 281 continue 282 fi 283 for so in $conscrypt_libs; do 284 src="${conscrypt_dir}/${l}/${so}" 285 dst="$ANDROID_PRODUCT_OUT/system/${l}/${so}" 286 if [ "${src}" -nt "${dst}" ]; then 287 cmd="cp -p \"${src}\" \"${dst}\"" 288 msginfo "Executing" "$cmd" 289 eval "$cmd" 290 fi 291 done 292 done 293 294 # TODO(b/159355595): Ensure there is a tzdata in system to avoid warnings on 295 # stderr from Bionic. 296 if [ ! -f $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata ]; then 297 mkdir -p $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo 298 cp $ANDROID_PRODUCT_OUT/system/apex/com.android.tzdata/etc/tz/tzdata \ 299 $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata 300 fi 301 302 # Create system symlinks for the Runtime APEX. Normally handled by 303 # installSymlinkToRuntimeApex in soong/cc/binary.go, but we have to replicate 304 # it here since we don't run the install rules for the Runtime APEX. 305 for b in linker{,_asan}{,64}; do 306 msginfo "Symlinking" "/apex/com.android.runtime/bin/$b to /system/bin" 307 ln -sf /apex/com.android.runtime/bin/$b $ANDROID_PRODUCT_OUT/system/bin/$b 308 done 309 for d in $ANDROID_PRODUCT_OUT/system/apex/com.android.runtime/lib{,64}/bionic; do 310 if [ -d $d ]; then 311 for p in $d/*; do 312 lib_dir=$(expr $p : '.*/\(lib[0-9]*\)/.*') 313 lib_file=$(basename $p) 314 src=/apex/com.android.runtime/${lib_dir}/bionic/${lib_file} 315 dst=$ANDROID_PRODUCT_OUT/system/${lib_dir}/${lib_file} 316 msginfo "Symlinking" "$src into /system/${lib_dir}" 317 mkdir -p $(dirname $dst) 318 ln -sf $src $dst 319 done 320 fi 321 done 322 323 # Create linker config files. We run linkerconfig on host to avoid problems 324 # building it statically for device in an unbundled tree. 325 326 # temporary root for linkerconfig 327 linkerconfig_root=$ANDROID_PRODUCT_OUT/art_linkerconfig_root 328 system_linker_config_pb=$linkerconfig_root/system/etc/linker.config.pb 329 330 rm -rf $linkerconfig_root 331 332 # Linkerconfig reads files from /system/etc 333 mkdir -p $linkerconfig_root/system 334 cp -r $ANDROID_PRODUCT_OUT/system/etc $linkerconfig_root/system 335 rm -f $system_linker_config_pb # We create our own below 336 337 # Use our smaller public.libraries.txt that contains only the public libraries 338 # pushed to the chroot directory. 339 cp $ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt \ 340 $linkerconfig_root/system/etc/public.libraries.txt 341 342 # For linkerconfig to pick up the APEXes correctly we need to make them 343 # available in $linkerconfig_root/apex. 344 mkdir -p $linkerconfig_root/apex 345 for apex in ${apexes[@]}; do 346 src="$ANDROID_PRODUCT_OUT/system/apex/${apex}" 347 dst="$linkerconfig_root/apex/$(override_apex_name $apex)" 348 msginfo "Copying APEX directory" "from $src to $dst" 349 rm -rf $dst 350 cp -r $src $dst 351 done 352 353 # Linkerconfig also looks at /apex/apex-info-list.xml to check for system APEXes. 354 apex_xml_file=$linkerconfig_root/apex/apex-info-list.xml 355 msginfo "Creating" "$apex_xml_file" 356 cat <<EOF > $apex_xml_file 357<?xml version="1.0" encoding="utf-8"?> 358<apex-info-list> 359EOF 360 for apex in ${apexes[@]}; do 361 apex=$(override_apex_name $apex) 362 cat <<EOF >> $apex_xml_file 363 <apex-info moduleName="${apex}" modulePath="/system/apex/${apex}.apex" preinstalledModulePath="/system/apex/${apex}.apex" versionCode="1" versionName="" isFactory="true" isActive="true"> 364 </apex-info> 365EOF 366 done 367 cat <<EOF >> $apex_xml_file 368</apex-info-list> 369EOF 370 371 # This list needs to be synced with provideLibs in system/etc/linker.config.pb 372 # in the targeted platform image. 373 # TODO(b/186649223): Create a prebuilt for it in platform-mainline-sdk. 374 system_provide_libs=( 375 heapprofd_client_api.so 376 libEGL.so 377 libGLESv1_CM.so 378 libGLESv2.so 379 libGLESv3.so 380 libOpenMAXAL.so 381 libOpenSLES.so 382 libRS.so 383 libaaudio.so 384 libadbd_auth.so 385 libadbd_fs.so 386 libamidi.so 387 libandroid.so 388 libandroid_net.so 389 libartpalette-system.so 390 libbinder_ndk.so 391 libc.so 392 libcamera2ndk.so 393 libcgrouprc.so 394 libclang_rt.asan-i686-android.so 395 libclang_rt.asan-x86_64-android.so 396 libdl.so 397 libdl_android.so 398 libft2.so 399 libincident.so 400 libjnigraphics.so 401 liblog.so 402 libm.so 403 libmediametrics.so 404 libmediandk.so 405 libnativewindow.so 406 libneuralnetworks_packageinfo.so 407 libselinux.so 408 libstdc++.so 409 libsync.so 410 libvndksupport.so 411 libvulkan.so 412 libz.so 413 ) 414 415 msginfo "Encoding linker.config.json" "to $system_linker_config_pb" 416 $ANDROID_HOST_OUT/bin/conv_linker_config proto -s $ANDROID_BUILD_TOP/system/core/rootdir/etc/linker.config.json -o $system_linker_config_pb 417 $ANDROID_HOST_OUT/bin/conv_linker_config append -s $system_linker_config_pb -o $system_linker_config_pb --key "provideLibs" --value "${system_provide_libs[*]}" 418 419 # To avoid warnings from linkerconfig when it checks following two partitions 420 mkdir -p $linkerconfig_root/product 421 mkdir -p $linkerconfig_root/system_ext 422 423 platform_version=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION) 424 linkerconfig_out=$ANDROID_PRODUCT_OUT/linkerconfig 425 msginfo "Generating linkerconfig" "in $linkerconfig_out" 426 rm -rf $linkerconfig_out 427 mkdir -p $linkerconfig_out 428 $ANDROID_HOST_OUT/bin/linkerconfig --target $linkerconfig_out --root $linkerconfig_root 429fi 430