• [gentoo-dev] [PATCH 1/5] cmake.eclass: Improve _cmake_modify-cmakelists

    From Andreas Sturmlechner@21:1/5 to All on Sun Jun 15 22:26:58 2025
    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 <[email protected]>
    Thanks-to: Sam James <[email protected]>
    Signed-off-by: Andreas Sturmlechner <[email protected]>
    ---
    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:]]*([[:spac
  • From Andreas Sturmlechner@21:1/5 to All on Sun Jun 15 22:31:48 2025
    See examples:
    https://bugs.gentoo.org/953075
    https://bugs.gentoo.org/957670
    https://bugs.gentoo.org/957671
    https://bugs.gentoo.org/957803

    Signed-off-by: Andreas Sturmlechner <[email protected]>
    ---
    eclass/cmake.eclass | 19 +++++++++++++++++++
    1 file changed, 19 insertions(+)

    diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
    index d61992576565..109227edfe02 100644
    --- a/eclass/cmake.eclass
    +++ b/eclass/cmake.eclass
    @@ -807,6 +807,25 @@ cmake_src_install() {
    einstalldocs
    popd > /dev/null || die
    fi
    +
    + local file files=()
    + while read -d '' -r file ; do
    + # Detect unsupported minimum CMake versions unless CMAKE_QA_COMPAT_SKIP is set
    + if ! [[ ${CMAKE_QA_COMPAT_SKIP} ]]; then
    + _cmake_minreqver-lt "3.5" "${file}" && files+=( "${file#"${D}"}" )
    + fi
    + done < <(find "${D}" -type f -iname "*.cmake" -print0 || die)
    + if [[ ${#files[*]} -gt 0 ]]; then
    + eqawarn "QA Notice: Package installs CMake module(s) incompatible with CMake 4,"
    + eqawarn "breaking any packages relying on it:"
    + eqawarn
    + for file in "${files[@]}"; do
    + eqawarn " ${file}"
    + done
    + eqawarn
    + eqawarn "See also tracker bug #951350; check existing bug or file a new one for"
    + eqa
  • From Andreas Sturmlechner@21:1/5 to All on Sun Jun 15 22:31:34 2025
    Thanks-to: Ionen Wolkens <[email protected]>
    Closes: https://bugs.gentoo.org/957990
    Bug: https://bugs.gentoo.org/958051
    Signed-off-by: Andreas Sturmlechner <[email protected]>
    ---
    eclass/cmake.eclass | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
    index ffd11bc0c863..d61992576565 100644
    --- a/eclass/cmake.eclass
    +++ b/eclass/cmake.eclass
    @@ -336,7 +336,7 @@ _cmake_check_build_dir() {
    # Returns 0 if the regex matched (a lower-than-specified version found).
    _cmake_minreqver-lt() {
    local ver chk=1
    - ver=$(sed -ne "/cmake_minimum_required/I{s/.*\(\.\.\.*\|\s\)\([0-9.]*\)\([)]\|\s\).*$/\2/p;q}" \
    + ver=$(sed -ne "/cmake_minimum_required/I{s/.*\(\.\.\.*\|\s\)\([0-9][0-9.]*\)\([)]\|\s\).*$/\2/p;q}" \
    "${2}" 2>/dev/null \
    )
    if [[ -n ${ver} ]] && ver_test "${ver}" -lt "${1}"; then
    --
    2.49.0


    -----BEGIN PGP SIGNATURE-----

    iQITBAABCgB9FiEEmaksxp6GvcraXyZQrlkbvHPk3V4FAmhPLaZfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDk5 QTkyQ0M2OUU4NkJEQ0FEQTVGMjY1MEFFNTkxQkJDNzNFNERENUUACgkQrlkbvHPk 3V4V/Qv/SfudfswrjvAZBxEG01GkPtlruTx1YbxV9zzGJ+qy8IZphBESMc/yLIJT
    H5/lrLO4PZMr1
  • From Andreas Sturmlechner@21:1/5 to All on Sun Jun 15 22:30:55 2025
    Allows to split detection/eqawarn and applying cmakearg over different
    phases.

    Signed-off-by: Andreas Sturmlechner <[email protected]>
    ---
    eclass/cmake.eclass | 11 ++++++++---
    1 file changed, 8 insertions(+), 3 deletions(-)

    diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
    index ea5a769b4cb4..4104882005a3 100644
    --- a/eclass/cmake.eclass
    +++ b/eclass/cmake.eclass
    @@ -123,6 +123,11 @@ fi
    # If set, skip detection of CMakeLists.txt unsupported in CMake 4 in case of
    # false positives (e.g. unused outdated bundled libs).

    +# @ECLASS_VARIABLE: _CMAKE_MINREQVER_UNSUPPORTED
    +# @DEFAULT_UNSET
    +# @DESCRIPTION:
    +# Is set to true if an unsupported cmake_minimum_required value was detected. +
    # @ECLASS_VARIABLE: CMAKE_QA_SRC_DIR_READONLY
    # @USER_VARIABLE
    # @DEFAULT_UNSET
    @@ -455,7 +460,7 @@ cmake_src_configure() {
    # Fix xdg collision with sandbox
    xdg_environment_reset

    - local file ver cmreq_isold
    + local file ver
    if ! [[ ${CMAKE_QA_COMPAT_SKIP} ]]; then
    while read -d '' -r file ; do
    ver=$(sed -ne "/cmake_minimum_required/I{s/.*\(\.\.\.*\|\s\)\([0-9.]*\)\([)]\|\s\).*$/\2/p;q}" \
    @@ -463,7 +468,7 @@ c
  • From Andreas Sturmlechner@21:1/5 to All on Sun Jun 15 22:31:18 2025
    - _cmake_minverreq-lt(): New function for reusability of regex
    - Optimise #1: Reuse existing loop over CMakeLists.txt files
    - Optimise #2: If _CMAKE_MINREQVER_UNSUPPORTED is already set, then no
    further run of _cmake_minverreq-lt is necessary since we currently throw
    away the info on affected files
    - Relegate "CMake 4 detected; ..." to be a non-QA Notice, it is just an
    addendum

    Signed-off-by: Andreas Sturmlechner <[email protected]>
    ---
    eclass/cmake.eclass | 70 +++++++++++++++++++++++++++------------------
    1 file changed, 42 insertions(+), 28 deletions(-)

    diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
    index 4104882005a3..ffd11bc0c863 100644
    --- a/eclass/cmake.eclass
    +++ b/eclass/cmake.eclass
    @@ -126,7 +126,8 @@ fi
    # @ECLASS_VARIABLE: _CMAKE_MINREQVER_UNSUPPORTED
    # @DEFAULT_UNSET
    # @DESCRIPTION:
    -# Is set to true if an unsupported cmake_minimum_required value was detected. +# Internal status set by _cmake_minreqver-lt(); is true if an unsupported
    +# cmake_minimum_required value was detected.

    # @ECLASS_VARIABLE: CMAKE_QA_SRC_DIR_READONLY
    # @USER_VARIABLE
    @@ -326,6 +327,25 @@ _cmake_check_build_dir() {
    mkdir -p "${BUILD_DIR}" || die
    }

    +# @FUNCTION: _cmake_minreqver-lt
    +# @USAGE: <lt-version> <path>
    +# @INTERNAL
    +# @DESCRIPTION:
    +# Internal function for detecting occurrence of lower-than-specified
    +# <lt-version> in cmake_minimum_required of a given CMake file <path>.
    +# Returns 0 if the regex