From 7a523569f7f403cdd7c2074cc49920f1dd7ecc70 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 18 Jan 2017 15:37:57 +0100 Subject: build: add support for automatically removing build dir contents during build This is used to save space on buildbot instances. If any part of a package needs to be rebuild, the whole package is rebuilt from scratch. Stamp files are preserved to allow dependency checks to work Signed-off-by: Felix Fietkau --- include/subdir.mk | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'include/subdir.mk') diff --git a/include/subdir.mk b/include/subdir.mk index 7e0c474035..e76a01e18a 100644 --- a/include/subdir.mk +++ b/include/subdir.mk @@ -29,6 +29,11 @@ endef lastdir=$(word $(words $(subst /, ,$(1))),$(subst /, ,$(1))) diralias=$(if $(findstring $(1),$(call lastdir,$(1))),,$(call lastdir,$(1))) +subdir_make_opts = \ + -r -C $(1) \ + BUILD_SUBDIR="$(1)" \ + BUILD_VARIANT="$(4)" + # 1: subdir # 2: target # 3: build type @@ -38,11 +43,19 @@ log_make = \ $(if $(BUILD_LOG), \ set -o pipefail; \ mkdir -p $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4));) \ - $$(SUBMAKE) -r -C $(1) $(if $(3),$(3)-)$(2) \ - BUILD_SUBDIR="$(1)" \ - BUILD_VARIANT="$(4)" \ + $$(SUBMAKE) $(subdir_make_opts) $(if $(3),$(3)-)$(2) \ $(if $(BUILD_LOG),SILENT= 2>&1 | tee $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4))/$(if $(3),$(3)-)$(2).txt) +ifdef CONFIG_AUTOREMOVE +rebuild_check = \ + @-$$(NO_TRACE_MAKE) $(subdir_make_opts) check-depends >/dev/null 2>/dev/null; \ + $(if $(BUILD_LOG),mkdir -p $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4));) \ + $$(NO_TRACE_MAKE) $(if $(BUILD_LOG),-d) -q $(subdir_make_opts) .$(if $(3),$(3)-)$(2) \ + > $(if $(BUILD_LOG),$(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4))/check-$(if $(3),$(3)-)$(2).txt,/dev/null) 2>&1 || \ + $$(SUBMAKE) $(subdir_make_opts) clean >/dev/null 2>/dev/null + +endif + # Parameters: define subdir $(call warn,$(1),d,D $(1)) @@ -58,6 +71,7 @@ define subdir $(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(target): $(if $(QUILT),,$($(1)/$(bd)/$(target)) $(call $(1)//$(target),$(1)/$(bd)))) $(foreach variant,$(if $(BUILD_VARIANT),$(BUILD_VARIANT),$(if $(strip $($(1)/$(bd)/variants)),$($(1)/$(bd)/variants),$(if $($(1)/$(bd)/default-variant),$($(1)/$(bd)/default-variant),__default))), $(if $(BUILD_LOG),@mkdir -p $(BUILD_LOG_DIR)/$(1)/$(bd)/$(filter-out __default,$(variant))) + $(if $($(1)/autoremove),$(call rebuild_check,$(1)/$(bd),$(target),,$(filter-out __default,$(variant)))) $(call log_make,$(1)/$(bd),$(target),,$(filter-out __default,$(variant))) \ $(if $(findstring $(bd),$($(1)/builddirs-ignore-$(target))), || $(call ERROR,$(1), ERROR: $(1)/$(bd) failed to build$(if $(filter-out __default,$(variant)), (build variant: $(variant))).)) ) -- cgit v1.2.3