install_clang_packages.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env bash
  2. #===- libcxx/utils/docker/scripts/install_clang_package.sh -----------------===//
  3. #
  4. # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. # See https://llvm.org/LICENSE.txt for license information.
  6. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. #
  8. #===-----------------------------------------------------------------------===//
  9. set -e
  10. function show_usage() {
  11. cat << EOF
  12. Usage: install_clang_package.sh [options]
  13. Install
  14. Available options:
  15. -h|--help show this help message
  16. --version the numeric version of the package to use.
  17. EOF
  18. }
  19. VERSION="9"
  20. while [[ $# -gt 0 ]]; do
  21. case "$1" in
  22. --version)
  23. shift
  24. VERSION="$1"
  25. shift
  26. ;;
  27. -h|--help)
  28. show_usage
  29. exit 0
  30. ;;
  31. *)
  32. echo "Unknown option: $1"
  33. exit 1
  34. esac
  35. done
  36. set -x
  37. curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
  38. add-apt-repository -s "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs) main"
  39. apt-get update
  40. apt-get upgrade -y
  41. apt-get install -y --no-install-recommends "clang-$VERSION"
  42. # FIXME(EricWF): Remove this once the clang packages are no longer broken.
  43. if [ -f "/usr/local/bin/clang" ]; then
  44. echo "clang already exists"
  45. exit 1
  46. else
  47. CC_BINARY="$(which clang-$VERSION)"
  48. ln -s "$CC_BINARY" "/usr/local/bin/clang"
  49. fi
  50. if [ -f "/usr/local/bin/clang++" ]; then
  51. echo "clang++ already exists"
  52. exit 1
  53. else
  54. CXX_BINARY="$(which clang++-$VERSION)"
  55. ln -s "$CXX_BINARY" "/usr/local/bin/clang++"
  56. fi
  57. echo "Testing clang version..."
  58. clang --version
  59. echo "Testing clang++ version..."
  60. clang++ --version
  61. # Figure out the libc++ and libc++abi package versions that we want.
  62. if [ "$VERSION" == "" ]; then
  63. VERSION="$(apt-cache search 'libc\+\+-[0-9]-dev' | awk '{print $1}' | awk -F- '{print $2}')"
  64. echo "Installing version '$VERSION'"
  65. fi
  66. apt-get purge -y "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
  67. apt-get install -y --no-install-recommends "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
  68. echo "Done"