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 | |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 19 | if [ ! -d art ]; then |
| 20 | echo "Script needs to be run at the root of the android tree" |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
Colin Cross | e0ef0a8 | 2017-07-27 21:29:18 +0000 | [diff] [blame] | 24 | source build/envsetup.sh >&/dev/null # for get_build_var |
| 25 | |
Fredrik Roubert | ad9c4a3 | 2016-11-11 19:28:18 -0800 | [diff] [blame] | 26 | # Logic for setting out_dir from build/make/core/envsetup.mk: |
| 27 | if [[ -z $OUT_DIR ]]; then |
| 28 | if [[ -z $OUT_DIR_COMMON_BASE ]]; then |
| 29 | out_dir=out |
| 30 | else |
| 31 | out_dir=${OUT_DIR_COMMON_BASE}/${PWD##*/} |
| 32 | fi |
| 33 | else |
| 34 | out_dir=${OUT_DIR} |
| 35 | fi |
| 36 | |
Nicolas Geoffray | 4b29f38 | 2015-10-07 09:28:52 +0100 | [diff] [blame] | 37 | java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES |
Alex Light | 761ee21 | 2020-02-19 20:47:43 +0000 | [diff] [blame] | 38 | 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] | 39 | mode="target" |
| 40 | j_arg="-j$(nproc)" |
Roland Levillain | b8b9356 | 2015-08-20 17:49:56 +0100 | [diff] [blame] | 41 | showcommands= |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 42 | make_command= |
| 43 | |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 44 | while true; do |
| 45 | if [[ "$1" == "--host" ]]; then |
| 46 | mode="host" |
| 47 | shift |
| 48 | elif [[ "$1" == "--target" ]]; then |
| 49 | mode="target" |
| 50 | shift |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 51 | elif [[ "$1" == -j* ]]; then |
Nicolas Geoffray | 667b99e | 2015-05-29 12:17:06 +0100 | [diff] [blame] | 52 | j_arg=$1 |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 53 | shift |
Roland Levillain | b8b9356 | 2015-08-20 17:49:56 +0100 | [diff] [blame] | 54 | elif [[ "$1" == "--showcommands" ]]; then |
| 55 | showcommands="showcommands" |
| 56 | shift |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 57 | elif [[ "$1" == "" ]]; then |
| 58 | break |
Andreas Gampe | 0dcee91 | 2017-02-01 22:07:45 -0800 | [diff] [blame] | 59 | else |
| 60 | echo "Unknown options $@" |
| 61 | exit 1 |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 62 | fi |
| 63 | done |
| 64 | |
Andreas Gampe | 353d818 | 2017-10-12 10:17:34 -0700 | [diff] [blame] | 65 | # Allow to build successfully in master-art. |
Martin Stjernholm | fb2967e | 2020-06-12 15:12:26 +0100 | [diff] [blame] | 66 | extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true" |
Andreas Gampe | 353d818 | 2017-10-12 10:17:34 -0700 | [diff] [blame] | 67 | |
Martin Stjernholm | 6906910 | 2020-06-16 13:26:40 +0100 | [diff] [blame] | 68 | # Switch the build system to unbundled mode in the reduced manifest branch. |
| 69 | # TODO(b/159109002): Clean this up. |
| 70 | if [ ! -d frameworks/base ]; then |
| 71 | extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true" |
| 72 | fi |
| 73 | |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 74 | apexes=( |
| 75 | "com.android.art.testing" |
| 76 | "com.android.conscrypt" |
| 77 | "com.android.i18n" |
| 78 | "com.android.runtime" |
| 79 | "com.android.tzdata" |
| 80 | ) |
| 81 | |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 82 | if [[ $mode == "host" ]]; then |
Alex Light | 92fc2c0 | 2019-07-30 16:15:29 -0700 | [diff] [blame] | 83 | 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] | 84 | make_command+=" dx-tests junit-host" |
Andreas Gampe | 6c3e1a0 | 2017-11-09 10:29:32 -0800 | [diff] [blame] | 85 | mode_suffix="-host" |
Nicolas Geoffray | fbeca75 | 2015-05-29 10:54:12 +0100 | [diff] [blame] | 86 | elif [[ $mode == "target" ]]; then |
Evgeny Astigeevich | 069391e | 2018-09-05 22:40:57 +0100 | [diff] [blame] | 87 | if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then |
| 88 | 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] | 89 | exit 1 |
| 90 | fi |
Alex Light | 92fc2c0 | 2019-07-30 16:15:29 -0700 | [diff] [blame] | 91 | make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-target-tests $common_targets" |
Nicolas Geoffray | eed0217 | 2020-05-26 09:54:25 +0100 | [diff] [blame] | 92 | make_command+=" libnetd_client-target toybox sh" |
Alex Light | 219420e | 2019-12-05 10:20:26 -0800 | [diff] [blame] | 93 | make_command+=" debuggerd su gdbserver" |
Nicolas Geoffray | c69b3f8 | 2020-06-22 12:33:38 +0000 | [diff] [blame] | 94 | # vogar requires the class files for conscrypt and ICU. |
| 95 | make_command+=" conscrypt core-icu4j" |
Evgeny Astigeevich | 069391e | 2018-09-05 22:40:57 +0100 | [diff] [blame] | 96 | 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] | 97 | # Targets required to generate a linker configuration for device within the |
| 98 | # chroot environment. The *.libraries.txt targets are required by |
| 99 | # linkerconfig but not included in host_linkerconfig_all_targets. We cannot |
| 100 | # use linkerconfig, because building the device binary statically might not |
| 101 | # work in an unbundled tree. |
| 102 | make_command+=" host_linkerconfig_all_targets sanitizer.libraries.txt vndkcorevariant.libraries.txt" |
| 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 | |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 140 | # Create canonical name -> file name symlink in the symbol directory for the |
| 141 | # Testing ART APEX. |
| 142 | # |
| 143 | # This mimics the logic from `art/Android.mk`. We made the choice not to |
| 144 | # implement this in `art/Android.mk`, as the Testing ART APEX is a test artifact |
| 145 | # that should never ship with an actual product, and we try to keep it out of |
| 146 | # standard build recipes |
| 147 | # |
| 148 | # TODO(b/141004137, b/129534335): Remove this, expose the Testing ART APEX in |
| 149 | # the `art/Android.mk` build logic, and add absence checks (e.g. in |
| 150 | # `build/make/core/main.mk`) to prevent the Testing ART APEX from ending up in a |
| 151 | # system image. |
Roland Levillain | 7997590 | 2019-09-16 18:00:29 +0100 | [diff] [blame] | 152 | target_out_unstripped="$ANDROID_PRODUCT_OUT/symbols" |
| 153 | link_name="$target_out_unstripped/apex/com.android.art" |
| 154 | link_command="mkdir -p $(dirname "$link_name") && ln -sf com.android.art.testing \"$link_name\"" |
| 155 | echo "Executing $link_command" |
Roland Levillain | c3f2fe9 | 2020-02-12 19:40:20 +0000 | [diff] [blame] | 156 | eval "$link_command" |
Roland Levillain | a871d84 | 2020-02-14 15:37:12 +0000 | [diff] [blame] | 157 | # Also provide access to symbols of binaries from the Runtime (Bionic) APEX, |
| 158 | # e.g. to support debugging in GDB. |
| 159 | find "$target_out_unstripped/apex/com.android.runtime/bin" -type f | while read target; do |
| 160 | cmd="ln -sf $target $target_out_unstripped/system/bin/$(basename $target)" |
Alex Light | 219420e | 2019-12-05 10:20:26 -0800 | [diff] [blame] | 161 | echo "Executing $cmd" |
Roland Levillain | c3f2fe9 | 2020-02-12 19:40:20 +0000 | [diff] [blame] | 162 | eval "$cmd" |
Alex Light | 219420e | 2019-12-05 10:20:26 -0800 | [diff] [blame] | 163 | done |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 164 | |
| 165 | # 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] | 166 | conscrypt_dir="$ANDROID_PRODUCT_OUT/system/apex/com.android.conscrypt" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 167 | conscrypt_libs="libjavacrypto.so libcrypto.so libssl.so" |
Nicolas Geoffray | cb62cd8 | 2020-04-03 12:17:50 +0100 | [diff] [blame] | 168 | if [ ! -d "${conscrypt_dir}" ]; then |
| 169 | echo -e "Missing conscrypt APEX in build output: ${conscrypt_dir}" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 170 | exit 1 |
| 171 | fi |
Nicolas Geoffray | 81673f0 | 2020-04-22 16:43:54 +0100 | [diff] [blame] | 172 | if [ ! -f "${conscrypt_dir}/javalib/conscrypt.jar" ]; then |
| 173 | echo -e "Missing conscrypt jar in build output: ${conscrypt_dir}" |
| 174 | exit 1 |
| 175 | fi |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 176 | for l in lib lib64; do |
Nicolas Geoffray | cb62cd8 | 2020-04-03 12:17:50 +0100 | [diff] [blame] | 177 | if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l" ]; then |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 178 | continue |
| 179 | fi |
| 180 | for so in $conscrypt_libs; do |
Nicolas Geoffray | cb62cd8 | 2020-04-03 12:17:50 +0100 | [diff] [blame] | 181 | src="${conscrypt_dir}/${l}/${so}" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 182 | dst="$ANDROID_PRODUCT_OUT/system/${l}/${so}" |
| 183 | if [ "${src}" -nt "${dst}" ]; then |
| 184 | cmd="cp -p \"${src}\" \"${dst}\"" |
| 185 | echo "Executing $cmd" |
Roland Levillain | c3f2fe9 | 2020-02-12 19:40:20 +0000 | [diff] [blame] | 186 | eval "$cmd" |
Orion Hodson | 3a809c8 | 2020-01-03 14:53:14 +0000 | [diff] [blame] | 187 | fi |
| 188 | done |
| 189 | done |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 190 | |
Martin Stjernholm | ac048ae | 2020-06-22 14:38:11 +0100 | [diff] [blame] | 191 | # TODO(b/159355595): Ensure there is a tzdata in system to avoid warnings on |
| 192 | # stderr from Bionic. |
| 193 | if [ ! -f $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata ]; then |
| 194 | mkdir -p $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo |
| 195 | cp $ANDROID_PRODUCT_OUT/system/apex/com.android.tzdata/etc/tz/tzdata \ |
| 196 | $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata |
| 197 | fi |
| 198 | |
Martin Stjernholm | 4bb9f67 | 2020-05-19 01:33:47 +0100 | [diff] [blame] | 199 | # Create system symlinks for the Runtime APEX. Normally handled by |
| 200 | # installSymlinkToRuntimeApex in soong/cc/binary.go, but we have to replicate |
| 201 | # it here since we don't run the install rules for the Runtime APEX. |
| 202 | for b in linker{,_asan}{,64}; do |
| 203 | echo "Symlinking /apex/com.android.runtime/bin/$b to /system/bin" |
| 204 | ln -sf /apex/com.android.runtime/bin/$b $ANDROID_PRODUCT_OUT/system/bin/$b |
| 205 | done |
| 206 | for p in $ANDROID_PRODUCT_OUT/system/apex/com.android.runtime/lib{,64}/bionic/*; do |
| 207 | lib_dir=$(expr $p : '.*/\(lib[0-9]*\)/.*') |
| 208 | lib_file=$(basename $p) |
| 209 | src=/apex/com.android.runtime/${lib_dir}/bionic/${lib_file} |
| 210 | dst=$ANDROID_PRODUCT_OUT/system/${lib_dir}/${lib_file} |
| 211 | echo "Symlinking $src into /system/${lib_dir}" |
| 212 | mkdir -p $(dirname $dst) |
| 213 | ln -sf $src $dst |
| 214 | done |
| 215 | |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 216 | # Create linker config files. We run linkerconfig on host to avoid problems |
| 217 | # building it statically for device in an unbundled tree. |
| 218 | |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 219 | # temporary root for linkerconfig |
| 220 | linkerconfig_root=$ANDROID_PRODUCT_OUT/art_linkerconfig_root |
| 221 | |
| 222 | rm -rf $linkerconfig_root |
| 223 | |
| 224 | # Linkerconfig reads files from /system/etc |
| 225 | mkdir -p $linkerconfig_root/system |
| 226 | cp -r $ANDROID_PRODUCT_OUT/system/etc $linkerconfig_root/system |
| 227 | |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 228 | # 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] | 229 | # available in $linkerconfig_root/apex. |
| 230 | mkdir -p $linkerconfig_root/apex |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 231 | for apex in ${apexes[@]}; do |
| 232 | src="$ANDROID_PRODUCT_OUT/system/apex/${apex}" |
| 233 | if [[ $apex == com.android.art.* ]]; then |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 234 | dst="$linkerconfig_root/apex/com.android.art" |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 235 | else |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 236 | dst="$linkerconfig_root/apex/${apex}" |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 237 | fi |
| 238 | echo "Copying APEX directory from $src to $dst" |
| 239 | rm -rf $dst |
| 240 | cp -r $src $dst |
| 241 | done |
| 242 | |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 243 | # To avoid warnings from linkerconfig when it checks following two partitions |
| 244 | mkdir -p $linkerconfig_root/product |
| 245 | mkdir -p $linkerconfig_root/system_ext |
| 246 | |
Martin Stjernholm | e2f9711 | 2020-05-21 14:59:42 +0100 | [diff] [blame] | 247 | platform_version=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION) |
Jooyung Han | f97a859 | 2020-06-17 15:19:17 +0900 | [diff] [blame] | 248 | linkerconfig_out=$ANDROID_PRODUCT_OUT/linkerconfig |
| 249 | echo "Generating linkerconfig in $linkerconfig_out" |
| 250 | rm -rf $linkerconfig_out |
| 251 | mkdir -p $linkerconfig_out |
| 252 | $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] | 253 | fi |