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 | |
Orion Hodson | 5697fab | 2019-11-19 15:01:02 +0000 | [diff] [blame] | 19 | if [ -t 1 ]; then |
| 20 | # Color sequences if terminal is a tty. |
| 21 | red='\033[0;31m' |
| 22 | green='\033[0;32m' |
| 23 | yellow='\033[0;33m' |
| 24 | magenta='\033[0;35m' |
| 25 | nc='\033[0m' |
| 26 | fi |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 27 | |
Roland Levillain | 1d852c3 | 2020-02-14 16:38:11 +0000 | [diff] [blame] | 28 | # Setup as root, as some actions performed here require it. |
| 29 | adb root |
Nicolas Geoffray | b745adc | 2018-10-11 10:30:19 +0100 | [diff] [blame] | 30 | adb wait-for-device |
| 31 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 32 | if [[ -z "$ANDROID_BUILD_TOP" ]]; then |
| 33 | echo 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?' |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | if [[ -z "$ANDROID_PRODUCT_OUT" ]]; then |
Nicolas Geoffray | b745adc | 2018-10-11 10:30:19 +0100 | [diff] [blame] | 38 | echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?' |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 42 | if [[ -z "$ART_TEST_CHROOT" ]]; then |
| 43 | 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] | 44 | exit 1 |
| 45 | fi |
| 46 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 47 | if [[ "$(build/soong/soong_ui.bash --dumpvar-mode TARGET_FLATTEN_APEX)" != "true" ]]; then |
| 48 | echo -e "${red}This script only works when APEX packages are flattened, but the build" \ |
| 49 | "configuration is set up to use non-flattened APEX packages.${nc}" |
| 50 | echo -e "${magenta}You can force APEX flattening by setting the environment variable" \ |
Roland Levillain | bd5fb28 | 2019-10-04 14:26:03 +0100 | [diff] [blame] | 51 | "\`OVERRIDE_TARGET_FLATTEN_APEX\` to \"true\" before starting the build and running this" \ |
| 52 | "script.${nc}" |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 53 | exit 1 |
| 54 | fi |
| 55 | |
Roland Levillain | 5d24c3d | 2020-02-07 11:57:12 +0000 | [diff] [blame] | 56 | |
| 57 | # `/system` "partition" synchronization. |
| 58 | # -------------------------------------- |
| 59 | |
| 60 | # Sync the system directory to the chroot. |
| 61 | echo -e "${green}Syncing system directory...${nc}" |
| 62 | adb shell mkdir -p "$ART_TEST_CHROOT/system" |
| 63 | adb push "$ANDROID_PRODUCT_OUT/system" "$ART_TEST_CHROOT/" |
| 64 | # Overwrite the default public.libraries.txt file with a smaller one that |
| 65 | # contains only the public libraries pushed to the chroot directory. |
| 66 | adb push "$ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt" \ |
| 67 | "$ART_TEST_CHROOT/system/etc/public.libraries.txt" |
| 68 | |
| 69 | |
Jooyung Han | 2d34867 | 2020-02-12 15:14:15 +0900 | [diff] [blame] | 70 | # APEX packages activation. |
| 71 | # ------------------------- |
| 72 | |
| 73 | # Manually "activate" the flattened APEX $1 by syncing it to /apex/$2 in the |
| 74 | # chroot. $2 defaults to $1. |
| 75 | # |
| 76 | # TODO: Handle the case of build targets using non-flatted APEX packages. |
| 77 | # As a workaround, one can run `export OVERRIDE_TARGET_FLATTEN_APEX=true` before building |
| 78 | # a target to have its APEX packages flattened. |
| 79 | activate_apex() { |
| 80 | local src_apex=${1} |
| 81 | local dst_apex=${2:-${src_apex}} |
| 82 | echo -e "${green}Activating APEX ${src_apex} as ${dst_apex}...${nc}" |
| 83 | # We move the files from `/system/apex/${src_apex}` to `/apex/${dst_apex}` in |
| 84 | # the chroot directory, instead of simply using a symlink, as Bionic's linker |
| 85 | # relies on the real path name of a binary (e.g. |
| 86 | # `/apex/com.android.art/bin/dex2oat`) to select the linker configuration. |
| 87 | adb shell mkdir -p "$ART_TEST_CHROOT/apex" |
| 88 | adb shell rm -rf "$ART_TEST_CHROOT/apex/${dst_apex}" |
| 89 | # Use use mv instead of cp, as cp has a bug on fugu NRD90R where symbolic |
| 90 | # links get copied with odd names, eg: libcrypto.so -> /system/lib/libcrypto.soe.sort.so |
| 91 | adb shell mv "$ART_TEST_CHROOT/system/apex/${src_apex}" "$ART_TEST_CHROOT/apex/${dst_apex}" \ |
| 92 | || exit 1 |
| 93 | } |
| 94 | |
| 95 | # "Activate" the required APEX modules. |
| 96 | activate_apex com.android.art.testing com.android.art |
| 97 | activate_apex com.android.i18n |
| 98 | activate_apex com.android.runtime |
| 99 | activate_apex com.android.tzdata |
| 100 | activate_apex com.android.conscrypt |
| 101 | |
| 102 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 103 | # Linker configuration. |
| 104 | # --------------------- |
| 105 | |
Roland Levillain | 15ff34d | 2020-02-05 19:55:34 +0000 | [diff] [blame] | 106 | # Statically linked `linkerconfig` binary. |
| 107 | linkerconfig_binary="/system/bin/linkerconfig" |
| 108 | # Generated linker configuration file path (since Android R). |
| 109 | ld_generated_config_file_path="/linkerconfig/ld.config.txt" |
| 110 | # Location of the generated linker configuration file. |
| 111 | ld_generated_config_file_location=$(dirname "$ld_generated_config_file_path") |
| 112 | |
Roland Levillain | e0ac2f3 | 2020-02-12 17:19:25 +0000 | [diff] [blame] | 113 | # Generate linker configuration files on device. |
| 114 | echo -e "${green}Generating linker configuration files on device in" \ |
| 115 | "\`$ld_generated_config_file_path\`${nc}..." |
Roland Levillain | 15ff34d | 2020-02-05 19:55:34 +0000 | [diff] [blame] | 116 | adb shell chroot "$ART_TEST_CHROOT" \ |
| 117 | "$linkerconfig_binary" --target "$ld_generated_config_file_location" || exit 1 |
Roland Levillain | e0ac2f3 | 2020-02-12 17:19:25 +0000 | [diff] [blame] | 118 | ld_generated_config_files=$(adb shell find $ART_TEST_CHROOT/linkerconfig ! -type d | sed 's/^/ /') |
| 119 | echo -e "${green}Generated linker configuration files on device:${nc}" |
| 120 | echo -e "${green}$ld_generated_config_files${nc}" |
Roland Levillain | 15ff34d | 2020-02-05 19:55:34 +0000 | [diff] [blame] | 121 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 122 | |
Roland Levillain | 5d24c3d | 2020-02-07 11:57:12 +0000 | [diff] [blame] | 123 | # `/data` "partition" synchronization. |
| 124 | # ------------------------------------ |
Roland Levillain | 0f9823e | 2019-06-18 16:49:24 +0100 | [diff] [blame] | 125 | |
Roland Levillain | 0587b62 | 2019-04-03 14:18:50 +0100 | [diff] [blame] | 126 | # Sync the data directory to the chroot. |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 127 | echo -e "${green}Syncing data directory...${nc}" |
Roland Levillain | 31e284b | 2019-10-03 16:03:09 +0100 | [diff] [blame] | 128 | adb shell mkdir -p "$ART_TEST_CHROOT/data" |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 129 | adb push "$ANDROID_PRODUCT_OUT/data" "$ART_TEST_CHROOT/" |