public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Andreas Sturmlechner <asturm@gentoo.org>
To: gentoo-dev@lists.gentoo.org, kde@gentoo.org, base-system@gentoo.org
Subject: [gentoo-dev] [PATCH 1/5] cmake.eclass: Improve _cmake_modify-cmakelists(), consolidate the sed
Date: Sun, 15 Jun 2025 22:26:58 +0200	[thread overview]
Message-ID: <12693580.O9o76ZdvQC@tuxbrain.fritz.box> (raw)

[-- Attachment #1: Type: text/plain, Size: 2576 bytes --]

Entire series in this PR: https://github.com/gentoo/gentoo/pull/42614

---

50% less find
50% less grep
100% less cut

Thanks-to: Michał Górny <mgorny@gentoo.org>
Thanks-to: Sam James <sam@gentoo.org>
Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 eclass/cmake.eclass | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
index f327521e9fc1..ea5a769b4cb4 100644
--- a/eclass/cmake.eclass
+++ b/eclass/cmake.eclass
@@ -333,17 +333,21 @@ _cmake_modify-cmakelists() {
 	grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0
 
 	# Comment out all set (<some_should_be_user_defined_variable> value)
-	find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec sed \
-		-e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' \
-		-e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
-		-e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
-		-e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
-		-i {} + || die "${LINENO}: failed to disable hardcoded settings"
-	local x
-	for x in $(find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec grep -l "^#_cmake_modify_IGNORE" {} +;); do
-		einfo "Hardcoded definition(s) removed in $(echo "${x}" | cut -c $((${#CMAKE_USE_DIR}+2))-):"
-		einfo "$(grep -se '^#_cmake_modify_IGNORE' ${x} | cut -c 22-99)"
-	done
+	local file
+	while read -d '' -r file ; do
+		sed \
+			-e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' \
+			-e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_\(COLOR_MAKEFILE\|INSTALL_PREFIX\|VERBOSE_MAKEFILE\)[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
+			-i "${file}" || die "failed to disable hardcoded settings"
+		readarray -t mod_lines < <(grep -se "^#_cmake_modify_IGNORE" "${file}")
+		if [[ ${#mod_lines[*]} -gt 0 ]]; then
+			einfo "Hardcoded definition(s) removed in ${file/${CMAKE_USE_DIR%\/}\//}:"
+			local mod_line
+			for mod_line in "${mod_lines[@]}"; do
+				einfo "${mod_line:22:99}"
+			done
+		fi
+	done < <(find "${CMAKE_USE_DIR}" -type f -iname "CMakeLists.txt" -print0 || die)
 
 	# NOTE Append some useful summary here
 	cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die
-- 
2.49.0

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 789 bytes --]

             reply	other threads:[~2025-06-15 20:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-15 20:26 Andreas Sturmlechner [this message]
2025-06-15 20:30 ` [gentoo-dev] [PATCH 2/5] cmake.eclass: Introduce _CMAKE_MINREQVER_UNSUPPORTED Andreas Sturmlechner
2025-06-15 20:31 ` [gentoo-dev] [PATCH 3/5] cmake.eclass: mv _CMAKE_MINREQVER_UNSUPPORTED detection to src_prepare Andreas Sturmlechner
2025-06-15 20:31 ` [gentoo-dev] [PATCH 4/5] cmake.eclass: Avoid none-detection by ensuring match starts w/ digit Andreas Sturmlechner
2025-06-15 20:31 ` [gentoo-dev] [PATCH 5/5] cmake.eclass: Add src_install() check for CMake-4-incompatible modules Andreas Sturmlechner
2025-06-16  5:19 ` [gentoo-dev] [PATCH 1/5] cmake.eclass: Improve _cmake_modify-cmakelists(), consolidate the sed Ulrich Müller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12693580.O9o76ZdvQC@tuxbrain.fritz.box \
    --to=asturm@gentoo.org \
    --cc=base-system@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=kde@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox