xref: /aosp_15_r20/external/toolchain-utils/compiler_wrapper/install_compiler_wrapper.sh (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1#!/bin/bash
2#
3# Copyright 2020 The ChromiumOS Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This script rebuilds and installs compiler wrappers
8
9if [[ ! -e /etc/cros_chroot_version ]]; then
10  echo "Please run this script inside chroot"
11  exit 1
12fi
13set -e
14
15# Use a unique value here, since folks doing wrapper dev _likely_ want builds
16# to always be redone.
17version_suffix="manually_installed_wrapper_at_unix_$(date +%s.%6N)"
18echo "Using toolchain hash: ${version_suffix}"
19cd "$(dirname "$(readlink -m "$0")")"
20
21build_py() {
22  ./build.py --version_suffix="${version_suffix}" "$@"
23}
24
25echo "Updated files:"
26# Update the host wrapper
27build_py \
28  --config=cros.host \
29  --use_ccache=false \
30  --use_llvm_next=false \
31  --output_file=./clang_host_wrapper
32sudo mv ./clang_host_wrapper /usr/bin/clang_host_wrapper
33echo "/usr/bin/clang_host_wrapper"
34sudo cp ../bisect_driver.py /usr/bin
35echo "/usr/bin/clang_host_wrapper/bisect_driver.py"
36
37# Update the target wrappers
38build_py \
39  --config=cros.hardened \
40  --use_ccache=false \
41  --use_llvm_next=false \
42  --output_file=./sysroot_wrapper.hardened.noccache
43build_py \
44  --config=cros.hardened \
45  --use_ccache=true \
46  --use_llvm_next=false \
47  --output_file=./sysroot_wrapper.hardened.ccache
48
49# Update clang target wrappers.
50sudo cp ./sysroot_wrapper.hardened.noccache ./sysroot_wrapper.hardened.ccache /usr/bin
51echo "Updated clang wrapper /usr/bin/sysroot_wrapper.hardened.noccache"
52echo "Updated clang wrapper /usr/bin/sysroot_wrapper.hardened.ccache"
53
54# Update GCC target wrappers.
55for GCC in cross-x86_64-cros-linux-gnu/gcc cross-armv7a-cros-linux-gnueabihf/gcc cross-aarch64-cros-linux-gnu/gcc; do
56  if ! FILES="$(equery f "${GCC}")"; then
57    if [[ $(equery l "${GCC}" 2>&1 | wc -c) -eq 0 ]]; then
58      echo "no ${GCC} package found; skipping" >&2
59      continue
60    fi
61    # Something went wrong, and the equery above probably complained about it.
62    exit 1
63  fi
64  echo "Updating ${GCC} wrapper."
65  sudo cp ./sysroot_wrapper.hardened.noccache "$(grep sysroot_wrapper.hardened.noccache <<< "${FILES}")"
66  grep sysroot_wrapper.hardened.noccache <<< "${FILES}"
67  sudo cp ./sysroot_wrapper.hardened.ccache "$(grep sysroot_wrapper.hardened.ccache <<< "${FILES}")"
68  grep sysroot_wrapper.hardened.ccache <<< "${FILES}"
69  sudo cp ../bisect_driver.py "$(grep bisect_driver.py <<< "${FILES}")"
70  grep bisect_driver.py <<< "${FILES}"
71done
72rm -f ./sysroot_wrapper.hardened.noccache ./sysroot_wrapper.hardened.ccache
73