1 #!/bin/bash
2#
3# Copyright (C) 2023 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
17set -e
18
19if [ ! -e 'build/make/core/Makefile' ]; then
20  echo "Script $0 needs to be run at the root of the android tree"
21  exit 1
22fi
23
24vars="$(build/soong/soong_ui.bash --dumpvars-mode --vars="OUT_DIR DIST_DIR")"
25# Assign to a variable and eval that, since bash ignores any error status from
26# the command substitution if it's directly on the eval line.
27eval $vars
28
29HOST_BINARIES=(
30  ${OUT_DIR}/host/linux-x86/bin/dex2oat64
31  ${OUT_DIR}/host/linux-x86/bin/dex2oatd64
32  ${OUT_DIR}/host/linux-x86/bin/dex2oat
33  ${OUT_DIR}/host/linux-x86/bin/dex2oatd
34  ${OUT_DIR}/host/linux-x86/bin/deapexer
35  ${OUT_DIR}/host/linux-x86/bin/debugfs_static
36  ${OUT_DIR}/host/linux-x86/bin/oatdump
37)
38
39# Build statically linked musl binaries for linux-x86 hosts without the
40# standard glibc implementation.
41build/soong/soong_ui.bash --make-mode USE_HOST_MUSL=true BUILD_HOST_static=true ${HOST_BINARIES[*]}
42# Zip these binaries in a temporary file
43prebuilts/build-tools/linux-x86/bin/soong_zip -o "${DIST_DIR}/temp-host-tools.zip" \
44  -j ${HOST_BINARIES[*]/#/-f }
45
46# Build art_release.zip and copy only art jars in a temporary zip
47build/soong/soong_ui.bash --make-mode dist "${DIST_DIR}/art_release.zip"
48prebuilts/build-tools/linux-x86/bin/zip2zip -i "${DIST_DIR}/art_release.zip" \
49  -o "${DIST_DIR}/temp-art-jars.zip" "bootjars/*"
50
51# Merge both temporary zips into output zip
52prebuilts/build-tools/linux-x86/bin/merge_zips "${DIST_DIR}/art-host-tools-linux-x86.zip" \
53  "${DIST_DIR}/temp-host-tools.zip" "${DIST_DIR}/temp-art-jars.zip"
54
55# Delete temporary zips
56rm "${DIST_DIR}/temp-host-tools.zip" "${DIST_DIR}/temp-art-jars.zip"
57