From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 9673715815E for ; Thu, 8 Feb 2024 19:06:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 13450E2A64; Thu, 8 Feb 2024 19:06:42 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A5FBEE2A43 for ; Thu, 8 Feb 2024 19:06:41 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH] llvm-utils.eclass: Fix llvm_prepend_path to avoid duplicates Date: Thu, 8 Feb 2024 20:06:04 +0100 Message-ID: <20240208190636.157498-1-mgorny@gentoo.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207203515.17640-4-mgorny@gentoo.org> References: <20240207203515.17640-4-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 5f27dddf-66d1-474f-94d0-7ab13f019801 X-Archives-Hash: f577e46b4f074129b60b84b2cab78b9f Fix llvm_prepend_path() not to append the new path multiple times, if the original PATH variable contained multiple LLVM directories. Thanks to Alexander Miller who spotted it in: https://github.com/gentoo/gentoo/pull/35196#discussion_r1480330001 Signed-off-by: Michał Górny --- eclass/llvm-utils.eclass | 10 ++++++---- eclass/tests/llvm-utils.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) Changed in v2: simplified the logic, courtesy of Alexander Miller, and added more test cases. diff --git a/eclass/llvm-utils.eclass b/eclass/llvm-utils.eclass index f308667e3dc2..532e609679b8 100644 --- a/eclass/llvm-utils.eclass +++ b/eclass/llvm-utils.eclass @@ -129,16 +129,18 @@ llvm_prepend_path() { local new_path=() local x added= - # prepend new path in front of the first LLVM version found for x in "${split_path[@]}"; do if [[ ${x} == */usr/lib/llvm/*/bin ]]; then - if [[ ${x} != ${llvm_path} ]]; then + # prepend new path in front of the first LLVM version found + if [[ ! ${added} ]]; then new_path+=( "${llvm_path}" ) - elif [[ ${added} && ${x} == ${llvm_path} ]]; then + added=1 + fi + # remove duplicate copies of the same path + if [[ ${x} == ${llvm_path} ]]; then # deduplicate continue fi - added=1 fi new_path+=( "${x}" ) done diff --git a/eclass/tests/llvm-utils.sh b/eclass/tests/llvm-utils.sh index 5a46b25b7ad6..6fe3da3eda13 100755 --- a/eclass/tests/llvm-utils.sh +++ b/eclass/tests/llvm-utils.sh @@ -98,9 +98,21 @@ ESYSROOT= test_prepend_path 17 /usr/bin /usr/bin:/usr/lib/llvm/17/bin test_prepend_path 17 /usr/lib/llvm/17/bin:/usr/bin /usr/lib/llvm/17/bin:/usr/bin test_prepend_path 17 /usr/bin:/usr/lib/llvm/17/bin /usr/bin:/usr/lib/llvm/17/bin +test_prepend_path 17 /usr/lib/llvm/17/bin:/usr/bin:/usr/lib/llvm/17/bin \ + /usr/lib/llvm/17/bin:/usr/bin +test_prepend_path 17 /usr/lib/llvm/17/bin:/usr/lib/llvm/17/bin:/usr/bin \ + /usr/lib/llvm/17/bin:/usr/bin +test_prepend_path 17 /usr/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/17/bin \ + /usr/bin:/usr/lib/llvm/17/bin test_prepend_path 18 /usr/lib/llvm/17/bin:/usr/bin \ /usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/bin test_prepend_path 18 /usr/bin:/usr/lib/llvm/17/bin \ /usr/bin:/usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin +test_prepend_path 18 /usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin:/usr/bin \ + /usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin:/usr/bin +test_prepend_path 18 /usr/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin \ + /usr/bin:/usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin +test_prepend_path 18 /usr/lib/llvm/17/bin:/usr/bin:/usr/lib/llvm/16/bin \ + /usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/bin:/usr/lib/llvm/16/bin texit -- 2.43.0