From 23d1e4255bf7ddfadf5e5d3eaa40505e1df4dfc5 Mon Sep 17 00:00:00 2001 From: Modestas Vainius Date: Thu, 11 Jun 2009 03:48:39 +0300 Subject: Remove empty build directory parent dirs (up to source directory) too. When rmdir_building(), if build directory has 2 or more levels, empty parent dirs should also be deleted until source directory level. Signed-off-by: Modestas Vainius --- Debian/Debhelper/Buildsystem.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm index 85a14013..6842e348 100644 --- a/Debian/Debhelper/Buildsystem.pm +++ b/Debian/Debhelper/Buildsystem.pm @@ -305,21 +305,29 @@ sub doit_in_builddir { } # In case of out of source tree building, whole build directory -# gets wiped (if it exists) and 1 is returned. Otherwise, nothing -# is done and 0 is returned. +# gets wiped (if it exists) and 1 is returned. If build directory +# had 2 or more levels, empty parent directories are also deleted. +# If build directory does not exist, nothing is done and 0 is returned. sub rmdir_builddir { my $this=shift; if ($this->get_builddir()) { my $buildpath = $this->get_buildpath(); - if (-d $buildpath) { + if (-d $buildpath && ! $dh{NO_ACT}) { doit("rm", "-rf", $buildpath); + # If build directory had 2 or more levels, delete empty + # parent directories until the source directory level. + my @spdir = File::Spec->splitdir($this->get_build_rel2sourcedir()); + my $peek; + pop @spdir; + while (($peek=pop(@spdir)) && $peek ne '.' && $peek ne '..') { + last if ! rmdir($this->get_sourcepath(File::Spec->catdir(@spdir, $peek))); + } } return 1; } return 0; } - # Instance method that is called before performing any step (see below). # Action name is passed as an argument. Derived classes overriding this # method should also call SUPER implementation of it. -- cgit v1.2.3