Skip to content

Commit

Permalink
make clean: split file list into manageable chunks
Browse files Browse the repository at this point in the history
"make clean" might fail with the following error:

  make[2]: execvp: /bin/bash: Argument list too long

This error was observed on a platform that has lots of additional
source files compared to upstream (drivers, etc.), and that sets a long
output path on the command line (make ... O=/some/long/path).

Fix the error by splitting the file list into more manageable chunks.
Note that removing one file at a time is not reasonable, because
spawning too may shells takes quite a long time (up to 7-10 seconds to
"make clean").

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reported-by: Lijianhui <airbak.li@hisilicon.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
jforissier committed Oct 26, 2017
1 parent e4a1f58 commit 4b358a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ include mk/cleandirs.mk
.PHONY: clean
clean:
@$(cmd-echo-silent) ' CLEAN $(out-dir)'
${q}rm -f $(cleanfiles)
$(call do-rm-f, $(cleanfiles))
${q}dirs="$(call cleandirs-for-rmdir)"; if [ "$$dirs" ]; then $(RMDIR) $$dirs; fi
@if [ "$(out-dir)" != "$(O)" ]; then $(cmd-echo-silent) ' CLEAN $(O)'; fi
${q}if [ -d "$(O)" ]; then $(RMDIR) $(O); fi
Expand Down
14 changes: 14 additions & 0 deletions mk/cleandirs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ $(eval _O:=$(if $(O),$(O),.))$(wildcard $(addprefix $(_O)/,$(call _reverse,
endef

RMDIR := rmdir --ignore-fail-on-non-empty

# Remove files with "rm -f".
# Split (possibly huge) file list into more manageable lines
# (200 files at a time), to minimize the odds of having:
# "/bin/bash: Argument list too long"
define do-rm-f
$(call _do-rm-f, $(wordlist 1, 200, $(1)))
$(eval _tail := $(wordlist 201, $(words $(1)), $(1)))
$(if $(_tail), $(call do-rm-f, $(_tail)))
endef

define _do-rm-f
${q}rm -f $1
endef

0 comments on commit 4b358a1

Please sign in to comment.