public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] cmake.eclass: Provide cmake_prepare() to solve conflicts w/ other eclass
@ 2025-10-02 18:02 Andreas Sturmlechner
  0 siblings, 0 replies; only message in thread
From: Andreas Sturmlechner @ 2025-10-02 18:02 UTC (permalink / raw
  To: gentoo-dev, kde, base-system

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

See also: https://github.com/gentoo/gentoo/pull/44007

Split out what we need from cmake_src_prepare into new cmake_prepare().

cmake_src_prepare henceforth just calls default_src_prepare(),
then cmake_prepare(). This change was made for >=EAPI-8 only.

This also switches on a general EAPI=7 imminent error QA notice.

Bug: https://bugs.gentoo.org/853805
Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 eclass/cmake.eclass | 125 ++++++++++++++++++++++++++++----------------
 1 file changed, 81 insertions(+), 44 deletions(-)

diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
index b3a1cde6057e..e3f9a50a518d 100644
--- a/eclass/cmake.eclass
+++ b/eclass/cmake.eclass
@@ -303,6 +303,8 @@ _cmake_check_build_dir() {
 	if [[ ${EAPI} == 7 ]]; then
 		: "${CMAKE_USE_DIR:=${S}}"
 	else
+		# Since EAPI-8 we use current working directory, bug #704524
+		# esp. test with 'special' pkgs like: app-arch/brotli, net-libs/quiche
 		: "${CMAKE_USE_DIR:=${PWD}}"
 	fi
 	if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
@@ -394,22 +396,38 @@ _cmake_modify-cmakelists() {
 	_EOF_
 }
 
-# @FUNCTION: cmake_src_prepare
+# @FUNCTION: _cmake4_callout
+# @INTERNAL
 # @DESCRIPTION:
-# Apply ebuild and user patches. *MUST* be run or cmake_src_configure will fail.
-cmake_src_prepare() {
+# QA notice printout for build systems unsupported w/ CMake-4.
+_cmake4_callout() {
+	if [[ ${_CMAKE_MINREQVER_UNSUPPORTED} ]]; then
+		eqawarn "QA Notice: Compatibility with CMake < 3.5 has been removed from CMake 4,"
+		eqawarn "${CATEGORY}/${PN} will fail to build w/o a fix."
+		eqawarn "See also tracker bug #951350; check existing bug or file a new one for"
+		eqawarn "this package, and take it upstream."
+		if has_version -b ">=dev-build/cmake-4"; then
+			eqawarn "CMake 4 detected; building with -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
+			eqawarn "This is merely a workaround and *not* a permanent fix."
+		fi
+	fi
+}
+
+# @FUNCTION: cmake_prepare
+# @DESCRIPTION:
+# Check existence of and sanitise CMake files, then make ${CMAKE_USE_DIR}
+# read-only.  *MUST* be run or cmake_src_configure will fail.  EAPI-8 only.
+cmake_prepare() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	if [[ ${EAPI} == 7 ]]; then
-		pushd "${S}" > /dev/null || die # workaround from cmake-utils
-		# in EAPI-8, we use current working directory instead, bug #704524
-		# esp. test with 'special' pkgs like: app-arch/brotli, net-libs/quiche
+		eerror "${FUNCNAME} is EAPI-8 only. Call cmake_src_prepare instead."
+		die "FATAL: Forbidden function call."
 	fi
-	_cmake_check_build_dir
 
-	default_src_prepare
+	_cmake_check_build_dir
 
-	# check if CMakeLists.txt exists and if not then die
+	# Check if CMakeLists.txt exists and if not then die
 	if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
 		eerror "Unable to locate CMakeLists.txt under:"
 		eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
@@ -417,54 +435,68 @@ cmake_src_prepare() {
 		die "FATAL: Unable to find CMakeLists.txt"
 	fi
 
-	local modules_list
-	if [[ ${EAPI} == 7 && $(declare -p CMAKE_REMOVE_MODULES_LIST) != "declare -a"* ]]; then
-		modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
-	else
-		modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
-	fi
+	local modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
 
 	local name
 	for name in "${modules_list[@]}" ; do
-		if [[ ${EAPI} == 7 ]]; then
-			find "${S}" -name "${name}.cmake" -exec rm -v {} + || die
-		else
-			find -name "${name}.cmake" -exec rm -v {} + || die
-		fi
+		find -name "${name}.cmake" -exec rm -v {} + || die
 	done
 
 	# Remove dangerous things.
 	_cmake_modify-cmakelists
+	_cmake4_callout
 
-	if [[ ${_CMAKE_MINREQVER_UNSUPPORTED} ]]; then
-		eqawarn "QA Notice: Compatibility with CMake < 3.5 has been removed from CMake 4,"
-		eqawarn "${CATEGORY}/${PN} will fail to build w/o a fix."
-		eqawarn "See also tracker bug #951350; check existing bug or file a new one for"
-		eqawarn "this package, and take it upstream."
-		if has_version -b ">=dev-build/cmake-4"; then
-			eqawarn "CMake 4 detected; building with -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
-			eqawarn "This is merely a workaround and *not* a permanent fix."
-		fi
-		if [[ ${EAPI} == 7 ]]; then
-			eqawarn "QA Notice: EAPI=7 detected; this package is now a prime last-rites target."
-		fi
+	# Make ${CMAKE_USE_DIR} read-only in order to detect broken build systems
+	if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
+		chmod -R a-w "${CMAKE_USE_DIR}"
 	fi
 
+	_CMAKE_PREPARE_HAS_RUN=1
+}
+
+# @FUNCTION: cmake_src_prepare
+# @DESCRIPTION:
+# Apply ebuild and user patches via default_src_prepare.  In case of
+# conflict with another eclass' src_prepare phase, use cmake_prepare
+# instead (EAPI-8 only).
+# In EAPI-7, this phase *must* be run or cmake_src_configure will fail.
+cmake_src_prepare() {
+	debug-print-function ${FUNCNAME} "$@"
+
 	if [[ ${EAPI} == 7 ]]; then
+		pushd "${S}" > /dev/null || die # workaround from cmake-utils
+			default_src_prepare
+			_cmake_check_build_dir
+			# check if CMakeLists.txt exists and if not then die
+			if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
+				eerror "Unable to locate CMakeLists.txt under:"
+				eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
+				eerror "Consider not inheriting the cmake eclass."
+				die "FATAL: Unable to find CMakeLists.txt"
+			fi
+			local modules_list
+			if [[ $(declare -p CMAKE_REMOVE_MODULES_LIST) != "declare -a"* ]]; then
+				modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
+			else
+				modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
+			fi
+			local name
+			for name in "${modules_list[@]}" ; do
+				find "${S}" -name "${name}.cmake" -exec rm -v {} + || die
+			done
+			_cmake_modify-cmakelists # Remove dangerous things.
+			_cmake4_callout
 		popd > /dev/null || die
-	fi
-
-	# Make ${CMAKE_USE_DIR} (in EAPI-7: ${S}) read-only in order to detect
-	# broken build systems.
-	if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
-		if [[ ${EAPI} == 7 ]]; then
+		# Make ${S} read-only in order to detect broken build systems
+		if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
 			chmod -R a-w "${S}"
-		else
-			chmod -R a-w "${CMAKE_USE_DIR}"
 		fi
+		_CMAKE_PREPARE_HAS_RUN=1
+		eqawarn "QA Notice: cmake.eclass will throw unsupported EAPI=7 error after 2025-11-01."
+	else
+		default_src_prepare
+		cmake_prepare
 	fi
-
-	_CMAKE_SRC_PREPARE_HAS_RUN=1
 }
 
 # @VARIABLE: MYCMAKEARGS
@@ -490,8 +522,13 @@ cmake_src_prepare() {
 cmake_src_configure() {
 	debug-print-function ${FUNCNAME} "$@"
 
-	[[ ${_CMAKE_SRC_PREPARE_HAS_RUN} ]] || \
-		die "FATAL: cmake_src_prepare has not been run"
+	if [[ -z ${_CMAKE_PREPARE_HAS_RUN} ]]; then
+		if [[ ${EAPI} == 7 ]]; then
+			die "FATAL: cmake_src_prepare has not been run"
+		else
+			die "FATAL: cmake_src_prepare (or cmake_prepare) has not been run"
+		fi
+	fi
 
 	_cmake_check_build_dir
 
-- 
2.51.0


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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-02 18:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-02 18:02 [gentoo-dev] [PATCH] cmake.eclass: Provide cmake_prepare() to solve conflicts w/ other eclass Andreas Sturmlechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox