From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id DDD7313838B for ; Tue, 30 Sep 2014 21:59:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6A085E08FB; Tue, 30 Sep 2014 21:59:32 +0000 (UTC) Received: from mail-pd0-f202.google.com (mail-pd0-f202.google.com [209.85.192.202]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5D1A5E08D0 for ; Tue, 30 Sep 2014 21:59:31 +0000 (UTC) Received: by mail-pd0-f202.google.com with SMTP id fp1so1397696pdb.5 for ; Tue, 30 Sep 2014 14:59:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aJi0yFPR/mXVr8OYhI9/ibvpEelMdycZcri1oBPH5kA=; b=SUcxb2stfrvh0F7yeJFppT0vt4R9l3jirAOAOcY2p2hmN0R42qXkNAGB/13ntkH4bI sLvu5QhIdiddPxmH/D6UJiwaYwZhLiif9FiQPAm+jgLZRLOMUyNj88pYSfuZgIIMU8Er 4va7HPNBMc2Mad3K5/buTQsc3o/K0+vXgHgEYji6nQ8Ltm5wZbbKctbEvegP1Af0+G6w iKLauLP3uuaTpP2U3vL5BRe+JrSwNvWklIIGNdv+SAkplBE+99xvNJK4MDpl1l4AE2Q2 x7JolphajEqB5Kt9uAgqNaLFwSPlwUTLZffRiPw67dGL34zK0J98fsxmG/XxvrTx/8kg th/g== X-Gm-Message-State: ALoCoQlqKqOJNLsydfm82rvZ1f+MY4ncUnPhoQXrMAATZQEe2l+al/S2m9hRnidsksPv6Y9dvJoj X-Received: by 10.66.218.162 with SMTP id ph2mr42569956pac.3.1412114369940; Tue, 30 Sep 2014 14:59:29 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id e24si949315yhe.3.2014.09.30.14.59.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Sep 2014 14:59:29 -0700 (PDT) Received: from bsimonnet-linux.mtv.corp.google.com ([172.22.64.31]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id qGRwtTEl.1; Tue, 30 Sep 2014 14:59:29 -0700 Received: by bsimonnet-linux.mtv.corp.google.com (Postfix, from userid 235571) id AC4E8202EEB; Mon, 29 Sep 2014 15:32:07 -0700 (PDT) From: Bertrand SIMONNET To: gentoo-portage-dev@lists.gentoo.org Cc: Bertrand SIMONNET Subject: [gentoo-portage-dev] [PATCH 1/3] Refactor bashrc scripts sourcing Date: Mon, 29 Sep 2014 15:31:51 -0700 Message-Id: <1412029913-13421-2-git-send-email-bsimonnet@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1412029913-13421-1-git-send-email-bsimonnet@chromium.org> References: <5425944A.2090404@gentoo.org> <1412029913-13421-1-git-send-email-bsimonnet@chromium.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: d92e6b8f-b495-4a8e-9bb7-bc050a31435d X-Archives-Hash: a13c05766f46798e88fb75126616709d Creates two new helper functions __try_source and __source_env_files to simplify __source_all_bashrcs. --- bin/ebuild.sh | 75 +++++++++++++++++++++++++++++++++----------------- bin/save-ebuild-env.sh | 1 + 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/bin/ebuild.sh b/bin/ebuild.sh index be044e0..14cc321 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -375,39 +375,64 @@ __source_all_bashrcs() { done fi - if [ -r "${PORTAGE_BASHRC}" ] ; then - if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then - source "${PORTAGE_BASHRC}" - else - set -x - source "${PORTAGE_BASHRC}" - set +x - fi - fi + # The user's bashrc is the ONLY non-portage bit of code + # that can change shopts without a QA violation. + __try_source --no-qa "${PORTAGE_BASHRC}" if [[ $EBUILD_PHASE != depend ]] ; then - # The user's bashrc is the ONLY non-portage bit of code that can - # change shopts without a QA violation. - for x in "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT%/*},${P},${PF}}; do - if [ -r "${x}" ]; then - # If $- contains x, then tracing has already been enabled - # elsewhere for some reason. We preserve it's state so as - # not to interfere. - if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then - source "${x}" - else - set -x - source "${x}" - set +x - fi - fi - done + __source_env_files --no-qa "${PM_EBUILD_HOOK_DIR}" fi [ ! -z "${OCC}" ] && export CC="${OCC}" [ ! -z "${OCXX}" ] && export CXX="${OCXX}" } +# @FUNCTION: __source_env_files +# @USAGE: [--no-qa] +# @DESCRIPTION: +# Source the files relevant to the current package from the given path. +# If --no-qa is specified, use source instead of __qa_source to source the +# files. +__source_env_files() { + local argument=() + if [[ $1 == --no-qa ]]; then + argument=( --no-qa ) + shift + fi + for x in "${1}"/${CATEGORY}/{${PN},${PN}:${SLOT%/*},${P},${PF}}; do + __try_source "${argument[@]}" "${x}" + done +} + +# @FUNCTION: __try_source +# @USAGE: [--no-qa] +# @DESCRIPTION: +# If the path given as argument exists, source the file while preserving +# $-. +# If --no-qa is specified, source the file with source instead of __qa_source. +__try_source() { + local qa=true + if [[ $1 == --no-qa ]]; then + qa=false + shift + fi + if [[ -r "$1" ]]; then + local debug_on=false + if [[ "$PORTAGE_DEBUG" == "1" ]] && [[ "${-/x/}" == "$-" ]]; then + debug_on=true + fi + $debug_on && set -x + # If $- contains x, then tracing has already been enabled + # elsewhere for some reason. We preserve it's state so as + # not to interfere. + if [[ ${qa} ]]; then + source "${1}" + else + __qa_source "${1}" + fi + $debug_on && set +x + fi +} # === === === === === === === === === === === === === === === === === === # === === === === === functions end, main part begins === === === === === # === === === === === === === === === === === === === === === === === === diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh index 98cff83..f114c48 100644 --- a/bin/save-ebuild-env.sh +++ b/bin/save-ebuild-env.sh @@ -75,6 +75,7 @@ __save_ebuild_env() { __ebuild_main __ebuild_phase __ebuild_phase_with_hooks \ __ebuild_arg_to_phase __ebuild_phase_funcs default \ __unpack_tar __unset_colors \ + __source_env_files __try_source \ ${QA_INTERCEPTORS} ___eapi_has_usex && unset -f usex -- 2.1.0.rc2.206.gedb03e5