]> git.donarmstrong.com Git - debhelper.git/commitdiff
Refactor build directory setting into separate method and solve a few bugs.
authorModestas Vainius <modestas@vainius.eu>
Thu, 11 Jun 2009 07:54:55 +0000 (10:54 +0300)
committerModestas Vainius <modestas@vainius.eu>
Thu, 11 Jun 2009 08:04:47 +0000 (11:04 +0300)
* Move setting of new build directory from constructor to _set_builddir()
  method including detection if directory (current or source) it should be
  relative to.
* Even if a new build directory was specified, detect if it matches the source
  directory and unset it in such a case.
* Use _set_builddir() in enforce_out_of_source_tree() methods. Previous
  implementation didn't handle default build directory properly (i.e.
  relativeness to current or source directory).

Signed-off-by: Modestas Vainius <modestas@vainius.eu>
Debian/Debhelper/Buildsystem.pm

index 6842e348b4eb0dba0f39ab84a2a9613869937ac9..f8028619adf4e2b26019154f1b948d58930c6fcc 100644 (file)
@@ -77,20 +77,7 @@ sub new {
                $this->{sourcedir} = File::Spec->abs2rel($abspath, $curdir);
        }
        if (exists $opts{builddir}) {
-               if ($opts{builddir}) {
-                       if ($opts{builddir} =~ m!^\./(.*)!) {
-                               # Specified as relative to the current directory
-                               $this->{builddir} = $1;
-                       }
-                       else {
-                               # Specified as relative to the source directory
-                               $this->{builddir} = $this->_canonpath($this->get_sourcepath($opts{builddir}));
-                       }
-               }
-               else {
-                       # Relative to the source directory by default
-                       $this->{builddir} = $this->get_sourcepath($this->DEFAULT_BUILD_DIRECTORY());
-               }
+               $this->_set_builddir($opts{builddir});
        }
        if (exists $opts{build_step}) {
                if (defined $opts{build_step}) {
@@ -103,6 +90,36 @@ sub new {
        return $this;
 }
 
+# Private method to set a build directory. If undef, use default.
+# Do $this->{builddir} = undef or pass $this->get_sourcedir() to
+# unset the build directory.
+sub _set_builddir {
+       my $this=shift;
+       my $builddir=shift;
+       if ($builddir) {
+               if ($builddir =~ m!^\./(.*)!) {
+                       # Specified as relative to the current directory
+                       $this->{builddir} = $1;
+               }
+               else {
+                       # Specified as relative to the source directory
+                       $this->{builddir} = $this->get_sourcepath($builddir);
+               }
+       }
+       else {
+               # Relative to the source directory by default
+               $this->{builddir} = $this->get_sourcepath($this->DEFAULT_BUILD_DIRECTORY());
+       }
+
+       # Canonicalize. If build directory ends up the same as source directory, drop it
+       if (defined $this->{builddir}) {
+               $this->{builddir} = $this->_canonpath($this->{builddir});
+               if ($this->{builddir} eq $this->get_sourcedir()) {
+                       $this->{builddir} = undef;
+               }
+       }
+}
+
 # Test is_buildable flag of the object.
 sub is_buildable {
        my $this=shift;
@@ -143,8 +160,13 @@ sub enforce_in_source_building {
 # out of source building even if the user didn't request it.
 sub enforce_out_of_source_building {
        my ($this, $builddir) = @_;
-       if (!defined $this->{builddir}) {
-               $this->{builddir} = ($builddir && $builddir ne ".") ? $builddir : $this->DEFAULT_BUILD_DIRECTORY();
+       if (!defined $this->get_builddir()) {
+               $this->_set_builddir($builddir);
+               # The build directory might have been dropped if it matched the
+               # source directory. Just set to default in this case.
+               if (!defined $this->get_builddir()) {
+                       $this->_set_builddir();
+               }
        }
 }