blob: 8c83a9d7031a10f75ab68b194627c748b5e2349e [file] [log] [blame]
Roland Levillain72f67742019-03-06 15:48:08 +00001#! /bin/bash
Nicolas Geoffrayb745adc2018-10-11 10:30:19 +01002#
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 Levillain72f67742019-03-06 15:48:08 +000017# Push ART artifacts and its dependencies to a chroot directory for on-device testing.
18
19red='\033[0;31m'
20green='\033[0;32m'
21yellow='\033[0;33m'
22magenta='\033[0;35m'
23nc='\033[0m'
24
Nicolas Geoffrayb745adc2018-10-11 10:30:19 +010025adb wait-for-device
26
Roland Levillain72f67742019-03-06 15:48:08 +000027if [[ -z "$ANDROID_BUILD_TOP" ]]; then
28 echo 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?'
29 exit 1
30fi
31
32if [[ -z "$ANDROID_PRODUCT_OUT" ]]; then
Nicolas Geoffrayb745adc2018-10-11 10:30:19 +010033 echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
34 exit 1
35fi
36
Roland Levillain72f67742019-03-06 15:48:08 +000037if [[ -z "$ART_TEST_CHROOT" ]]; then
38 echo 'ART_TEST_CHROOT environment variable is empty; please set it before running this script.'
Nicolas Geoffrayb745adc2018-10-11 10:30:19 +010039 exit 1
40fi
41
Roland Levillain72f67742019-03-06 15:48:08 +000042if [[ "$(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
48fi
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.
64ld_config_file_path="/system/etc/ld.config.txt";
65# VNDK-lite linker configuration file name.
66ld_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).
73get_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.
109get_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 Levillain0587b622019-04-03 14:18:50 +0100134# Sync the system directory to the chroot.
Roland Levillain72f67742019-03-06 15:48:08 +0000135echo -e "${green}Syncing system directory...${nc}"
136adb push "$ANDROID_PRODUCT_OUT/system" "$ART_TEST_CHROOT/"
Roland Levillain0587b622019-04-03 14:18:50 +0100137# Overwrite the default public.libraries.txt file with a smaller one that
138# contains only the public libraries pushed to the chroot directory.
Roland Levillain72f67742019-03-06 15:48:08 +0000139adb push "$ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt" \
140 "$ART_TEST_CHROOT/system/etc/public.libraries.txt"
Roland Levillain0587b622019-04-03 14:18:50 +0100141
Roland Levillain72f67742019-03-06 15:48:08 +0000142echo -e "${green}Activating Runtime APEX...${nc}"
Roland Levillain8d5a2152019-07-02 19:40:28 +0100143# Manually "activate" the flattened Testing Runtime APEX by syncing it to the
Roland Levillain72f67742019-03-06 15:48:08 +0000144# /apex directory in the chroot.
145#
Roland Levillain8d5a2152019-07-02 19:40:28 +0100146# We copy the files from `/system/apex/com.android.runtime.testing` to
Roland Levillain72f67742019-03-06 15:48:08 +0000147# `/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.
155adb shell rm -rf "$ART_TEST_CHROOT/apex/com.android.runtime"
Roland Levillain8d5a2152019-07-02 19:40:28 +0100156adb shell cp -a "$ART_TEST_CHROOT/system/apex/com.android.runtime.testing" \
Roland Levillain72f67742019-03-06 15:48:08 +0000157 "$ART_TEST_CHROOT/apex/com.android.runtime"
158
Victor Chang64611242019-07-05 16:32:41 +0100159echo -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.
164adb shell rm -rf "$ART_TEST_CHROOT/apex/com.android.i18n"
165adb shell cp -a "$ART_TEST_CHROOT/system/apex/com.android.i18n" "$ART_TEST_CHROOT/apex/"
166
Roland Levillain2f1e8f82019-06-12 19:57:50 +0100167echo -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.
173adb shell rm -rf "$ART_TEST_CHROOT/apex/com.android.tzdata"
174adb shell cp -a "$ART_TEST_CHROOT/system/apex/com.android.tzdata" "$ART_TEST_CHROOT/apex/"
175
Roland Levillain72f67742019-03-06 15:48:08 +0000176# 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.
182ld_host_system_config_file_path=$(get_ld_host_system_config_file_path)
183echo -e "${green}Determining host system linker configuration:" \
184 "\`$ld_host_system_config_file_path\`${nc}"
185ld_guest_system_config_file_path=$(get_ld_guest_system_config_file_path)
186echo -e "${green}Determining guest system linker configuration:" \
187 "\`$ld_guest_system_config_file_path\`${nc}"
188if [[ "$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"
194fi
Roland Levillain0f9823e2019-06-18 16:49:24 +0100195
Roland Levillain0587b622019-04-03 14:18:50 +0100196# Sync the data directory to the chroot.
Roland Levillain72f67742019-03-06 15:48:08 +0000197echo -e "${green}Syncing data directory...${nc}"
198adb push "$ANDROID_PRODUCT_OUT/data" "$ART_TEST_CHROOT/"