gbuild: removing stale files from $OUTDIR and $INSTDIR

David Tardon dtardon at redhat.com
Sat Apr 13 06:56:11 PDT 2013


Hi all,

I got an idea yesterday how to keep $OUTDIR (and $INSTDIR) free of stale
files in incremental builds (this has mainly been problem with headers),
by (ab)using the Deliver mechanism that is used for "make
showdeliverables", and knocked together an implementation of the idea.
Obviously, removing anything from the output dirs during build is a bit
risky (if a file is not properly registered by
gb_Deliver_add_deliverable, it will be removed. I must note here that I
have not found any problems with my configuration that builds
practically everything.), so it needs careful testing. It can also have
a performance impact. As I do not plan to continue to work on it in the
near future (I have enough ideas for gbuild that are far less disruptive
than this one :-), I am parking the patch there for reference. And if
there is someone willing to do the necessary testing and profiling, even
better :-)

D.
-------------- next part --------------
>From 66ce3692bda24f9836b9e48b779954dfabd25d2f Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon at redhat.com>
Date: Sat, 13 Apr 2013 11:00:25 +0200
Subject: [PATCH] remove stale files from $(OUTDIR) during build

Change-Id: I73ca65ba640f9b4d162a683f8111d90a101613b7
---
 solenv/gbuild/Deliver.mk | 34 ++++++++++++++++++++++++++++++++++
 solenv/gbuild/gbuild.mk  |  4 ++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/solenv/gbuild/Deliver.mk b/solenv/gbuild/Deliver.mk
index de47b2b..2da4865 100644
--- a/solenv/gbuild/Deliver.mk
+++ b/solenv/gbuild/Deliver.mk
@@ -37,10 +37,41 @@ else
 gb_Deliver_CLEARONDELIVER := $(true)
 endif
 
+gb_Deliver_TARGET := $(WORKDIR)/Deliver/cleanup
+gb_Deliver_CLEANTARGET := $(WORKDIR)/Clean/Deliver/cleanup
+
+define gb_Deliver__command
+$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),DEL,1)
+touch $(call var2file,$@.new,500,$(gb_Deliver_DELIVERABLES_OUTDIR)) && \
+$(if $(wildcard $@),\
+	tr ' ' "\n" < $@.new | sort > $@.new.list && \
+	tr ' ' "\n" < $@ | sort > $@.old.list && \
+	comm -23 $@.old.list $@.new.list | xargs rm -f && \
+	rm $@ $@.old.list $@.new.list && \
+) \
+mv $@.new $@
+endef
+
+$(dir $(gb_Deliver_TARGET)).dir :
+	$(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
+
+$(gb_Deliver_TARGET) : $(BUILDDIR)/config_$(gb_Side).mk
+	$(call gb_Deliver__command,$@)
+
+.PHONY : $(gb_Deliver_CLEANTARGET)
+$(gb_Deliver_CLEANTARGET) :
+	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(false),DEL,1)
 
 define gb_Deliver_init
 gb_Deliver_DELIVERABLES :=
 gb_Deliver_DELIVERABLES_INDEX := 
+# Just a plain list of files, used to remove outdated files from
+# output dirs.
+gb_Deliver_DELIVERABLES_OUTDIR :=
+
+$(gb_Deliver_TARGET) :| $(dir $(gb_Deliver_TARGET)).dir
+
+$$(eval $$(call gb_Module_register_target,$(gb_Deliver_TARGET),$(gb_Deliver_CLEANTARGET)))
 
 endef
 
@@ -55,6 +86,9 @@ define gb_Deliver_add_deliverable
 $$(if $(3),,$$(error - missing third parameter for deliverable $(1)))
 ifeq ($(MAKECMDGOALS),showdeliverables)
 $(call gb_Deliver_register_deliverable,$(1),$(2),$(3))
+else
+$(1) :| $(gb_Deliver_TARGET)
+gb_Deliver_DELIVERABLES_OUTDIR += $(1)
 endif
 
 endef
diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk
index 87a5c65..f622602 100644
--- a/solenv/gbuild/gbuild.mk
+++ b/solenv/gbuild/gbuild.mk
@@ -278,8 +278,6 @@ gb_GLOBALDEFS := $(sort $(gb_GLOBALDEFS))
 
 include $(GBUILDDIR)/Deliver.mk
 
-$(eval $(call gb_Deliver_init))
-
 # We are using a set of scopes that we might as well call classes.
 
 # It is important to include them in the right order as that is
@@ -346,6 +344,8 @@ include $(foreach class, \
 	PackageSet \
 ,$(GBUILDDIR)/$(class).mk)
 
+$(eval $(call gb_Deliver_init))
+
 $(eval $(call gb_Helper_process_executable_registrations))
 $(eval $(call gb_Postprocess_make_targets))
 
-- 
1.8.1.4



More information about the LibreOffice mailing list