commit: 9787d328acbbb1bf149b05cc4a4023b2fa9c311d
Author: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 3 22:50:47 2025 +0000
Commit: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
CommitDate: Sun Jun 22 10:57:08 2025 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9787d328
cmake.eclass: Improve _cmake_modify-cmakelists(), consolidate the sed
50% less find
50% less grep
100% less cut
Thanks-to: Michał Górny <mgorny <AT> gentoo.org>
Thanks-to: Sam James <sam <AT> gentoo.org>
Signed-off-by: Andreas Sturmlechner <asturm <AT> 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