Skip to content

Commit 9a234a2

Browse files
committed
kbuild: create directory for make cache only when necessary
Currently, the existence of $(dir $(make-cache)) is always checked, and created if it is missing. We can avoid unnecessary system calls by some tricks. [1] If KBUILD_SRC is unset, we are building in the source tree. The output directory checks can be entirely skipped. [2] If at least one cache data is found, it means the cache file was included. Obviously its directory exists. Skip "mkdir -p". [3] If Makefile does not contain any call of __run-and-store, it will not create a cache file. No need to create its directory. [4] The "mkdir -p" should be only invoked by the first call of __run-and-store Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Douglas Anderson <[email protected]>
1 parent 859fd58 commit 9a234a2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scripts/Kbuild.include

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,19 @@ cc-cross-prefix = \
9999

100100
# Include values from last time
101101
make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk
102-
ifeq ($(wildcard $(dir $(make-cache))),)
103-
$(shell mkdir -p '$(dir $(make-cache))')
104-
endif
105102
$(make-cache): ;
106103
-include $(make-cache)
107104

105+
cached-data := $(filter __cached_%, $(.VARIABLES))
106+
108107
# If cache exceeds 1000 lines, shrink it down to 500.
109-
ifneq ($(word 1000,$(filter __cached_%, $(.VARIABLES))),)
108+
ifneq ($(word 1000,$(cached-data)),)
110109
$(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \
111110
mv $(make-cache).tmp $(make-cache))
112111
endif
113112

113+
create-cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,1))
114+
114115
# Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios)
115116
#
116117
# Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_'
@@ -136,6 +137,10 @@ __sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$
136137
define __run-and-store
137138
ifeq ($(origin $(1)),undefined)
138139
$$(eval $(1) := $$(shell $$(2)))
140+
ifeq ($(create-cache-dir),1)
141+
$$(shell mkdir -p $(dir $(make-cache)))
142+
$$(eval create-cache-dir :=)
143+
endif
139144
$$(shell echo '$(1) := $$($(1))' >> $(make-cache))
140145
endif
141146
endef

0 commit comments

Comments
 (0)