summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorModestas Vainius <modestas@vainius.eu>2009-06-11 03:48:39 +0300
committerModestas Vainius <modestas@vainius.eu>2009-06-11 10:40:35 +0300
commit23d1e4255bf7ddfadf5e5d3eaa40505e1df4dfc5 (patch)
tree26c831b7e90dfdbb53f1d02d94b9bbd0798dcab9
parent26631f8cd7c72f5e546d3ccff7d24224fb44961f (diff)
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 <modestas@vainius.eu>
-rw-r--r--Debian/Debhelper/Buildsystem.pm16
1 files changed, 12 insertions, 4 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
index 85a1401..6842e34 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.