Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1 | #! /bin/bash |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 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 | |
Orion Hodson | 44ab2cd | 2019-10-08 10:17:05 +0100 | [diff] [blame] | 17 | set -e |
| 18 | |
Martin Stjernholm | fa37ba2 | 2020-09-01 18:54:06 +0100 | [diff] [blame^] | 19 | shopt -s failglob |
| 20 | |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 21 | if [ ! -d art ]; then |
| 22 | echo "Script needs to be run at the root of the android tree" |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
Nicolas Geoffray | c631a24 | 2020-08-05 15:52:31 +0100 | [diff] [blame] | 26 | TARGET_ARCH=$(source build/envsetup.sh > /dev/null; get_build_var TARGET_ARCH) |
Colin Cross | e0ef0a8 | 2017-07-27 21:29:18 +0000 | [diff] [blame] | 27 | |
Fredrik Roubert | ad9c4a3 | 2016-11-11 19:28:18 -0800 | [diff] [blame] | 28 | # Logic for setting out_dir from build/make/core/envsetup.mk: |
| 29 | if [[ -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 |
| 35 | else |
| 36 | out_dir=${OUT_DIR} |
| 37 | fi |
| 38 | |
Nicolas Geoffray | 4b29f38 | 2015-10-07 09:28:52 +0100 | [diff] [blame] | 39 | java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES |
Alex Light | 761ee21 | 2020-02-19 20:47:43 +0000 | [diff] [blame] | 40 | common_targets="vogar core-tests apache-harmony-jdwp-tests-hostdex jsr166-tests libartpalette-system mockito-target" |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 41 | mode="target" |
| 42 | j_arg="-j$(nproc)" |
Roland Levillain | b8b9356 | 2015-08-20 17:49:56 +0100 | [diff] [blame] | 43 | showcommands= |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 44 | make_command= |
| 45 | |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 46 | while true; do |
| 47 | if [[ "$1" == "--host" ]]; then |
| 48 | mode="host" |
| 49 | shift |
| 50 | elif [[ "$1" == "--target" ]]; then |
| 51 | mode="target" |
| 52 | shift |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 53 | elif [[ "$1" == -j* ]]; then |
Nicolas Geoffray | 667b99e | 2015-05-29 12:17:06 +0100 | [diff] [blame] | 54 | j_arg=$1 |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 55 | shift |
Roland Levillain | b8b9356 | 2015-08-20 17:49:56 +0100 | [diff] [blame] | 56 | elif [[ "$1" == "--showcommands" ]]; then |
| 57 | showcommands="showcommands" |
| 58 | shift |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 59 | elif [[ "$1" == "" ]]; then |
| 60 | break |
Andreas Gampe | 0dcee91 | 2017-02-01 22:07:45 -0800 | [diff] [blame] | 61 | else |
| 62 | echo "Unknown options $@" |
| 63 | exit 1 |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 64 | fi |
| 65 | done |
| 66 | |
Andreas Gampe | 353d818 | 2017-10-12 10:17:34 -0700 | [diff] [blame] | 67 | # Allow to build successfully in master-art. |
Martin Stjernholm | fb2967e | 2020-06-12 15:12:26 +0100 | [diff] [blame] | 68 | extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true" |
Andreas Gampe | 353d818 | 2017-10-12 10:17:34 -0700 | [diff] [blame] | 69 | |
Martin Stjernholm | 6906910 | 2020-06-16 13:26:40 +0100 | [diff] [blame] | 70 | # Switch the build system to unbundled mode in the reduced manifest branch. |
| 71 | # TODO(b/159109002): Clean this up. |
| 72 | if [ ! -d frameworks/base ]; then |
| 73 | extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true" |
| 74 | fi |
| 75 | |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 76 | apexes=( |
| 77 | "com.android.art.testing" |
| 78 | "com.android.conscrypt" |
| 79 | "com.android.i18n" |
| 80 | "com.android.runtime" |
| 81 | "com.android.tzdata" |
| 82 | ) |
| 83 | |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 84 | if [[ $mode == "host" ]]; then |
Alex Light | 92fc2c0 | 2019-07-30 16:15:29 -0700 | [diff] [blame] | 85 | make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-host-tests $common_targets" |
Orion Hodson | f7f85d0 | 2019-02-22 16:17:46 +0000 | [diff] [blame] | 86 | make_command+=" dx-tests junit-host" |
Andreas Gampe | 6c3e1a0 | 2017-11-09 10:29:32 -0800 | [diff] [blame] | 87 | mode_suffix="-host" |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 88 | elif [[ $mode == "target" ]]; then |
Evgeny Astigeevich | 069391e | 2018-09-05 22:40:57 +0100 | [diff] [blame] | 89 | if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then |
| 90 | echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?' |
Roland Levillain | fe3e2bf | 2018-03-02 16:01:50 +0000 | [diff] [blame] | 91 | exit 1 |
| 92 | fi |
Alex Light | 92fc2c0 | 2019-07-30 16:15:29 -0700 | [diff] [blame] | 93 | make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-target-tests $common_targets" |
Nicolas Geoffray | c631a24 | 2020-08-05 15:52:31 +0100 | [diff] [blame] | 94 | make_command+=" libnetd_client-target toybox sh libtombstoned_client" |
Alex Light | 219420e | 2019-12-05 10:20:26 -0800 | [diff] [blame] | 95 | make_command+=" debuggerd su gdbserver" |
Nicolas Geoffray | c69b3f8 | 2020-06-22 12:33:38 +0000 | [diff] [blame] | 96 | # vogar requires the class files for conscrypt and ICU. |
| 97 | make_command+=" conscrypt core-icu4j" |
Evgeny Astigeevich | 069391e | 2018-09-05 22:40:57 +0100 | [diff] [blame] | 98 | make_command+=" ${ANDROID_PRODUCT_OUT#"${ANDROID_BUILD_TOP}/"}/system/etc/public.libraries.txt" |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 99 | # Targets required to generate a linker configuration for device within the |
| 100 | # chroot environment. The *.libraries.txt targets are required by |
Martin Stjernholm | c3c7dff | 2020-08-05 22:40:01 +0100 | [diff] [blame] | 101 | # the source linkerconfig but not included in the prebuilt one. |
| 102 | make_command+=" linkerconfig sanitizer.libraries.txt vndkcorevariant.libraries.txt" |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 103 | # Additional targets needed for the chroot environment. |
Martin Stjernholm | 4bb9f67 | 2020-05-19 01:33:47 +0100 | [diff] [blame] | 104 | make_command+=" event-log-tags" |
| 105 | # Needed to extract prebuilt APEXes. |
| 106 | make_command+=" deapexer" |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 107 | # Build/install the required APEXes. |
| 108 | make_command+=" ${apexes[*]}" |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 109 | fi |
| 110 | |
Andreas Gampe | 6c3e1a0 | 2017-11-09 10:29:32 -0800 | [diff] [blame] | 111 | mode_specific_libraries="libjavacoretests libjdwp libwrapagentproperties libwrapagentpropertiesd" |
| 112 | for LIB in ${mode_specific_libraries} ; do |
| 113 | make_command+=" $LIB${mode_suffix}" |
| 114 | done |
| 115 | |
| 116 | |
Nicolas Geoffray | aadc986 | 2015-09-29 14:56:31 +0100 | [diff] [blame] | 117 | echo "Executing $make_command" |
Nicolas Geoffray | a8e8cdf | 2018-10-16 09:44:58 +0100 | [diff] [blame] | 118 | # Disable path restrictions to enable luci builds using vpython. |
Roland Levillain | c3f2fe9 | 2020-02-12 19:40:20 +0000 | [diff] [blame] | 119 | eval "$make_command" |
Roland Levillain | 7997590 | 2019-09-16 18:00:29 +0100 | [diff] [blame] | 120 | |
Roland Levillain | 7997590 | 2019-09-16 18:00:29 +0100 | [diff] [blame] | 121 | if [[ $mode == "target" ]]; then |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 122 | 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 Geoffray | c631a24 | 2020-08-05 15:52:31 +0100 | [diff] [blame] | 140 | # 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 Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 167 | # 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 Levillain | 7997590 | 2019-09-16 18:00:29 +0100 | [diff] [blame] | 179 | 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 Levillain | c3f2fe9 | 2020-02-12 19:40:20 +0000 | [diff] [blame] | 183 | eval "$link_command" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 184 | |
| 185 | # Temporary fix for libjavacrypto.so dependencies in libcore and jvmti tests (b/147124225). |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 186 | conscrypt_dir="$ANDROID_PRODUCT_OUT/system/apex/com.android.conscrypt" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 187 | conscrypt_libs="libjavacrypto.so libcrypto.so libssl.so" |
Nicolas Geoffray | cb62cd8 | 2020-04-03 12:17:50 +0100 | [diff] [blame] | 188 | if [ ! -d "${conscrypt_dir}" ]; then |
| 189 | echo -e "Missing conscrypt APEX in build output: ${conscrypt_dir}" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 190 | exit 1 |
| 191 | fi |
Nicolas Geoffray | 81673f0 | 2020-04-22 16:43:54 +0100 | [diff] [blame] | 192 | 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 Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 196 | for l in lib lib64; do |
Nicolas Geoffray | cb62cd8 | 2020-04-03 12:17:50 +0100 | [diff] [blame] | 197 | if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l" ]; then |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 198 | continue |
| 199 | fi |
| 200 | for so in $conscrypt_libs; do |
Nicolas Geoffray | cb62cd8 | 2020-04-03 12:17:50 +0100 | [diff] [blame] | 201 | src="${conscrypt_dir}/${l}/${so}" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 202 | dst="$ANDROID_PRODUCT_OUT/system/${l}/${so}" |
| 203 | if [ "${src}" -nt "${dst}" ]; then |
| 204 | cmd="cp -p \"${src}\" \"${dst}\"" |
| 205 | echo "Executing $cmd" |
Roland Levillain | c3f2fe9 | 2020-02-12 19:40:20 +0000 | [diff] [blame] | 206 | eval "$cmd" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 207 | fi |
| 208 | done |
| 209 | done |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 210 | |
Martin Stjernholm | ac048ae | 2020-06-22 14:38:11 +0100 | [diff] [blame] | 211 | # 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 Stjernholm | 4bb9f67 | 2020-05-19 01:33:47 +0100 | [diff] [blame] | 219 | # 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 Stjernholm | fa37ba2 | 2020-09-01 18:54:06 +0100 | [diff] [blame^] | 226 | 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 Stjernholm | 4bb9f67 | 2020-05-19 01:33:47 +0100 | [diff] [blame] | 238 | done |
| 239 | |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 240 | # Create linker config files. We run linkerconfig on host to avoid problems |
| 241 | # building it statically for device in an unbundled tree. |
| 242 | |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 243 | # 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 Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 252 | # For linkerconfig to pick up the APEXes correctly we need to make them |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 253 | # available in $linkerconfig_root/apex. |
| 254 | mkdir -p $linkerconfig_root/apex |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 255 | for apex in ${apexes[@]}; do |
| 256 | src="$ANDROID_PRODUCT_OUT/system/apex/${apex}" |
| 257 | if [[ $apex == com.android.art.* ]]; then |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 258 | dst="$linkerconfig_root/apex/com.android.art" |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 259 | else |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 260 | dst="$linkerconfig_root/apex/${apex}" |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 261 | fi |
| 262 | echo "Copying APEX directory from $src to $dst" |
| 263 | rm -rf $dst |
| 264 | cp -r $src $dst |
| 265 | done |
| 266 | |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 267 | # 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 Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 271 | platform_version=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION) |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 272 | 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 Levillain | 7997590 | 2019-09-16 18:00:29 +0100 | [diff] [blame] | 277 | fi |