From patchwork Thu Jul 12 22:17:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 10522371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4CD2D6028E for ; Thu, 12 Jul 2018 22:17:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C50929A3A for ; Thu, 12 Jul 2018 22:17:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30D8829AC0; Thu, 12 Jul 2018 22:17:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAEB529A3A for ; Thu, 12 Jul 2018 22:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732582AbeGLW3F (ORCPT ); Thu, 12 Jul 2018 18:29:05 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:38059 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732298AbeGLW3F (ORCPT ); Thu, 12 Jul 2018 18:29:05 -0400 Received: from ben by shadbolt.decadent.org.uk with local (Exim 4.84_2) (envelope-from ) id 1fdjty-0007k5-8L for linux-kbuild@vger.kernel.org; Thu, 12 Jul 2018 23:17:30 +0100 Date: Thu, 12 Jul 2018 23:17:30 +0100 From: Ben Hutchings To: linux-kbuild@vger.kernel.org Message-ID: <20180712221730.GK14131@decadent.org.uk> References: <20180712221619.GH14131@decadent.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180712221619.GH14131@decadent.org.uk> User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: ben@decadent.org.uk Subject: [RFC PATCH 3/3] kbuild: In quiet mode, print the full command line if it fails X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on shadbolt.decadent.org.uk) Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the $(run-cmd) macro, add a trap on EXIT that prints the full command line. Remove the trap after running the command(s) successfully. (A more straightforward approach would be to use "if" or "||" to test for failure, but that doesn't work. Some command lines given to $(run-cmd) have multiple commands separated by semi-colons, and the caller must run "set -e" to enable exit-on-error. Testing the result of such a command line, even if it is probably grouped and run in a sub-shell, inhibits exit-on-error and would cause some errors to be ignored.) Signed-off-by: Ben Hutchings --- scripts/Kbuild.include | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 8778ae4a3476..c2525aaa36ac 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -224,7 +224,10 @@ flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) echo-cmd = $(if $($(quiet)cmd_$(1)),\ echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) -run-cmd = $(echo-cmd) $(cmd_$(1)) +trap-cmd-failed = trap 'test $$? = 0 || echo Failed command: '\''$(call escsq,$(call escsq,$(cmd_$(1))))'\' EXIT +untrap-cmd-failed = trap - EXIT + +run-cmd = $(echo-cmd) $(if $(cmd_$(1)), $(if $(quiet), $(trap-cmd-failed); $(cmd_$(1)); $(untrap-cmd-failed), $(cmd_$(1)))) # printing commands cmd = @$(run-cmd)