• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -ex
2
3# Copyright 2019 Google Inc. All rights reserved.
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
17source "$(dirname "$0")/envsetup.sh"
18
19if [ -z "${OUT_DIR}" ]; then
20    echo "error: Must set OUT_DIR"
21    exit 1
22fi
23
24TOP=$(pwd)
25
26UNAME="$(uname)"
27case "${UNAME}" in
28Linux)
29    OS='linux'
30    ;;
31Darwin)
32    OS='darwin'
33    ;;
34*)
35    echo "error: Unknown uname: ${UNAME}"
36    exit 1
37    ;;
38esac
39
40# Setup Soong configuration
41SOONG_OUT="${OUT_DIR}/soong"
42SOONG_HOST_OUT="${OUT_DIR}/soong/host/${OS}-x86"
43rm -rf "${SOONG_OUT}"
44mkdir -p "${SOONG_OUT}"
45cat > "${SOONG_OUT}/soong.variables" << __EOF__
46{
47    "Allow_missing_dependencies": true,
48    "HostArch":"x86_64"
49}
50__EOF__
51
52# Targets to be built
53if [ "${OS}" = "darwin" ]; then
54    SOONG_BINARIES=(
55        "versioner"
56    )
57else
58    SOONG_BINARIES=(
59        "bindgen"
60        "cxx_extractor"
61        "header-abi-linker"
62        "header-abi-dumper"
63        "header-abi-diff"
64        "proto_metadata_plugin"
65        "protoc_extractor"
66        "versioner"
67    )
68fi
69
70binaries=()
71for name in "${SOONG_BINARIES[@]}"; do
72    binaries+=("${SOONG_HOST_OUT}/bin/${name}")
73done
74
75libs=()
76if [ "${OS}" = "darwin" ]; then
77    libs+=("${SOONG_HOST_OUT}/lib64/libc++abi_host.dylib")
78fi
79
80# Build binaries and shared libs
81build/soong/soong_ui.bash --make-mode --skip-config --soong-only "${binaries[@]}" "${libs[@]}"
82
83# Copy binaries and shared libs
84SOONG_DIST="${SOONG_OUT}/dist"
85mkdir -p "${SOONG_DIST}/bin"
86cp "${binaries[@]}" "${SOONG_DIST}/bin"
87cp -R "${SOONG_HOST_OUT}/lib"* "${SOONG_DIST}"
88
89# Copy clang header and share files
90CLANG_DIR="prebuilts/clang/host/${OS}-x86/${LLVM_PREBUILTS_VERSION}"
91CLANG_LIB_DIR="${CLANG_DIR}/lib64/clang/${LLVM_RELEASE_VERSION}"
92CLANG_LIB_DIR_OUT="${SOONG_DIST}/lib64/clang/${LLVM_RELEASE_VERSION}"
93mkdir -p "${CLANG_LIB_DIR_OUT}"
94cp -R "${CLANG_LIB_DIR}/share" "${CLANG_LIB_DIR_OUT}/share"
95cp -R "${CLANG_LIB_DIR}/include" "${CLANG_LIB_DIR_OUT}/include"
96ln -s "lib64/clang/${LLVM_RELEASE_VERSION}/include" "${SOONG_DIST}/clang-headers"
97
98# Normalize library file names.  All library file names must match their soname.
99function extract_soname () {
100    local file="$1"
101
102    case "${OS}" in
103    linux)
104        readelf -d "${file}" | \
105            grep '(SONAME)\s*Library soname: \[.*\]$' -o | \
106            sed 's/(SONAME)\s*Library soname: \[\(.*\)\]$/\1/g'
107        ;;
108    darwin)
109        local install_path="$(otool -D "${file}" | sed -n 2p)"
110        if [ -n "${install_path}" ]; then
111            basename "${install_path}"
112        fi
113        ;;
114    esac
115}
116
117for file in "${SOONG_OUT}/dist/lib"*"/"*; do
118    soname="$(extract_soname "${file}")"
119    if [ -n "${soname}" -a "$(basename "${file}")" != "${soname}" ]; then
120        mv "${file}" "$(dirname "${file}")/${soname}"
121    fi
122done
123
124# Package binaries and shared libs
125(
126    cd "${SOONG_OUT}/dist"
127    zip -qryX build-prebuilts.zip *
128)
129
130if [ -n "${DIST_DIR}" ]; then
131    mkdir -p "${DIST_DIR}" || true
132    cp "${SOONG_OUT}/dist/build-prebuilts.zip" "${DIST_DIR}/"
133fi
134