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