blob: 80f771f09da45378279bc3d70bec84cca59d14b6 [file] [log] [blame]
Roland Levillain72f67742019-03-06 15:48:08 +00001#! /bin/bash
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +01002#
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 Hodson44ab2cd2019-10-08 10:17:05 +010017set -e
18
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010019if [ ! -d art ]; then
20 echo "Script needs to be run at the root of the android tree"
21 exit 1
22fi
23
Colin Crosse0ef0a82017-07-27 21:29:18 +000024source build/envsetup.sh >&/dev/null # for get_build_var
25
Fredrik Roubertad9c4a32016-11-11 19:28:18 -080026# Logic for setting out_dir from build/make/core/envsetup.mk:
27if [[ -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
33else
34 out_dir=${OUT_DIR}
35fi
36
Nicolas Geoffray4b29f382015-10-07 09:28:52 +010037java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES
Alex Light761ee212020-02-19 20:47:43 +000038common_targets="vogar core-tests apache-harmony-jdwp-tests-hostdex jsr166-tests libartpalette-system mockito-target"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010039mode="target"
40j_arg="-j$(nproc)"
Roland Levillainb8b93562015-08-20 17:49:56 +010041showcommands=
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010042make_command=
43
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010044while true; do
45 if [[ "$1" == "--host" ]]; then
46 mode="host"
47 shift
48 elif [[ "$1" == "--target" ]]; then
49 mode="target"
50 shift
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010051 elif [[ "$1" == -j* ]]; then
Nicolas Geoffray667b99e2015-05-29 12:17:06 +010052 j_arg=$1
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010053 shift
Roland Levillainb8b93562015-08-20 17:49:56 +010054 elif [[ "$1" == "--showcommands" ]]; then
55 showcommands="showcommands"
56 shift
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010057 elif [[ "$1" == "" ]]; then
58 break
Andreas Gampe0dcee912017-02-01 22:07:45 -080059 else
60 echo "Unknown options $@"
61 exit 1
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010062 fi
63done
64
Andreas Gampe353d8182017-10-12 10:17:34 -070065# Allow to build successfully in master-art.
Martin Stjernholmfb2967e2020-06-12 15:12:26 +010066extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true"
Andreas Gampe353d8182017-10-12 10:17:34 -070067
Martin Stjernholm69069102020-06-16 13:26:40 +010068# Switch the build system to unbundled mode in the reduced manifest branch.
69# TODO(b/159109002): Clean this up.
70if [ ! -d frameworks/base ]; then
71 extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true"
72fi
73
Martin Stjernholme2f97112020-05-21 14:59:42 +010074apexes=(
75 "com.android.art.testing"
76 "com.android.conscrypt"
77 "com.android.i18n"
78 "com.android.runtime"
79 "com.android.tzdata"
80)
81
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010082if [[ $mode == "host" ]]; then
Alex Light92fc2c02019-07-30 16:15:29 -070083 make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-host-tests $common_targets"
Orion Hodsonf7f85d02019-02-22 16:17:46 +000084 make_command+=" dx-tests junit-host"
Andreas Gampe6c3e1a02017-11-09 10:29:32 -080085 mode_suffix="-host"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +010086elif [[ $mode == "target" ]]; then
Evgeny Astigeevich069391e2018-09-05 22:40:57 +010087 if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then
88 echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
Roland Levillainfe3e2bf2018-03-02 16:01:50 +000089 exit 1
90 fi
Alex Light92fc2c02019-07-30 16:15:29 -070091 make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-target-tests $common_targets"
Nicolas Geoffrayeed02172020-05-26 09:54:25 +010092 make_command+=" libnetd_client-target toybox sh"
Alex Light219420e2019-12-05 10:20:26 -080093 make_command+=" debuggerd su gdbserver"
Nicolas Geoffrayc69b3f82020-06-22 12:33:38 +000094 # vogar requires the class files for conscrypt and ICU.
95 make_command+=" conscrypt core-icu4j"
Evgeny Astigeevich069391e2018-09-05 22:40:57 +010096 make_command+=" ${ANDROID_PRODUCT_OUT#"${ANDROID_BUILD_TOP}/"}/system/etc/public.libraries.txt"
Martin Stjernholme2f97112020-05-21 14:59:42 +010097 # 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 Stjernholm4bb9f672020-05-19 01:33:47 +0100104 make_command+=" event-log-tags"
105 # Needed to extract prebuilt APEXes.
106 make_command+=" deapexer"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100107 # Build/install the required APEXes.
108 make_command+=" ${apexes[*]}"
Nicolas Geoffrayfbeca752015-05-29 10:54:12 +0100109fi
110
Andreas Gampe6c3e1a02017-11-09 10:29:32 -0800111mode_specific_libraries="libjavacoretests libjdwp libwrapagentproperties libwrapagentpropertiesd"
112for LIB in ${mode_specific_libraries} ; do
113 make_command+=" $LIB${mode_suffix}"
114done
115
116
Nicolas Geoffrayaadc9862015-09-29 14:56:31 +0100117echo "Executing $make_command"
Nicolas Geoffraya8e8cdf2018-10-16 09:44:58 +0100118# Disable path restrictions to enable luci builds using vpython.
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000119eval "$make_command"
Roland Levillain79975902019-09-16 18:00:29 +0100120
Roland Levillain79975902019-09-16 18:00:29 +0100121if [[ $mode == "target" ]]; then
Martin Stjernholme2f97112020-05-21 14:59:42 +0100122 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 Hodson3a809c82020-01-03 14:53:14 +0000140 # 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 Levillain79975902019-09-16 18:00:29 +0100152 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 Levillainc3f2fe92020-02-12 19:40:20 +0000156 eval "$link_command"
Roland Levillaina871d842020-02-14 15:37:12 +0000157 # 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 Light219420e2019-12-05 10:20:26 -0800161 echo "Executing $cmd"
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000162 eval "$cmd"
Alex Light219420e2019-12-05 10:20:26 -0800163 done
Orion Hodson3a809c82020-01-03 14:53:14 +0000164
165 # Temporary fix for libjavacrypto.so dependencies in libcore and jvmti tests (b/147124225).
Martin Stjernholme2f97112020-05-21 14:59:42 +0100166 conscrypt_dir="$ANDROID_PRODUCT_OUT/system/apex/com.android.conscrypt"
Orion Hodson3a809c82020-01-03 14:53:14 +0000167 conscrypt_libs="libjavacrypto.so libcrypto.so libssl.so"
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100168 if [ ! -d "${conscrypt_dir}" ]; then
169 echo -e "Missing conscrypt APEX in build output: ${conscrypt_dir}"
Orion Hodson3a809c82020-01-03 14:53:14 +0000170 exit 1
171 fi
Nicolas Geoffray81673f02020-04-22 16:43:54 +0100172 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 Hodson3a809c82020-01-03 14:53:14 +0000176 for l in lib lib64; do
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100177 if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l" ]; then
Orion Hodson3a809c82020-01-03 14:53:14 +0000178 continue
179 fi
180 for so in $conscrypt_libs; do
Nicolas Geoffraycb62cd82020-04-03 12:17:50 +0100181 src="${conscrypt_dir}/${l}/${so}"
Orion Hodson3a809c82020-01-03 14:53:14 +0000182 dst="$ANDROID_PRODUCT_OUT/system/${l}/${so}"
183 if [ "${src}" -nt "${dst}" ]; then
184 cmd="cp -p \"${src}\" \"${dst}\""
185 echo "Executing $cmd"
Roland Levillainc3f2fe92020-02-12 19:40:20 +0000186 eval "$cmd"
Orion Hodson3a809c82020-01-03 14:53:14 +0000187 fi
188 done
189 done
Martin Stjernholme2f97112020-05-21 14:59:42 +0100190
Martin Stjernholmac048ae2020-06-22 14:38:11 +0100191 # 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 Stjernholm4bb9f672020-05-19 01:33:47 +0100199 # 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 Stjernholme2f97112020-05-21 14:59:42 +0100216 # Create linker config files. We run linkerconfig on host to avoid problems
217 # building it statically for device in an unbundled tree.
218
Jooyung Hanf97a8592020-06-17 15:19:17 +0900219 # 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 Stjernholme2f97112020-05-21 14:59:42 +0100228 # For linkerconfig to pick up the APEXes correctly we need to make them
Jooyung Hanf97a8592020-06-17 15:19:17 +0900229 # available in $linkerconfig_root/apex.
230 mkdir -p $linkerconfig_root/apex
Martin Stjernholme2f97112020-05-21 14:59:42 +0100231 for apex in ${apexes[@]}; do
232 src="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
233 if [[ $apex == com.android.art.* ]]; then
Jooyung Hanf97a8592020-06-17 15:19:17 +0900234 dst="$linkerconfig_root/apex/com.android.art"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100235 else
Jooyung Hanf97a8592020-06-17 15:19:17 +0900236 dst="$linkerconfig_root/apex/${apex}"
Martin Stjernholme2f97112020-05-21 14:59:42 +0100237 fi
238 echo "Copying APEX directory from $src to $dst"
239 rm -rf $dst
240 cp -r $src $dst
241 done
242
Jooyung Hanf97a8592020-06-17 15:19:17 +0900243 # 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 Stjernholme2f97112020-05-21 14:59:42 +0100247 platform_version=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION)
Jooyung Hanf97a8592020-06-17 15:19:17 +0900248 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 Levillain79975902019-09-16 18:00:29 +0100253fi