From 441c959460217ba81591ada9185bed2665cdc994 Mon Sep 17 00:00:00 2001
From: Frantisek Sumsal <frantisek@sumsal.cz>
Date: Mon, 11 Oct 2021 21:12:42 +0200
Subject: [PATCH] ci: use the system llvm-11 package on Focal

ATTOW llvm-11 got into focal-updates, which conflicts with llvm-11
provided by the apt.llvm.org repositories. Let's use the system
llvm package if available in such cases to avoid that.

(cherry picked from commit 1c71302f70c7d0712d49b5214f5f29b4d6a2c73e)

Conflict:NA
Reference:https://github.com/systemd/systemd/commit/441c959460217ba81591ada9185bed2665cdc994
---
 .github/workflows/build_test.sh | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/build_test.sh b/.github/workflows/build_test.sh
index bdcb71ba9c..10fa1ea9b0 100755
--- a/.github/workflows/build_test.sh
+++ b/.github/workflows/build_test.sh
@@ -71,11 +71,17 @@ if [[ "$COMPILER" == clang ]]; then
     CC="clang-$COMPILER_VERSION"
     CXX="clang++-$COMPILER_VERSION"
     AR="llvm-ar-$COMPILER_VERSION"
-    # Latest LLVM stack deb packages provided by https://apt.llvm.org/
-    # Following snippet was borrowed from https://apt.llvm.org/llvm.sh
-    wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
-    add-apt-repository -y "deb http://apt.llvm.org/$RELEASE/   llvm-toolchain-$RELEASE-$COMPILER_VERSION  main"
-    PACKAGES+=(clang-$COMPILER_VERSION lldb-$COMPILER_VERSION lld-$COMPILER_VERSION clangd-$COMPILER_VERSION)
+
+    # ATTOW llvm-11 got into focal-updates, which conflicts with llvm-11
+    # provided by the apt.llvm.org repositories. Let's use the system
+    # llvm package if available in such cases to avoid that.
+    if ! apt show --quiet "llvm-$COMPILER_VERSION" &>/dev/null; then
+        # Latest LLVM stack deb packages provided by https://apt.llvm.org/
+        # Following snippet was borrowed from https://apt.llvm.org/llvm.sh
+        wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
+        add-apt-repository -y "deb http://apt.llvm.org/$RELEASE/   llvm-toolchain-$RELEASE-$COMPILER_VERSION  main"
+        PACKAGES+=("clang-$COMPILER_VERSION" "lldb-$COMPILER_VERSION" "lld-$COMPILER_VERSION" "clangd-$COMPILER_VERSION")
+    fi
 elif [[ "$COMPILER" == gcc ]]; then
     CC="gcc-$COMPILER_VERSION"
     CXX="g++-$COMPILER_VERSION"
-- 
2.33.0

