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