xref: /aosp_15_r20/external/toolchain-utils/compiler_wrapper/reset_compiler_wrapper.sh (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1#!/bin/bash -eux
2#
3# Copyright 2021 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# If your compiler wrapper ends up broken, you can run this script to try to
8# restore it to a working version. We can only use artifacts we download from
9# gs://, since it's kind of hard to build a working compiler with a broken
10# compiler wrapper. ;)
11
12if [[ ! -e "/etc/cros_chroot_version" ]]; then
13  echo "Run me inside of the chroot."
14  exit 1
15fi
16
17packages_to_reemerge=(
18  # We want to reemerge the host wrapper...
19  sys-devel/llvm
20)
21
22gcc_wrappers=(
23  cross-x86_64-cros-linux-gnu/gcc
24  cross-armv7a-cros-linux-gnueabihf/gcc
25  cross-aarch64-cros-linux-gnu/gcc
26)
27
28# ...and any existing target wrappers.
29for gcc in "${gcc_wrappers[@]}"; do
30  # cheap check for whether or not the package in question is already installed
31  if ls /var/db/pkg/"${gcc}"-* >& /dev/null; then
32    packages_to_reemerge+=( "${gcc}" )
33  fi
34done
35
36# Ensure that we don't pick up any broken binpkgs for these when we install
37# them below.
38for pkg in "${packages_to_reemerge[@]}"; do
39  sudo rm -f "/var/lib/portage/pkgs/${pkg}"*
40done
41
42sudo emerge -j16 -G "${packages_to_reemerge[@]}"
43