| 1 | #!/bin/bash |
| 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | # You may not use this file except in compliance with the License. |
| 6 | # A copy of the License is located at |
| 7 | # |
| 8 | # http://aws.amazon.com/apache2.0 |
| 9 | # |
| 10 | # or in the "license" file accompanying this file. This file is distributed |
| 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | # express or implied. See the License for the specific language governing |
| 13 | # permissions and limitations under the License. |
| 14 | # |
| 15 | |
| 16 | set -e |
| 17 | |
| 18 | usage() { |
| 19 | echo "install_clang.sh download_dir install_dir os_name" |
| 20 | exit 1 |
| 21 | } |
| 22 | |
| 23 | if [ "$#" -ne "3" ]; then |
| 24 | usage |
| 25 | fi |
| 26 | |
| 27 | CLANG_DOWNLOAD_DIR=$1 |
| 28 | CLANG_INSTALL_DIR=$2 |
| 29 | PLATFORM=$3 |
| 30 | |
| 31 | mkdir -p "$CLANG_DOWNLOAD_DIR" |
| 32 | cd "$CLANG_DOWNLOAD_DIR" |
| 33 | |
| 34 | if [ "$PLATFORM" == "linux" ]; then |
| 35 | # The Certificate used by chromium.googlesource.com is not in the default CA |
| 36 | # list supported by git/curl on Ubuntu, but the certificate is in the |
| 37 | # ca-certificates.crt file in Ubuntu, so set this env variable so that it is |
| 38 | # picked up by git. |
| 39 | export SSL_CERT_FILE=/usr/lib/ssl/certs/ca-certificates.crt |
| 40 | fi |
| 41 | |
| 42 | export GIT_CURL_VERBOSE=1 |
| 43 | echo "Downloading Clang..." |
| 44 | git clone https://chromium.googlesource.com/chromium/src/tools/clang |
| 45 | |
| 46 | echo "Updating Clang..." |
| 47 | python3 "$CLANG_DOWNLOAD_DIR"/clang/scripts/update.py |
| 48 | |
| 49 | # "third_party" directory is created above $CLANG_DOWNLOAD_DIR after running |
| 50 | # update, move it into $CLANG_DOWNLOAD_DIR once update is complete. |
| 51 | mv ../third_party "$CLANG_DOWNLOAD_DIR" |
| 52 | |
| 53 | echo "Installed Clang Version: " |
| 54 | "$CLANG_DOWNLOAD_DIR"/third_party/llvm-build/Release+Asserts/bin/clang --version |
| 55 | |
| 56 | # Install matching LLVM if FUZZ_COVERAGE is enabled |
| 57 | if [[ "$FUZZ_COVERAGE" == "true" ]]; then |
| 58 | LLVM_INSTALL_DIR="$CLANG_INSTALL_DIR"/../llvm |
| 59 | mkdir -p "$LLVM_INSTALL_DIR" |
| 60 | python3 "$CLANG_DOWNLOAD_DIR"/clang/scripts/update.py --package="coverage_tools" --output-dir="$LLVM_INSTALL_DIR" |
| 61 | ln -sf $LLVM_INSTALL_DIR/bin/llvm-cov /usr/bin/llvm-cov |
| 62 | ln -sf $LLVM_INSTALL_DIR/bin/llvm-profdata /usr/bin/llvm-profdata |
| 63 | fi |
| 64 | |
| 65 | mkdir -p "$CLANG_INSTALL_DIR" && cp -rf "$CLANG_DOWNLOAD_DIR"/third_party/llvm-build/Release+Asserts/* "$CLANG_INSTALL_DIR" |
| 66 |