about summary refs log tree commit diff homepage
path: root/scripts/build/p-sanitizer-linux-ubuntu.inc
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/build/p-sanitizer-linux-ubuntu.inc')
-rw-r--r--scripts/build/p-sanitizer-linux-ubuntu.inc52
1 files changed, 32 insertions, 20 deletions
diff --git a/scripts/build/p-sanitizer-linux-ubuntu.inc b/scripts/build/p-sanitizer-linux-ubuntu.inc
index 30e153bb..5aa6480a 100644
--- a/scripts/build/p-sanitizer-linux-ubuntu.inc
+++ b/scripts/build/p-sanitizer-linux-ubuntu.inc
@@ -1,5 +1,5 @@
 install_binary_artifact_sanitizer() {
-  if [[ -z "${SANITIZER_BUILD:=}" ]]; then
+  if [[ -z "${SANITIZER_BUILD:-}" ]]; then
     return 1
   fi
 
@@ -7,34 +7,46 @@ install_binary_artifact_sanitizer() {
   local SANITIZER_LLVM_VERSION_MAJOR="${SANITIZER_LLVM_VERSION/.*/}"
   local version="-${SANITIZER_LLVM_VERSION_MAJOR}"
 
-  # Add certificate
-  with_sudo apt update -y
-  dependencies=(
-    ca-certificates
-    wget
-    lsb-release
-    gnupg
-  )
-
-  with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
-  wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | with_sudo apt-key add -
+  local LLVM_UPSTREAM_USED=0
+  # Check if package in standard repository otherwise use upstream
+  with_sudo apt-get update -y
+  if ! apt-cache show "llvm${version}"; then
+    if [[ -z "$(which wget)" ]]; then
+      # Add certificate
+      with_sudo apt-get update -y
+      dependencies=(
+        ca-certificates
+        wget
+        lsb-release
+        gnupg
+      )
+      with_sudo apt-get -y --no-install-recommends install "${dependencies[@]}"
+    fi
 
-  # Add repository
-  codename="$(lsb_release --codename --short)"
-  apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
-  if [[ ! $(grep -rq "${apt_entry}" /etc/apt) ]]; then
-    echo "${apt_entry}" | with_sudo tee -a /etc/apt/sources.list
-    with_sudo apt update -y
+    # Add LLVM upstream repository if available
+    codename="$(lsb_release --codename --short)"
+    if wget -q "https://apt.llvm.org/${codename}/dists/llvm-toolchain-${codename}${version}/"; then
+      LLVM_UPSTREAM_USED=1
+      apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
+      if ! grep -rq "${apt_entry}" /etc/apt; then
+        wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| with_sudo apt-key add -
+        echo "${apt_entry}" | with_sudo tee -a /etc/apt/sources.list
+        with_sudo apt-get update -y
+      fi
+    fi
   fi
 
-  with_sudo apt update -y
   dependencies=(
     "llvm${version}"
     "clang${version}"
   )
 
+  if [[ "${SANITIZER_LLVM_VERSION_MAJOR}" -ge 14 && "${LLVM_UPSTREAM_USED}" -eq 1 ]]; then
+    dependencies+=("libclang-rt${version}-dev")
+  fi
+
   #Install essential dependencies
-  with_sudo apt -y --no-install-recommends install "${dependencies[@]}" || return 1
+  with_sudo apt-get -y --no-install-recommends install "${dependencies[@]}" || return 1
 }
 
 get_docker_config_id_sanitizer() {