public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating builddir above ${WORKDIR}
@ 2023-06-26  9:57 Sam James
  2023-06-26 10:36 ` Ulrich Mueller
  0 siblings, 1 reply; 5+ messages in thread
From: Sam James @ 2023-06-26  9:57 UTC (permalink / raw
  To: gentoo-dev; +Cc: base-system, kde, Sam James

When S=${WORKDIR}, cmake.eclass would create its build directory (if CMAKE_USE_DIR
is unset) above WORKDIR(!) as ${WORKDIR}_build. Creating directories above
WORKDIR is not legal.

Portage has its own bug (bug #889418) in that it doesn't clean up unknown directories
above WORKDIR in PORTAGE_TMPDIR, so combined, you get a problem where "ebuild ... clean" doesn't
actually clean things up at all, and you get very confusing issues if e.g. changing
CC between runs.

The explicit S=WORKDIR check isn't truly needed but it makes explicit our
intent here.

Bug: https://bugs.gentoo.org/889418
Closes: https://bugs.gentoo.org/889420
Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/cmake.eclass | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
index 1cdbc123a243..4050beb22ba3 100644
--- a/eclass/cmake.eclass
+++ b/eclass/cmake.eclass
@@ -293,6 +293,15 @@ _cmake_check_build_dir() {
 		BUILD_DIR="${CMAKE_USE_DIR}"
 	else
 		: "${BUILD_DIR:=${CMAKE_USE_DIR}_build}"
+
+		# Avoid creating ${WORKDIR}_build (which is above WORKDIR).
+		# TODO: For EAPI > 8, we should ban S=WORKDIR for CMake.
+		# See bug #889420.
+		if [[ ${S} == ${WORKDIR} && ${BUILD_DIR} == ${WORKDIR}_build ]] ; then
+			eqawarn "QA notice: S=WORKDIR is deprecated for cmake.eclass."
+			eqawarn "Please relocate the sources in src_unpack."
+			BUILD_DIR="${WORKDIR}"/${P}_build
+		fi
 	fi
 
 	einfo "Source directory (CMAKE_USE_DIR): \"${CMAKE_USE_DIR}\""
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating builddir above ${WORKDIR}
  2023-06-26  9:57 [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating builddir above ${WORKDIR} Sam James
@ 2023-06-26 10:36 ` Ulrich Mueller
  2023-06-26 10:45   ` Jaco Kroon
  2023-06-26 15:24   ` Sam James
  0 siblings, 2 replies; 5+ messages in thread
From: Ulrich Mueller @ 2023-06-26 10:36 UTC (permalink / raw
  To: Sam James; +Cc: gentoo-dev, base-system, kde

>>>>> On Mon, 26 Jun 2023, Sam James wrote:

> +
> +		# Avoid creating ${WORKDIR}_build (which is above WORKDIR).
> +		# TODO: For EAPI > 8, we should ban S=WORKDIR for CMake.
> +		# See bug #889420.
> +		if [[ ${S} == ${WORKDIR} && ${BUILD_DIR} == ${WORKDIR}_build ]] ; then

I'd suggest adding quotes to the RHS of the expression, to prevent
globbing.

But I think what you really want is to check whether ${BUILD_DIR}
(whatever its name is) is a subdirectory of ${WORKDIR}? Maybe a test
like this would make that intent clearer:

    if [[ ${BUILD_DIR} != "${WORKDIR}"/* ]]; then

> +			eqawarn "QA notice: S=WORKDIR is deprecated for cmake.eclass."
> +			eqawarn "Please relocate the sources in src_unpack."
> +			BUILD_DIR="${WORKDIR}"/${P}_build
> +		fi


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating builddir above ${WORKDIR}
  2023-06-26 10:36 ` Ulrich Mueller
@ 2023-06-26 10:45   ` Jaco Kroon
  2023-06-26 11:14     ` Ulrich Mueller
  2023-06-26 15:24   ` Sam James
  1 sibling, 1 reply; 5+ messages in thread
From: Jaco Kroon @ 2023-06-26 10:45 UTC (permalink / raw
  To: gentoo-dev, Ulrich Mueller, Sam James; +Cc: base-system, kde

Hi,

On 2023/06/26 12:36, Ulrich Mueller wrote:
>>>>>> On Mon, 26 Jun 2023, Sam James wrote:
>> +
>> +		# Avoid creating ${WORKDIR}_build (which is above WORKDIR).
>> +		# TODO: For EAPI > 8, we should ban S=WORKDIR for CMake.
>> +		# See bug #889420.
>> +		if [[ ${S} == ${WORKDIR} && ${BUILD_DIR} == ${WORKDIR}_build ]] ; then
> I'd suggest adding quotes to the RHS of the expression, to prevent
> globbing.
>
> But I think what you really want is to check whether ${BUILD_DIR}
> (whatever its name is) is a subdirectory of ${WORKDIR}? Maybe a test
> like this would make that intent clearer:
>
>      if [[ ${BUILD_DIR} != "${WORKDIR}"/* ]]; then

BUILD_DIR="${WORKDIR}/../build"

I know it's pathological ... but still.  readlink -f should be 
considered here unless it can be guaranteed that BUILD_DIR will not 
contain .. components at this stage.

Kind Regards,
Jaco



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating builddir above ${WORKDIR}
  2023-06-26 10:45   ` Jaco Kroon
@ 2023-06-26 11:14     ` Ulrich Mueller
  0 siblings, 0 replies; 5+ messages in thread
From: Ulrich Mueller @ 2023-06-26 11:14 UTC (permalink / raw
  To: Jaco Kroon; +Cc: gentoo-dev, Sam James, base-system, kde

>>>>> On Mon, 26 Jun 2023, Jaco Kroon wrote:

>> if [[ ${BUILD_DIR} != "${WORKDIR}"/* ]]; then

> BUILD_DIR="${WORKDIR}/../build"

Oh right, I hadn't thought about the case that the ebuild would override
it. (AFAICS cmake.eclass itself doesn't do .. in BUILD_DIR.)

> I know it's pathological ... but still.  readlink -f should be
> considered here unless it can be guaranteed that BUILD_DIR will not
> contain .. components at this stage.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating builddir above ${WORKDIR}
  2023-06-26 10:36 ` Ulrich Mueller
  2023-06-26 10:45   ` Jaco Kroon
@ 2023-06-26 15:24   ` Sam James
  1 sibling, 0 replies; 5+ messages in thread
From: Sam James @ 2023-06-26 15:24 UTC (permalink / raw
  To: gentoo-dev; +Cc: base-system, kde

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


Ulrich Mueller <ulm@gentoo.org> writes:

>>>>>> On Mon, 26 Jun 2023, Sam James wrote:
>
>> +
>> +		# Avoid creating ${WORKDIR}_build (which is above WORKDIR).
>> +		# TODO: For EAPI > 8, we should ban S=WORKDIR for CMake.
>> +		# See bug #889420.
>> +		if [[ ${S} == ${WORKDIR} && ${BUILD_DIR} == ${WORKDIR}_build ]] ; then
>
> I'd suggest adding quotes to the RHS of the expression, to prevent
> globbing.

I'm fine with quoting the RHS, but I don't think it's worth making the
other changes given this works and it's already an edge case.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 377 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-26 15:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-26  9:57 [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating builddir above ${WORKDIR} Sam James
2023-06-26 10:36 ` Ulrich Mueller
2023-06-26 10:45   ` Jaco Kroon
2023-06-26 11:14     ` Ulrich Mueller
2023-06-26 15:24   ` Sam James

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