1#!/bin/bash
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
17
18if [[ -z $ANDROID_BUILD_TOP ]]; then
19  pushd .
20else
21  pushd $ANDROID_BUILD_TOP
22fi
23
24if [ ! -d art ]; then
25  echo "Script needs to be run at the root of the android tree"
26  exit 1
27fi
28
29source build/envsetup.sh >&/dev/null # for get_build_var
30
31out_dir=$(get_build_var OUT_DIR)
32host_out=$(get_build_var HOST_OUT)
33
34# TODO(b/31559095) Figure out a better way to do this.
35#
36# There is no good way to force soong to generate host-bionic builds currently
37# so this is a hacky workaround.
38
39# First build all the targets still in .mk files (also build normal glibc host
40# targets so we know what's needed to run the tests).
41build/soong/soong_ui.bash --make-mode "$@" test-art-host-run-test-dependencies build-art-host-tests
42if [ $? != 0 ]; then
43  exit 1
44fi
45
46tmp_soong_var=$(mktemp --tmpdir soong.variables.bak.XXXXXX)
47
48echo "Saving soong.variables to " $tmp_soong_var
49cat $out_dir/soong/soong.variables > ${tmp_soong_var}
50python3 <<END - ${tmp_soong_var} ${out_dir}/soong/soong.variables
51import json
52import sys
53x = json.load(open(sys.argv[1]))
54x['Allow_missing_dependencies'] = True
55x['HostArch'] = 'x86_64'
56x['CrossHost'] = 'linux_bionic'
57x['CrossHostArch'] = 'x86_64'
58if 'CrossHostSecondaryArch' in x:
59  del x['CrossHostSecondaryArch']
60json.dump(x, open(sys.argv[2], mode='w'))
61END
62if [ $? != 0 ]; then
63  mv $tmp_soong_var $out_dir/soong/soong.variables
64  exit 2
65fi
66
67soong_out=$out_dir/soong/host/linux_bionic-x86
68declare -a bionic_targets
69# These are the binaries actually used in tests. Since some of the files are
70# java targets or 32 bit we cannot just do the same find for the bin files.
71#
72# We look at what the earlier build generated to figure out what to ask soong to
73# build since we cannot use the .mk defined phony targets.
74bionic_targets=(
75  $soong_out/bin/dalvikvm
76  $soong_out/bin/dalvikvm64
77  $soong_out/bin/dex2oat
78  $soong_out/bin/dex2oatd
79  $soong_out/bin/profman
80  $soong_out/bin/profmand
81  $soong_out/bin/hiddenapi
82  $soong_out/bin/hprof-conv
83  $soong_out/bin/signal_dumper
84  $soong_out/lib64/libclang_rt.ubsan_standalone-x86_64-android.so
85  $(find $host_out/apex -type f | sed "s:$host_out:$soong_out:g")
86  $(find $host_out/lib64 -type f | sed "s:$host_out:$soong_out:g")
87  $(find $host_out/nativetest64 -type f | sed "s:$host_out:$soong_out:g"))
88
89echo building ${bionic_targets[*]}
90
91build/soong/soong_ui.bash --make-mode --skip-make "$@" ${bionic_targets[*]}
92ret=$?
93
94mv $tmp_soong_var $out_dir/soong/soong.variables
95
96# Having built with host-bionic confuses soong somewhat by making it think the
97# linux_bionic targets are needed for art phony targets like
98# test-art-host-run-test-dependencies. To work around this blow away all
99# ninja files in OUT_DIR. The build system is smart enough to not need to
100# rebuild stuff so this should be fine.
101rm -f $OUT_DIR/*.ninja $OUT_DIR/soong/*.ninja
102
103popd
104
105exit $ret
106