From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3748B15800F for ; Sun, 1 Jan 2023 16:00:05 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CD1FDE084A; Sun, 1 Jan 2023 16:00:00 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 8EBEAE07E6 for ; Sun, 1 Jan 2023 16:00:00 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 1/5] out-of-source-utils.eclass: New utility eclass Date: Sun, 1 Jan 2023 16:59:51 +0100 Message-Id: <20230101155955.965158-1-mgorny@gentoo.org> X-Mailer: git-send-email 2.39.0 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: b4ae5b2d-fe13-4a81-b510-8f00d5eae1ef X-Archives-Hash: 570f9faa7c752829d10fcb81a35af485 Introduce a new out-of-source-utils.eclass to carry run_in_build_dir() helper function. This function used to be defined in multibuild.eclass and indirectly exposed through the eclasses using it. However, it is used rather rarely and it is technically also useful for out-of-source.eclass, so it makes more sense for it to be standalone. In the end, eclasses are cheap. Signed-off-by: Michał Górny --- eclass/out-of-source-utils.eclass | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 eclass/out-of-source-utils.eclass diff --git a/eclass/out-of-source-utils.eclass b/eclass/out-of-source-utils.eclass new file mode 100644 index 000000000000..450237b224b3 --- /dev/null +++ b/eclass/out-of-source-utils.eclass @@ -0,0 +1,43 @@ +# Copyright 2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: out-of-source-utils.eclass +# @MAINTAINER: +# Michał Górny +# @AUTHOR: +# Michał Górny +# @SUPPORTED_EAPIS: 6 7 8 +# @BLURB: Utility functions for building packages out-of-source +# @DESCRIPTION: +# This eclass provides a run_in_build_dir() helper that can be used +# to execute specified command inside BUILD_DIR. + +case ${EAPI} in + 6|7|8) ;; + *) die "${ECLASS}: EAPI ${EAPI} unsupported." +esac + +if [[ ! ${_OUT_OF_SOURCE_UTILS_ECLASS} ]]; then +_OUT_OF_SOURCE_UTILS_ECLASS=1 + +# @FUNCTION: run_in_build_dir +# @USAGE: ... +# @DESCRIPTION: +# Run the given command in the directory pointed by BUILD_DIR. +run_in_build_dir() { + debug-print-function ${FUNCNAME} "${@}" + local ret + + [[ ${#} -eq 0 ]] && die "${FUNCNAME}: no command specified." + [[ -z ${BUILD_DIR} ]] && die "${FUNCNAME}: BUILD_DIR not set." + + mkdir -p "${BUILD_DIR}" || die + pushd "${BUILD_DIR}" >/dev/null || die + "${@}" + ret=${?} + popd >/dev/null || die + + return ${ret} +} + +fi -- 2.39.0