From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-portage-dev+bounces-3760-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id 47AFF13877A
	for <garchives@archives.gentoo.org>; Mon, 18 Aug 2014 17:56:29 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 14479E0BA6;
	Mon, 18 Aug 2014 17:56:11 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 97F53E0BA5
	for <gentoo-portage-dev@lists.gentoo.org>; Mon, 18 Aug 2014 17:56:10 +0000 (UTC)
Received: from pomiot.lan (77-253-136-53.adsl.inetia.pl [77.253.136.53])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits))
	(No client certificate requested)
	(Authenticated sender: mgorny)
	by smtp.gentoo.org (Postfix) with ESMTPSA id 0B95633FFD1;
	Mon, 18 Aug 2014 17:56:08 +0000 (UTC)
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH 05/13] Add tentative support for EAPI6 eapply function
Date: Mon, 18 Aug 2014 19:56:44 +0200
Message-Id: <1408384612-14713-6-git-send-email-mgorny@gentoo.org>
X-Mailer: git-send-email 2.0.4
In-Reply-To: <1408384612-14713-1-git-send-email-mgorny@gentoo.org>
References: <1408384612-14713-1-git-send-email-mgorny@gentoo.org>
Precedence: bulk
List-Post: <mailto:gentoo-portage-dev@lists.gentoo.org>
List-Help: <mailto:gentoo-portage-dev+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-portage-dev+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-portage-dev+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-portage-dev.gentoo.org>
X-BeenThere: gentoo-portage-dev@lists.gentoo.org
Reply-to: gentoo-portage-dev@lists.gentoo.org
X-Archives-Salt: 8cb3046f-e5e6-417e-9a24-d46f59c35b6a
X-Archives-Hash: 45b7311a316f124ca93b655e75eb59ba

Add the eapply patch applying function.
---
 bin/eapi.sh          |  4 ++++
 bin/phase-helpers.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/bin/eapi.sh b/bin/eapi.sh
index 978a410..8ffffbb 100644
--- a/bin/eapi.sh
+++ b/bin/eapi.sh
@@ -72,6 +72,10 @@ ___eapi_has_einstalldocs() {
 	[[ ! ${1-${EAPI}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]]
 }
 
+___eapi_has_eapply() {
+	[[ ! ${1-${EAPI}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]]
+}
+
 ___eapi_has_master_repositories() {
 	[[ ${1-${EAPI}} =~ ^(5-progress)$ ]]
 }
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 6ccf4f4..6bd8a12 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -875,6 +875,58 @@ if ___eapi_has_einstalldocs; then
 	}
 fi
 
+if ___eapi_has_eapply; then
+	eapply() {
+		_eapply_patch() {
+			started_applying=1
+			ebegin "Applying ${1#${top_dir}/}"
+			# -p1 as a sane default
+			# -f to avoid interactivity
+			# -s to silence progress output
+			patch -p1 -f -s "${patch_options[@]}" < "${1}"
+			if ! eend ${?}; then
+				__helpers_die "patch -p1 ${patch_options[*]} failed with ${1}"
+				failed=1
+			fi
+		}
+
+		local f patch_options=() failed started_applying options_terminated
+		for f; do
+			local top_dir=${f%/*}
+
+			if [[ ${f} == -* && -z ${options_terminated} ]]; then
+				if [[ -n ${started_applying} ]]; then
+					die "eapply: options need to be specified before files"
+				fi
+				if [[ ${f} == -- ]]; then
+					options_terminated=1
+				else
+					patch_options+=( ${f} )
+				fi
+			elif [[ -d ${f} ]]; then
+				local prev_shopt=$(shopt -p nullglob)
+				shopt -s nullglob
+				local files=( "${f}"/*.{patch,diff} )
+				${prev_shopt}
+
+				[[ -z ${files[@]} ]] && die "No *.{patch,diff} files in directory ${f}"
+
+				local f2
+				for f2 in "${files[@]}"; do
+					_eapply_patch "${f2}"
+				done
+			else
+				_eapply_patch "${f}"
+			fi
+
+			# in case of nonfatal
+			[[ -n ${failed} ]] && return 1
+		done
+
+		return 0
+	}
+fi
+
 if ___eapi_has_master_repositories; then
 	master_repositories() {
 		local output repository=$1 retval
-- 
2.0.4