blob: de83c502cde85e5ba692f2fab838e0a975a8747b [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
Orion Hodson5697fab2019-11-19 15:01:02 +000019if [ -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'
26fi
Roland Levillain72f67742019-03-06 15:48:08 +000027
Roland Levillain1d852c32020-02-14 16:38:11 +000028# Setup as root, as some actions performed here require it.
29adb root
Nicolas Geoffrayb745adc2018-10-11 10:30:19 +010030adb wait-for-device
31
Roland Levillain72f67742019-03-06 15:48:08 +000032if [[ -z "$ANDROID_BUILD_TOP" ]]; then
33 echo 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?'
34 exit 1
35fi
36
37if [[ -z "$ANDROID_PRODUCT_OUT" ]]; then
Nicolas Geoffrayb745adc2018-10-11 10:30:19 +010038 echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
39 exit 1
40fi
41
Roland Levillain72f67742019-03-06 15:48:08 +000042if [[ -z "$ART_TEST_CHROOT" ]]; then
43 echo 'ART_TEST_CHROOT environment variable is empty; please set it before running this script.'
Nicolas Geoffrayb745adc2018-10-11 10:30:19 +010044 exit 1
45fi
46
Roland Levillain72f67742019-03-06 15:48:08 +000047if [[ "$(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 Levillainbd5fb282019-10-04 14:26:03 +010051 "\`OVERRIDE_TARGET_FLATTEN_APEX\` to \"true\" before starting the build and running this" \
52 "script.${nc}"
Roland Levillain72f67742019-03-06 15:48:08 +000053 exit 1
54fi
55
Roland Levillain5d24c3d2020-02-07 11:57:12 +000056
57# `/system` "partition" synchronization.
58# --------------------------------------
59
60# Sync the system directory to the chroot.
61echo -e "${green}Syncing system directory...${nc}"
62adb shell mkdir -p "$ART_TEST_CHROOT/system"
63adb 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.
66adb push "$ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt" \
67 "$ART_TEST_CHROOT/system/etc/public.libraries.txt"
68
69
Jooyung Han2d348672020-02-12 15:14:15 +090070# 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.
79activate_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.
96activate_apex com.android.art.testing com.android.art
97activate_apex com.android.i18n
98activate_apex com.android.runtime
99activate_apex com.android.tzdata
100activate_apex com.android.conscrypt
101
102
Roland Levillain72f67742019-03-06 15:48:08 +0000103# Linker configuration.
104# ---------------------
105
Roland Levillain15ff34d2020-02-05 19:55:34 +0000106# Statically linked `linkerconfig` binary.
107linkerconfig_binary="/system/bin/linkerconfig"
108# Generated linker configuration file path (since Android R).
109ld_generated_config_file_path="/linkerconfig/ld.config.txt"
110# Location of the generated linker configuration file.
111ld_generated_config_file_location=$(dirname "$ld_generated_config_file_path")
112
Roland Levillaine0ac2f32020-02-12 17:19:25 +0000113# Generate linker configuration files on device.
114echo -e "${green}Generating linker configuration files on device in" \
115 "\`$ld_generated_config_file_path\`${nc}..."
Roland Levillain15ff34d2020-02-05 19:55:34 +0000116adb shell chroot "$ART_TEST_CHROOT" \
117 "$linkerconfig_binary" --target "$ld_generated_config_file_location" || exit 1
Roland Levillaine0ac2f32020-02-12 17:19:25 +0000118ld_generated_config_files=$(adb shell find $ART_TEST_CHROOT/linkerconfig ! -type d | sed 's/^/ /')
119echo -e "${green}Generated linker configuration files on device:${nc}"
120echo -e "${green}$ld_generated_config_files${nc}"
Roland Levillain15ff34d2020-02-05 19:55:34 +0000121
Roland Levillain72f67742019-03-06 15:48:08 +0000122
Roland Levillain5d24c3d2020-02-07 11:57:12 +0000123# `/data` "partition" synchronization.
124# ------------------------------------
Roland Levillain0f9823e2019-06-18 16:49:24 +0100125
Roland Levillain0587b622019-04-03 14:18:50 +0100126# Sync the data directory to the chroot.
Roland Levillain72f67742019-03-06 15:48:08 +0000127echo -e "${green}Syncing data directory...${nc}"
Roland Levillain31e284b2019-10-03 16:03:09 +0100128adb shell mkdir -p "$ART_TEST_CHROOT/data"
Roland Levillain72f67742019-03-06 15:48:08 +0000129adb push "$ANDROID_PRODUCT_OUT/data" "$ART_TEST_CHROOT/"