]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Buildsystem.pm
In v8 mode, stop passing packlist=0 in perl_makemaker buildsystem, since perl_build...
[debhelper.git] / Debian / Debhelper / Buildsystem.pm
index 494d2298ce73c082577da342b85a1ed50e3a35d8..763baa9d1773d40957c87f11122fc094cf632034 100644 (file)
@@ -12,10 +12,6 @@ use Cwd ();
 use File::Spec;
 use Debian::Debhelper::Dh_Lib;
 
-# Cache DEB_BUILD_GNU_TYPE value. Performance hit of multiple
-# invocations is noticable when listing build systems.
-our $DEB_BUILD_GNU_TYPE = dpkg_architecture_value("DEB_BUILD_GNU_TYPE");
-
 # Build system name. Defaults to the last component of the class
 # name. Do not override this method unless you know what you are
 # doing.
@@ -38,7 +34,7 @@ sub DESCRIPTION {
 # Default build directory. Can be overriden in the derived
 # class if really needed.
 sub DEFAULT_BUILD_DIRECTORY {
-       "obj-" . $DEB_BUILD_GNU_TYPE;
+       "obj-" . dpkg_architecture_value("DEB_BUILD_GNU_TYPE");
 }
 
 # Constructs a new build system object. Named parameters:
@@ -47,7 +43,9 @@ sub DEFAULT_BUILD_DIRECTORY {
 #                  specified or empty, defaults to the current directory.
 # - builddir -     specifies build directory to use. Path is relative to the
 #                  current (top) directory. If undef or empty,
-#                  DEFAULT_BUILD_DIRECTORY directory will be used. 
+#                  DEFAULT_BUILD_DIRECTORY directory will be used.
+# - parallel -     max number of parallel processes to be spawned for building
+#                  sources (-1 = unlimited; 1 = no parallel)
 # Derived class can override the constructor to initialize common object
 # parameters. Do NOT use constructor to execute commands or otherwise
 # configure/setup build environment. There is absolutely no guarantee the
@@ -58,6 +56,7 @@ sub new {
 
        my $this = bless({ sourcedir => '.',
                           builddir => undef,
+                          parallel => undef,
                           cwd => Cwd::getcwd() }, $class);
 
        if (exists $opts{sourcedir}) {
@@ -71,6 +70,9 @@ sub new {
        if (exists $opts{builddir}) {
                $this->_set_builddir($opts{builddir});
        }
+       if (defined $opts{parallel}) {
+               $this->{parallel} = $opts{parallel};
+       }
        return $this;
 }
 
@@ -90,7 +92,7 @@ sub _set_builddir {
                        $builddir = File::Spec->catdir($this->{cwd}, $builddir);
                }
                elsif ($builddir =~ /\Q$this->{cwd}\E/) {
-                       $builddir = File::Spec::abs2rel($builddir, $this->{cwd});
+                       $builddir = File::Spec->abs2rel($builddir, $this->{cwd});
                }
 
                # If build directory ends up the same as source directory, drop it
@@ -103,18 +105,27 @@ sub _set_builddir {
 }
 
 # This instance method is called to check if the build system is able
-# to auto build a source package. Additional argument $step describes
-# which operation the caller is going to perform (either configure,
-# build, test, install or clean). You must override this method for the
-# build system module to be ever picked up automatically. This method is
-# used in conjuction with @Dh_Buildsystems::BUILDSYSTEMS.
+# to build a source package. It will be called during the build
+# system auto-selection process, inside the root directory of the debian
+# source package. The current build step is passed as an argument.
+# Return 0 if the source is not buildable, or a positive integer
+# otherwise.
 #
-# This method is supposed to be called inside the source root directory.
-# Use $this->get_buildpath($path) method to get full path to the files
-# in the build directory.
+# Generally, it is enough to look for invariant unique build system
+# files shipped with clean source to determine if the source might
+# be buildable or not. However, if the build system is derived from
+# another other auto-buildable build system, this method
+# may also check if the source has already been built with this build
+# system partitially by looking for temporary files or other common
+# results the build system produces during the build process. The
+# latter checks must be unique to the current build system and must
+# be very unlikely to be true for either its parent or other build
+# systems. If it is determined that the source has already built
+# partitially with this build system, the value returned must be
+# greater than the one of the SUPER call.
 sub check_auto_buildable {
        my $this=shift;
-       my ($step) = @_;
+       my ($step)=@_;
        return 0;
 }
 
@@ -147,15 +158,6 @@ sub prefer_out_of_source_building {
        }
 }
 
-# Derived class can call this method in its constructor to *enforce*
-# out of source building even if the user didn't request it.
-# Build directory is set to DEFAULT_BUILD_DIRECTORY or building
-# fails if it is not possible to set it
-sub enforce_out_of_source_building {
-       my $this=shift;
-       $this->prefer_out_of_source_building();
-}
-
 # Enhanced version of File::Spec::canonpath. It collapses ..
 # too so it may return invalid path if symlinks are involved.
 # On the other hand, it does not need for the path to exist.
@@ -163,7 +165,7 @@ sub canonpath {
        my ($this, $path)=@_;
        my @canon;
        my $back=0;
-       for my $comp (split(m%/+%, $path)) {
+       foreach my $comp (split(m%/+%, $path)) {
                if ($comp eq '.') {
                        next;
                }
@@ -186,9 +188,11 @@ sub _rel2rel {
 
        if (File::Spec->file_name_is_absolute($path)) {
                return $path;
-       } elsif (File::Spec->file_name_is_absolute($base)) {
+       }
+       elsif (File::Spec->file_name_is_absolute($base)) {
                return File::Spec->rel2abs($path, $root);
-       } else {
+       }
+       else {
                return File::Spec->abs2rel(
                        File::Spec->rel2abs($path, $root),
                        File::Spec->rel2abs($base, $root)
@@ -250,6 +254,11 @@ sub get_source_rel2builddir {
        return $dir;
 }
 
+sub get_parallel {
+       my $this=shift;
+       return $this->{parallel};
+}
+
 # When given a relative path to the build directory, converts it
 # to the path that is relative to the source directory. If $path is
 # not given, returns a path to the build directory that is relative
@@ -327,18 +336,20 @@ sub rmdir_builddir {
        my $only_empty=shift;
        if ($this->get_builddir()) {
                my $buildpath = $this->get_buildpath();
-               if (-d $buildpath && ! $dh{NO_ACT}) {
-                       my @spdir = File::Spec->splitdir($this->get_build_rel2sourcedir());
+               if (-d $buildpath) {
+                       my @dir = File::Spec->splitdir($this->get_build_rel2sourcedir());
                        my $peek;
-                       if (!$only_empty) {
+                       if (not $only_empty) {
                                doit("rm", "-rf", $buildpath);
-                               pop @spdir;
+                               pop @dir;
                        }
                        # If build directory is relative and had 2 or more levels, delete
-                       # empty parent directories until the source directory level.
+                       # empty parent directories until the source or top directory level.
                        if (not File::Spec->file_name_is_absolute($buildpath)) {
-                               while (($peek=pop(@spdir)) && $peek ne '.' && $peek ne '..') {
-                                       last if ! rmdir($this->get_sourcepath(File::Spec->catdir(@spdir, $peek)));
+                               while (($peek=pop @dir) && $peek ne '.' && $peek ne '..') {
+                                       my $dir = $this->get_sourcepath(File::Spec->catdir(@dir, $peek));
+                                       doit("rmdir", "--ignore-fail-on-non-empty", $dir);
+                                       last if -d $dir;
                                }
                        }
                }