• [gentoo-dev] [PATCH] cmake.eclass: workaround S=${WORKDIR} creating bui

    From Sam James@21:1/5 to All on Mon Jun 26 12:00:01 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ulrich Mueller@21:1/5 to All on Mon Jun 26 12:40:01 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jaco Kroon@21:1/5 to Ulrich Mueller on Mon Jun 26 12:50:01 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ulrich Mueller@21:1/5 to All on Mon Jun 26 13:20:01 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam James@21:1/5 to Ulrich Mueller on Mon Jun 26 17:30:01 2023
    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.

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

    iOUEARYKAI0WIQQlpruI3Zt2TGtVQcJzhAn1IN+RkAUCZJmtuF8UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0MjVB NkJCODhERDlCNzY0QzZCNTU0MUMyNzM4NDA5RjUyMERGOTE5MA8cc2FtQGdlbnRv by5vcmcACgkQc4QJ9SDfkZDglgD/fN4/k3Klbwuzz2h5sxN4IAVYi4kkDEZlpAaf tQHwWEcBAPdNdKPO4rrXYP4zLlLNpn0iialVcEFYsnNgwOIETnUI
    =tVoU
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)