From patchwork Thu Jan 10 20:30:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 1023207 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43bHgJ1DZqz9s2P for ; Fri, 11 Jan 2019 07:30:19 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id EC4C286E0A; Thu, 10 Jan 2019 20:30:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Xtt+r6KTnQ4c; Thu, 10 Jan 2019 20:30:15 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 0A4EC86D08; Thu, 10 Jan 2019 20:30:15 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 9BD1F1BF3E0 for ; Thu, 10 Jan 2019 20:30:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 9929E2E3E4 for ; Thu, 10 Jan 2019 20:30:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qVPZrK4+1mOB for ; Thu, 10 Jan 2019 20:30:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by silver.osuosl.org (Postfix) with ESMTP id DEBC02E2C6 for ; Thu, 10 Jan 2019 20:30:12 +0000 (UTC) Received: by mail.bootlin.com (Postfix, from userid 110) id 862212078E; Thu, 10 Jan 2019 21:30:11 +0100 (CET) Received: from localhost (lfbn-tou-1-411-96.w86-206.abo.wanadoo.fr [86.206.237.96]) by mail.bootlin.com (Postfix) with ESMTPSA id 5491A20432; Thu, 10 Jan 2019 21:30:11 +0100 (CET) From: Thomas Petazzoni To: buildroot@buildroot.org Date: Thu, 10 Jan 2019 21:30:04 +0100 Message-Id: <20190110203004.9812-1-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Buildroot] [PATCH] support/scripts/apply-patches: use "git apply" as a fallback when applying patches X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kostya Porotchkin , Thomas Petazzoni Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" We currently use plain old "patch" to apply patches. While this works fine in most situations, it doesn't work well for patches generated with git format-patch that: - Contain changes to binary files - Or contain changes to files in directories that were symlinks to other directories, with the symlink being removed as part of the same patch. We encountered such issues with a large stack of patches to be applied on top of arm-trusted-firmware. Such patches apply perfectly fine with "git apply". Switching everybody to unconditionally use "git apply" seems a bit risky, so instead we take a different route: if applying the patch with "patch" fails, then we try with "git apply". A few implementation notes: - The script has "set -e" so for the "patch --dry-run" command, we have to take special precautions to not bail out of the script on error. - Also due to "set -e", the check on the return value of "patch" is no longer needed, and we also don't need to check the return value of "git apply". - We need to pass "--git-dir=/dev/null", otherwise "git apply" travels up the directory hierarchy until it finds a .git folder. If it finds one, but the files being patched are not under version control, it skips patching those files. Obviously, the files in output/build/foo/ are not under version control, so this behavior is not desirable. Simply making "git apply" believe it is not running from inside a Git repository disables this check. Cc: Kostya Porotchkin Signed-off-by: Thomas Petazzoni --- support/scripts/apply-patches.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/support/scripts/apply-patches.sh b/support/scripts/apply-patches.sh index 66fef262ee..0fd336968e 100755 --- a/support/scripts/apply-patches.sh +++ b/support/scripts/apply-patches.sh @@ -119,11 +119,18 @@ function apply_patch { exit 1 fi echo "${path}/${patch}" >> ${builddir}/.applied_patches_list - ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t -N $silent - if [ $? != 0 ] ; then - echo "Patch failed! Please fix ${patch}!" - exit 1 + + # We don't want this to abort the script on failure (script is run + # with set -e) + ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" --dry-run -t -N -s && retval=0 || retval=$? + if [ $retval -eq 0 ] ; then + ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t -N $silent + # Due to set -e, if we reach here, applying the patch was successful + return fi + + [ -z "${silent}" ] && gitopts=-v + (cd ${builddir}; ${uncomp} "${path}/$patch" | git --git-dir=/dev/null apply -p1 ${gitopts}) } function scan_patchdir {