From 214b2fec7c840691b5b6599c07b6f3c3d6c1ff28 Mon Sep 17 00:00:00 2001 From: Andreas Sturmlechner Date: Wed, 4 Jun 2025 00:50:47 +0200 Subject: cmake.eclass: Improve _cmake_modify-cmakelists() 50% less find 50% less grep 100% less cut Signed-off-by: Andreas Sturmlechner --- eclass/cmake.eclass | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'eclass/cmake.eclass') diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass index 987c6e4c6ee..e200b39432f 100644 --- a/eclass/cmake.eclass +++ b/eclass/cmake.eclass @@ -250,17 +250,23 @@ _cmake_modify-cmakelists() { grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0 # Comment out all set ( 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[[: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 ${file} || die "${LINENO}: 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) # NOTE Append some useful summary here cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die -- cgit v1.2.3