]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Buildsystem.pm
Drop special handling for build directory ./path.
[debhelper.git] / Debian / Debhelper / Buildsystem.pm
index f8028619adf4e2b26019154f1b948d58930c6fcc..babbd10d332ab9b5b4ea076e3ac532cef6f12105 100644 (file)
@@ -46,26 +46,18 @@ sub DEFAULT_BUILD_DIRECTORY {
 #                  directory) where the sources to be built live. If not
 #                  specified or empty, defaults to the current directory.
 # - builddir -     specifies build directory to use. Path is relative to the
-#                  source directory unless it starts with ./, then it is
-#                  assumed to be relative to the top directory. If undef or
-#                  empty, DEFAULT_BUILD_DIRECTORY relative to the source
-#                  directory will be used. If not specified, in source build
-#                  will be attempted.
-# - build_step -   set this parameter to the name of the build step
-#                  if you want the object to determine its is_buidable
-#                  status automatically (with check_auto_buildable()).
-#                  Do not pass this parameter if is_buildable flag should
-#                  be forced to true or set this parameter to undef if
-#                  is_buildable flag should be false.
+#                  current (top) directory. If undef or empty,
+#                  DEFAULT_BUILD_DIRECTORY directory will be used. 
 # Derived class can override the constructor to initialize common object
-# parameters and execute commands to configure build environment if
-# is_buildable flag is set on the object.
+# parameters. Do NOT use constructor to execute commands or otherwise
+# configure/setup build environment. There is absolutely no guarantee the
+# constructed object will be used to build something. Use pre_building_step(),
+# $build_step() or post_building_step() methods for this.
 sub new {
        my ($class, %opts)=@_;
 
        my $this = bless({ sourcedir => '.',
-                          builddir => undef,
-                          is_buildable => 1 }, $class);
+                          builddir => undef, }, $class);
 
        if (exists $opts{sourcedir}) {
                # Get relative sourcedir abs_path (without symlinks)
@@ -79,14 +71,6 @@ sub new {
        if (exists $opts{builddir}) {
                $this->_set_builddir($opts{builddir});
        }
-       if (exists $opts{build_step}) {
-               if (defined $opts{build_step}) {
-                       $this->{is_buildable} = $this->check_auto_buildable($opts{build_step});
-               }
-               else {
-                       $this->{is_buildable} = 0;
-               }
-       }
        return $this;
 }
 
@@ -96,20 +80,7 @@ sub new {
 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());
-       }
+       $this->{builddir} = ($builddir) ? $builddir : $this->DEFAULT_BUILD_DIRECTORY;
 
        # Canonicalize. If build directory ends up the same as source directory, drop it
        if (defined $this->{builddir}) {
@@ -120,12 +91,6 @@ sub _set_builddir {
        }
 }
 
-# Test is_buildable flag of the object.
-sub is_buildable {
-       my $this=shift;
-       return $this->{is_buildable};
-}
-
 # This instance method is called to check if the build system is capable
 # to auto build a source package. Additional argument $step describes
 # which operation the caller is going to perform (either configure,
@@ -146,26 +111,25 @@ sub check_auto_buildable {
 # to enforce in source building even if the user requested otherwise.
 sub enforce_in_source_building {
        my $this=shift;
-       if ($this->{builddir}) {
-               # Do not emit warning unless the object is buildable.
-               if ($this->is_buildable()) {
-                       warning("warning: " . $this->NAME() .
-                           " does not support building out of source tree. In source building enforced.");
-               }
+       if ($this->get_builddir()) {
+               $this->{warn_insource} = 1;
                $this->{builddir} = undef;
        }
 }
 
 # Derived class can call this method in its constructor to enforce
-# out of source building even if the user didn't request it.
+# out of source building even if the user didn't request it. However,
+# if $builddir is specified, accept it even if it matches the source
+# directory (soft mode).
 sub enforce_out_of_source_building {
        my ($this, $builddir) = @_;
        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();
+               if (!defined $this->get_builddir() && !$builddir) {
+                       # If we are here, DEFAULT_BUILD_DIRECTORY matches
+                       # the source directory, building might fail.
+                       error("default build directory is the same as the source directory." .
+                             " Please specify a custom build directory");
                }
        }
 }
@@ -218,7 +182,8 @@ sub get_sourcepath {
 }
 
 # Get path to the build directory if it was specified
-# (relative to the current (top) directory). undef otherwise.
+# (relative to the current (top) directory). undef if the same
+# as the source directory.
 sub get_builddir {
        my $this=shift;
        return $this->{builddir};
@@ -356,6 +321,14 @@ sub rmdir_builddir {
 sub pre_building_step {
        my $this=shift;
        my ($step)=@_;
+
+       # Warn if in source building was enforced but build directory was
+       # specified. See enforce_in_source_building().
+       if ($this->{warn_insource}) {
+               warning("warning: " . $this->NAME() .
+                   " does not support building out of source tree. In source building enforced.");
+               delete $this->{warn_insource};
+       }
 }
 
 # Instance method that is called after performing any step (see below).