From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Masahiro Yamada <masahiroy@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Nicolas Schier <nicolas@fjasle.eu>
Subject: [PATCH 2/5] kbuild: print short log in addition to the whole command with V=1
Date: Fri, 23 Dec 2022 01:25:32 +0900 [thread overview]
Message-ID: <20221222162535.1578462-2-masahiroy@kernel.org> (raw)
In-Reply-To: <20221222162535.1578462-1-masahiroy@kernel.org>
"make V=1" prints the whole command instead of the short log, but I
think it is nicer to print both so that you can easily spot the build
rule of your interest.
This commit changes V=1 to print the short log (the line starts with
'#'), followed by the full log.
In parallel builds, the short/full logs from the same build rule may
be interspersed. To avoid it, please add -Otarget along with the -j<N>
option. Kbuild will never set -Otarget by default because Make would
buffer the logs and lose the escape sequences. (Modern compilers print
warnings and errors in color, but only when they write to a terminal.)
This is also a preparation for supporting V=12 because V=2 appends the
reason for rebuilding to the short log.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
Makefile | 18 +++++++-----------
scripts/Kbuild.include | 26 +++++++++++++-------------
2 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/Makefile b/Makefile
index e8ce3e2b30d6..ce98dfd8359a 100644
--- a/Makefile
+++ b/Makefile
@@ -56,22 +56,18 @@ unexport GREP_OPTIONS
# Beautify output
# ---------------------------------------------------------------------------
#
-# Normally, we echo the whole command before executing it. By making
-# that echo $($(quiet)$(cmd)), we now have the possibility to set
-# $(quiet) to choose other forms of output instead, e.g.
+# Most of build commands in Kbuild start with "cmd_". You can optionally define
+# "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from
+# that command is printed by default.
#
-# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
-# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
-#
-# If $(quiet) is empty, the whole command will be printed.
-# If it is set to "quiet_", only the short version will be printed.
-# If it is set to "silent_", nothing will be printed at all, since
-# the variable $(silent_cmd_cc_o_c) doesn't exist.
+# e.g.)
+# quiet_cmd_depmod = DEPMOD $(MODLIB)
+# cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE)
#
# A simple variant is to prefix commands with $(Q) - that's useful
# for commands that shall be hidden in non-verbose mode.
#
-# $(Q)ln $@ :<
+# $(Q)$(MAKE) $(build)=scripts/basic
#
# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
# If KBUILD_VERBOSE equals 1 then the above command is displayed.
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 2f7356b2990b..faae3c7986b0 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -125,15 +125,15 @@ dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
# $(Q)$(MAKE) $(clean)=dir
clean := -f $(srctree)/scripts/Makefile.clean obj
-# echo command.
-# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
-echo-cmd = $(if $($(quiet)cmd_$(1)),\
- echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
-
-# sink stdout for 'make -s'
- redirect :=
- quiet_redirect :=
-silent_redirect := exec >/dev/null;
+# pring log
+#
+# If quiet is "silent_", print nothing and sink stdout
+# If quiet is "quiet_", print short log
+# If quiet is empty, print short log and whole command
+silent_log_print = exec >/dev/null;
+ quiet_log_print = $(if $(quiet_cmd_$1), echo ' $(call escsq,$(quiet_cmd_$1)$(why))';)
+ log_print = echo '$(pound) $(call escsq,$(or $(quiet_cmd_$1),cmd_$1 $@))'; \
+ echo ' $(call escsq,$(cmd_$1))';
# Delete the target on interruption
#
@@ -156,8 +156,8 @@ delete-on-interrupt = \
$(foreach sig, HUP INT QUIT TERM PIPE, \
trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);))
-# printing commands
-cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(delete-on-interrupt) $(cmd_$(1))
+# print and execute commands
+cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cmd_$(1)),:)
###
# if_changed - execute command if any prerequisite is newer than
@@ -234,7 +234,7 @@ if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:)
# (6) No dir/.target.cmd file and target not listed in $(targets)
# This is a good hint that there is a bug in the kbuild file
ifeq ($(KBUILD_VERBOSE),2)
-why = \
+_why = \
$(if $(filter $@, $(PHONY)),- due to target is PHONY, \
$(if $(wildcard $@), \
$(if $(newer-prereqs),- due to: $(newer-prereqs), \
@@ -251,7 +251,7 @@ why = \
) \
)
-echo-why = $(call escsq, $(strip $(why)))
+why = $(space)$(strip $(_why))
endif
###############################################################################
--
2.34.1
next prev parent reply other threads:[~2022-12-22 16:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 16:25 [PATCH 1/5] kbuild: refactor silent mode detection Masahiro Yamada
2022-12-22 16:25 ` Masahiro Yamada [this message]
2022-12-23 11:23 ` [PATCH 2/5] kbuild: print short log in addition to the whole command with V=1 Nicolas Schier
2022-12-22 16:25 ` [PATCH 3/5] kbuild: do not print extra logs for V=2 Masahiro Yamada
2022-12-23 11:23 ` Nicolas Schier
2022-12-22 16:25 ` [PATCH 4/5] kbuild: allow to combine multiple V= levels Masahiro Yamada
2022-12-23 11:23 ` Nicolas Schier
2022-12-22 16:25 ` [PATCH 5/5] kbuild: drop V=0 support Masahiro Yamada
2022-12-23 11:24 ` Nicolas Schier
2022-12-22 17:51 ` [PATCH 1/5] kbuild: refactor silent mode detection Nick Desaulniers
2022-12-23 11:23 ` Nicolas Schier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221222162535.1578462-2-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=nicolas@fjasle.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox