Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1 | #! /bin/bash |
Nicolas Geoffray | b745adc | 2018-10-11 10:30:19 +0100 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2018 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 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 17 | # Push ART artifacts and its dependencies to a chroot directory for on-device testing. |
| 18 | |
| 19 | red='\033[0;31m' |
| 20 | green='\033[0;32m' |
| 21 | yellow='\033[0;33m' |
| 22 | magenta='\033[0;35m' |
| 23 | nc='\033[0m' |
| 24 | |
Nicolas Geoffray | b745adc | 2018-10-11 10:30:19 +0100 | [diff] [blame] | 25 | adb wait-for-device |
| 26 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 27 | if [[ -z "$ANDROID_BUILD_TOP" ]]; then |
| 28 | echo 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?' |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | if [[ -z "$ANDROID_PRODUCT_OUT" ]]; then |
Nicolas Geoffray | b745adc | 2018-10-11 10:30:19 +0100 | [diff] [blame] | 33 | echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?' |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 37 | if [[ -z "$ART_TEST_CHROOT" ]]; then |
| 38 | echo 'ART_TEST_CHROOT environment variable is empty; please set it before running this script.' |
Nicolas Geoffray | b745adc | 2018-10-11 10:30:19 +0100 | [diff] [blame] | 39 | exit 1 |
| 40 | fi |
| 41 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 42 | if [[ "$(build/soong/soong_ui.bash --dumpvar-mode TARGET_FLATTEN_APEX)" != "true" ]]; then |
| 43 | echo -e "${red}This script only works when APEX packages are flattened, but the build" \ |
| 44 | "configuration is set up to use non-flattened APEX packages.${nc}" |
| 45 | echo -e "${magenta}You can force APEX flattening by setting the environment variable" \ |
| 46 | "\`TARGET_FLATTEN_APEX\` to \"true\" before starting the build and running this script.${nc}" |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | # Linker configuration. |
| 51 | # --------------------- |
| 52 | |
| 53 | # Adjust the chroot environment to have it use the system linker configuration |
| 54 | # of the built target ("guest system"), located in `/system/etc` under the |
| 55 | # chroot directory, even if the linker configuration flavor of the "guest |
| 56 | # system" (e.g. legacy configuration) does not match the one of the "host |
| 57 | # system" (e.g. full-VNDK configuration). This is done by renaming the |
| 58 | # configuration file provided by the "guest system" (created according to the |
| 59 | # build target configuration) within the chroot environment, using the name of |
| 60 | # the configuration file expected by the linker (governed by system properties |
| 61 | # of the "host system"). |
| 62 | |
| 63 | # Default linker configuration file name/stem. |
| 64 | ld_config_file_path="/system/etc/ld.config.txt"; |
| 65 | # VNDK-lite linker configuration file name. |
| 66 | ld_config_vndk_lite_file_path="/system/etc/ld.config.vndk_lite.txt"; |
| 67 | |
| 68 | # Find linker configuration path name on the "host system". |
| 69 | # |
| 70 | # The logic here partly replicates (and simplifies) Bionic's linker logic around |
| 71 | # configuration file search (see `get_ld_config_file_path` in |
| 72 | # bionic/linker/linker.cpp). |
| 73 | get_ld_host_system_config_file_path() { |
| 74 | # Check whether the "host device" uses a VNDK-lite linker configuration. |
| 75 | local vndk_lite=$(adb shell getprop "ro.vndk.lite" false) |
| 76 | if [[ "$vndk_lite" = true ]]; then |
| 77 | if adb shell test -f "$ld_config_vndk_lite_file_path"; then |
| 78 | echo "$ld_config_vndk_lite_file_path" |
| 79 | return |
| 80 | fi |
| 81 | fi |
| 82 | # Check the "host device"'s VNDK version, if any. |
| 83 | local vndk_version=$(adb shell getprop "ro.vndk.version") |
| 84 | if [[ -n "$vndk_version" ]] && [[ "$vndk_version" != current ]]; then |
| 85 | # Insert the VNDK version after the last period (and add another period). |
| 86 | local ld_config_file_vdnk_path=$(echo "$ld_config_file_path" \ |
| 87 | | sed -e "s/^\\(.*\\)\\.\\([^.]\\)/\\1.${vndk_version}.\\2/") |
| 88 | if adb shell test -f "$ld_config_file_vdnk_path"; then |
| 89 | echo "$ld_config_file_vdnk_path" |
| 90 | return |
| 91 | fi |
| 92 | else |
| 93 | if adb shell test -f "$ld_config_file_path"; then |
| 94 | echo "$ld_config_file_path" |
| 95 | return |
| 96 | fi |
| 97 | fi |
| 98 | # If all else fails, return the default linker configuration name. |
| 99 | echo -e "${yellow}Cannot find linker configuration; using default path name:" \ |
| 100 | "\`$ld_config_file_path\`${nc}" >&2 |
| 101 | echo "$ld_config_file_path" |
| 102 | return |
| 103 | } |
| 104 | |
| 105 | # Find linker configuration path name on the "guest system". |
| 106 | # |
| 107 | # The logic here tries to "guess" the name of the linker configuration file, |
| 108 | # based on the contents of the build directory. |
| 109 | get_ld_guest_system_config_file_path() { |
| 110 | if [[ -z "$ANDROID_PRODUCT_OUT" ]]; then |
| 111 | echo -e "${red}ANDROID_PRODUCT_OUT environment variable is empty;" \ |
| 112 | "did you forget to run \`lunch\`${nc}?" >&2 |
| 113 | exit 1 |
| 114 | fi |
| 115 | local ld_config_file_location="$ANDROID_PRODUCT_OUT/system/etc" |
| 116 | local ld_config_file_path_number=$(find "$ld_config_file_location" -name "ld.*.txt" | wc -l) |
| 117 | if [[ "$ld_config_file_path_number" -eq 0 ]]; then |
| 118 | echo -e "${red}No linker configuration file found in \`$ld_config_file_location\`${nc}" >&2 |
| 119 | exit 1 |
| 120 | fi |
| 121 | if [[ "$ld_config_file_path_number" -gt 1 ]]; then |
| 122 | echo -e \ |
| 123 | "${red}More than one linker configuration file found in \`$ld_config_file_location\`${nc}" >&2 |
| 124 | exit 1 |
| 125 | fi |
| 126 | # Strip the build prefix to make the path name relative to the "guest root directory". |
| 127 | find "$ld_config_file_location" -name "ld.*.txt" | sed -e "s|^$ANDROID_PRODUCT_OUT||" |
| 128 | } |
| 129 | |
| 130 | |
| 131 | # Synchronization recipe. |
| 132 | # ----------------------- |
| 133 | |
Roland Levillain | 0587b62 | 2019-04-03 14:18:50 +0100 | [diff] [blame] | 134 | # Sync the system directory to the chroot. |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 135 | echo -e "${green}Syncing system directory...${nc}" |
| 136 | adb push "$ANDROID_PRODUCT_OUT/system" "$ART_TEST_CHROOT/" |
Roland Levillain | 0587b62 | 2019-04-03 14:18:50 +0100 | [diff] [blame] | 137 | # Overwrite the default public.libraries.txt file with a smaller one that |
| 138 | # contains only the public libraries pushed to the chroot directory. |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 139 | adb push "$ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt" \ |
| 140 | "$ART_TEST_CHROOT/system/etc/public.libraries.txt" |
Roland Levillain | 0587b62 | 2019-04-03 14:18:50 +0100 | [diff] [blame] | 141 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 142 | echo -e "${green}Activating Runtime APEX...${nc}" |
Roland Levillain | 8d5a215 | 2019-07-02 19:40:28 +0100 | [diff] [blame] | 143 | # Manually "activate" the flattened Testing Runtime APEX by syncing it to the |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 144 | # /apex directory in the chroot. |
| 145 | # |
Roland Levillain | 8d5a215 | 2019-07-02 19:40:28 +0100 | [diff] [blame] | 146 | # We copy the files from `/system/apex/com.android.runtime.testing` to |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 147 | # `/apex/com.android.runtime` in the chroot directory, instead of simply using a |
| 148 | # symlink, as Bionic's linker relies on the real path name of a binary |
| 149 | # (e.g. `/apex/com.android.runtime/bin/dex2oat`) to select the linker |
| 150 | # configuration. |
| 151 | # |
| 152 | # TODO: Handle the case of build targets using non-flatted APEX packages. |
| 153 | # As a workaround, one can run `export TARGET_FLATTEN_APEX=true` before building |
| 154 | # a target to have its APEX packages flattened. |
| 155 | adb shell rm -rf "$ART_TEST_CHROOT/apex/com.android.runtime" |
Roland Levillain | 8d5a215 | 2019-07-02 19:40:28 +0100 | [diff] [blame] | 156 | adb shell cp -a "$ART_TEST_CHROOT/system/apex/com.android.runtime.testing" \ |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 157 | "$ART_TEST_CHROOT/apex/com.android.runtime" |
| 158 | |
Victor Chang | 6461124 | 2019-07-05 16:32:41 +0100 | [diff] [blame] | 159 | echo -e "${green}Activating i18n APEX...${nc}" |
| 160 | # Manually "activate" the flattened i18n APEX by syncing it to the |
| 161 | # /apex directory in the chroot. |
| 162 | # |
| 163 | # TODO: Likewise, handle the case of build targets using non-flatted APEX packages. |
| 164 | adb shell rm -rf "$ART_TEST_CHROOT/apex/com.android.i18n" |
| 165 | adb shell cp -a "$ART_TEST_CHROOT/system/apex/com.android.i18n" "$ART_TEST_CHROOT/apex/" |
| 166 | |
Roland Levillain | 2f1e8f8 | 2019-06-12 19:57:50 +0100 | [diff] [blame] | 167 | echo -e "${green}Activating Time Zone Data APEX...${nc}" |
| 168 | # Manually "activate" the flattened Time Zone Data APEX by syncing it to the |
| 169 | # /apex directory in the chroot. |
| 170 | # |
| 171 | # TODO: Likewise, handle the case of build targets using non-flatted APEX |
| 172 | # packages. |
| 173 | adb shell rm -rf "$ART_TEST_CHROOT/apex/com.android.tzdata" |
| 174 | adb shell cp -a "$ART_TEST_CHROOT/system/apex/com.android.tzdata" "$ART_TEST_CHROOT/apex/" |
| 175 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 176 | # Adjust the linker configuration file (if needed). |
| 177 | # |
| 178 | # Check the linker configurations files on the "host system" and the "guest |
| 179 | # system". If these file names are different, rename the "guest system" linker |
| 180 | # configuration file within the chroot environment using the "host system" |
| 181 | # linker configuration file name. |
| 182 | ld_host_system_config_file_path=$(get_ld_host_system_config_file_path) |
| 183 | echo -e "${green}Determining host system linker configuration:" \ |
| 184 | "\`$ld_host_system_config_file_path\`${nc}" |
| 185 | ld_guest_system_config_file_path=$(get_ld_guest_system_config_file_path) |
| 186 | echo -e "${green}Determining guest system linker configuration:" \ |
| 187 | "\`$ld_guest_system_config_file_path\`${nc}" |
| 188 | if [[ "$ld_host_system_config_file_path" != "$ld_guest_system_config_file_path" ]]; then |
| 189 | echo -e "${green}Renaming linker configuration file in chroot environment:" \ |
| 190 | "\`$ART_TEST_CHROOT$ld_guest_system_config_file_path\`" \ |
| 191 | "-> \`$ART_TEST_CHROOT$ld_host_system_config_file_path\`${nc}" |
| 192 | adb shell mv -f "$ART_TEST_CHROOT$ld_guest_system_config_file_path" \ |
| 193 | "$ART_TEST_CHROOT$ld_host_system_config_file_path" |
| 194 | fi |
Roland Levillain | 0f9823e | 2019-06-18 16:49:24 +0100 | [diff] [blame] | 195 | |
Roland Levillain | 0587b62 | 2019-04-03 14:18:50 +0100 | [diff] [blame] | 196 | # Sync the data directory to the chroot. |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 197 | echo -e "${green}Syncing data directory...${nc}" |
| 198 | adb push "$ANDROID_PRODUCT_OUT/data" "$ART_TEST_CHROOT/" |