[RFC PATCH 09/11] kbuild: simplify commands in --dry-run mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- $filechk is used to check if a file is up to date.

- $cmd includes logic for echoing commands and deleting intermediate
  files on interrupt. Skip all of that in --dry-run mode and just execute
  the command.

- $cmd_and_savecmd executes the command and echoes it into .<target>.cmd.

- $if_changed_dep executes the command if any dependencies have changed.

- $cmd_and_fixdep executes the command and updates .<target>.cmd.

Skip all of that in --dry-run mode and just execute the command.

Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx>
---
 scripts/Kbuild.include | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index ed8a7493524b2..a1ef3b1828bb3 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -94,6 +94,7 @@ kecho := $($(quiet)kecho)
 # - If no file exist it is created
 # - If the content differ the new file is used
 # - If they are equal no change, and no timestamp update
+ifndef dry_run
 define filechk
 	$(check-FORCE)
 	$(Q)set -e;						\
@@ -105,6 +106,14 @@ define filechk
 		mv -f $(tmp-target) $@;				\
 	fi
 endef
+else
+# simplify and write the output directly if we're just printing
+# the commands
+define filechk
+	mkdir -p $(dir $@)
+	{ $(filechk_$(1)); } > $@
+endef
+endif
 
 ###
 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
@@ -149,8 +158,13 @@ delete-on-interrupt = \
 		$(foreach sig, HUP INT QUIT TERM PIPE, \
 			trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);))
 
+ifndef dry_run
 # print and execute commands
 cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cmd_$(1)),:)
+else
+# just execute (...which will actually "just print" with make -n)
+cmd = @$(if $(cmd_$(1)),$(cmd_$(1)),)
+endif
 
 ###
 # if_changed      - execute command if any prerequisite is newer than
@@ -196,17 +210,30 @@ if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE)
 # Execute command if command has changed or prerequisite(s) are updated.
 if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:)
 
+ifndef dry_run
 cmd_and_savecmd =                                                            \
 	$(cmd);                                                              \
 	printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd
+else
+cmd_and_savecmd = $(cmd)
+endif
 
+ifndef dry_run
 # Execute the command and also postprocess generated .d dependencies file.
 if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
+else
+# Just execute the command directly
+if_changed_dep = $(cmd)
+endif
 
+ifndef dry_run
 cmd_and_fixdep =                                                             \
 	$(cmd);                                                              \
 	scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
 	rm -f $(depfile)
+else
+cmd_and_fixdep = $(cmd)
+endif
 
 # Usage: $(call if_changed_rule,foo)
 # Will check if $(cmd_foo) or any of the prerequisites changed,
-- 
2.34.1





[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux