From 683f6060d8304d6d4e83bd76e5ac624a35b43442 Mon Sep 17 00:00:00 2001 From: Modestas Vainius Date: Tue, 14 Apr 2009 15:12:14 +0300 Subject: Modular object-orientied buildsystem implementation (try 2). Major changess: * Dh_Buildsystem_Option dropped and Dh_Buildsystem_Chdir functionality partitially merged into Dh_Buildsystem_Basic. Dh_Buildsystem_Bases.pm renamed to Dh_Buildsystem_Basic.pm to match classname. * *_impl() ditched completely. Previous {configure,build,test,install,clean}_impl() renamed to just configure(), build(), test(), install(), clean() instead. Added pre_action($action) and post_action($action) hooks instead which are called by Dh_Buildsystems::buildsystems_do(). * Builddir is handled via mkdir_builddir(), doit_in_buildddir(), clean_builddir() methods which buildsystems should call directly. Removed get_top* method, added get_rel2builddir_path(). * is_buildable() method renamed to is_auto_buildable() to reflect its purpose more. * ::perl_makefile renamed to ::perl_makemaker and which is based on ::makefile now. MakeMaker hack moved from ::makefile to ::perl_makemaker where it belongs (thanks for the tip). * Dh_Buildsystems refactored into a simple perl module rather than OO class and simplified a bit. * @BUILDSYSTEMS and is_auto_buildable() modified to 100% match historical order. TODO: user documentation (e.g. DH_AUTO_BUILDDIRECTORY and DH_AUTO_BUILDSYSTEM environment variables and common dh_auto_* options (--buildsystem and --builddirectory)). Current plugin inheritance hierarchy is like this: Buildsystem::perl_build -> Dh_Buildsystem_Basic <- Buildsystem::python_distutils ^ | Buildsystem::makefile <- Buildsystem::perl_makemaker ^ ^ ^ / | \ Buildsystem::autotools Buildsystem::cmake Buildsystem::python_distutils Signed-off-by: Modestas Vainius --- Debian/Debhelper/Buildsystem/autotools.pm | 27 +++---- Debian/Debhelper/Buildsystem/cmake.pm | 44 ++++++------ Debian/Debhelper/Buildsystem/makefile.pm | 92 ++++++++++++------------ Debian/Debhelper/Buildsystem/perl_build.pm | 37 +++++----- Debian/Debhelper/Buildsystem/perl_makefile.pm | 38 ---------- Debian/Debhelper/Buildsystem/perl_makemaker.pm | 71 ++++++++++++++++++ Debian/Debhelper/Buildsystem/python_distutils.pm | 49 ++++++------- 7 files changed, 189 insertions(+), 169 deletions(-) delete mode 100644 Debian/Debhelper/Buildsystem/perl_makefile.pm create mode 100644 Debian/Debhelper/Buildsystem/perl_makemaker.pm (limited to 'Debian/Debhelper/Buildsystem') diff --git a/Debian/Debhelper/Buildsystem/autotools.pm b/Debian/Debhelper/Buildsystem/autotools.pm index 945ca408..1ebc9384 100644 --- a/Debian/Debhelper/Buildsystem/autotools.pm +++ b/Debian/Debhelper/Buildsystem/autotools.pm @@ -15,17 +15,18 @@ sub DESCRIPTION { "support for building GNU Autotools based packages" } -sub is_buildable { +sub is_auto_buildable { my $self=shift; - my ($action) = @_; + my $action=shift; + + # Handle configure; the rest - next class if ($action eq "configure") { return -x "configure"; - } else { - return $self->SUPER::is_buildable(@_); } + return 0; } -sub configure_impl { +sub configure { my $self=shift; # Standard set of options for configure. @@ -37,17 +38,7 @@ sub configure_impl { push @opts, "--infodir=\${prefix}/share/info"; push @opts, "--sysconfdir=/etc"; push @opts, "--localstatedir=/var"; - # XXX JEH this is where the sheer evil of Dh_Buildsystem_Chdir - # becomes evident. Why is exec_in_topdir needed here? - # Because: - # - The parent class happens to be derived from Dh_Buildsystem_Chdir. - # - sourcepage() happens to, like many other parts of debhelper's - # library, assume it's being run in the top of the source tree, - # and fails if it's not. - # Having to worry about interactions like that for every line of - # every derived method is simply not acceptable. - # Dh_Buildsystem_Chdir must die! -- JEH - push @opts, "--libexecdir=\${prefix}/lib/" . $self->exec_in_topdir(\&sourcepackage); + push @opts, "--libexecdir=\${prefix}/lib/" . sourcepackage(); push @opts, "--disable-maintainer-mode"; push @opts, "--disable-dependency-tracking"; # Provide --host only if different from --build, as recommended in @@ -62,7 +53,9 @@ sub configure_impl { # but does not need to in the is_buildable method is not clear, # unless one is familiar with the implementation of its parent # class. I think that speaks to a bad design.. - doit($self->get_toppath("configure"), @opts, @_); + # XXX MDX It should be more explicit now. + $self->mkdir_builddir(); + $self->doit_in_builddir($self->get_rel2builddir_path("configure"), @opts, @_); } 1; diff --git a/Debian/Debhelper/Buildsystem/cmake.pm b/Debian/Debhelper/Buildsystem/cmake.pm index 00f6be4d..026004a0 100644 --- a/Debian/Debhelper/Buildsystem/cmake.pm +++ b/Debian/Debhelper/Buildsystem/cmake.pm @@ -10,45 +10,43 @@ use strict; use Debian::Debhelper::Dh_Lib; use base 'Debian::Debhelper::Buildsystem::makefile'; -sub _add_cmake_flag { - my ($self, $name, $val) = @_; - push @{$self->{cmake_flags}}, "-D$name=$val"; -} - sub DESCRIPTION { "support for building CMake based packages (outside-source tree only)" } -sub is_buildable { - return -e "CMakeLists.txt"; +sub is_auto_buildable { + my $self=shift; + my ($action)=@_; + my $ret = -e "CMakeLists.txt"; + $ret &&= $self->SUPER::is_auto_buildable(@_) if $action ne "configure"; + return $ret; } sub new { my $cls=shift; my $self=$cls->SUPER::new(@_); - # Enfore outside-source tree builds. + # Enforce outside-source tree builds. $self->enforce_outside_source_building(); - $self->{cmake_flags} = []; return $self; } -sub configure_impl { +sub configure { my $self=shift; + my @flags; # Standard set of cmake flags - $self->_add_cmake_flag("CMAKE_INSTALL_PREFIX", "/usr"); - $self->_add_cmake_flag("CMAKE_C_FLAGS", $ENV{CFLAGS}) if (exists $ENV{CFLAGS}); - $self->_add_cmake_flag("CMAKE_CXX_FLAGS", $ENV{CXXFLAGS}) if (exists $ENV{CXXFLAGS}); - $self->_add_cmake_flag("CMAKE_SKIP_RPATH", "ON"); - $self->_add_cmake_flag("CMAKE_VERBOSE_MAKEFILE", "ON"); - # TODO: LDFLAGS - # XXX JEH why are we using a method and an object - # field to build up a simple one-time-use list? - # my @flags; - # push @flags, ... if $foo - - # XXX JEH again a non-sequitor get_topdir. - doit("cmake", $self->get_topdir(), @{$self->{cmake_flags}}, @_); + push @flags, "-DCMAKE_INSTALL_PREFIX=/usr"; + push @flags, "-DCMAKE_C_FLAGS=$ENV{CFLAGS}" if (exists $ENV{CFLAGS}); + push @flags, "-DCMAKE_CXX_FLAGS=$ENV{CXXFLAGS}" if (exists $ENV{CXXFLAGS}); + push @flags, "-DCMAKE_LD_FLAGS=$ENV{LDFLAGS}" if (exists $ENV{LDFLAGS}); + push @flags, "-DCMAKE_SKIP_RPATH=ON"; + push @flags, "-DCMAKE_VERBOSE_MAKEFILE=ON"; + + # XXX JEH again a non-sequitor get_topdir. + # XXX MDX I cannot avoid it as I need to pass the path to the sourcedir + # to cmake which is relative to the builddir. + $self->mkdir_builddir(); + $self->doit_in_builddir("cmake", $self->get_rel2builddir_path(), @flags); } 1; diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm index cbd9e3c3..7ffb048e 100644 --- a/Debian/Debhelper/Buildsystem/makefile.pm +++ b/Debian/Debhelper/Buildsystem/makefile.pm @@ -8,30 +8,41 @@ package Debian::Debhelper::Buildsystem::makefile; use strict; use Debian::Debhelper::Dh_Lib; -use Debian::Debhelper::Dh_Buildsystem_Bases; -use base 'Debian::Debhelper::Dh_Buildsystem_Chdir'; +use base 'Debian::Debhelper::Dh_Buildsystem_Basic'; + +# XXX JEH setting this env var is dodgy, +# probably better to test if it exists with a default value. +# (Factor out to helper function?) +# XXX MDX Done. See new(). + +sub get_makecmd_C { + my $self=shift; + if ($self->get_builddir()) { + return $self->{makecmd} . " -C " . $self->get_builddir(); + } + return $self->{makecmd}; +} # XXX JEH I *like* this. Yay for factoring out ugly ugly stuff! -sub _exists_make_target { - my ($cls, $target) = @_; +# XXX MDX TODO: this could use dh debian/rules parser. +sub exists_make_target { + my ($self, $target) = @_; + my $makecmd=$self->get_makecmd_C(); + # Use make -n to check to see if the target would do # anything. There's no good way to test if a target exists. - my $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`; + my $ret=`$makecmd -s -n $target 2>/dev/null`; chomp $ret; return length($ret); } -sub _make_first_existing_target { - my $cls = shift; - my $targets = shift; +sub make_first_existing_target { + my $self=shift; + my $targets=shift; - # XXX JEH setting this env var is dodgy, - # probably better to test if it exists with a default value. - # (Factor out to helper function?) - $ENV{MAKE}="make" unless exists $ENV{MAKE}; foreach my $target (@$targets) { - if ($cls->_exists_make_target($target)) { - doit($ENV{MAKE}, $target, @_); + if ($self->exists_make_target($target)) { + $self->doit_in_builddir($self->{makecmd}, $target, @_); return $target; } } @@ -42,56 +53,49 @@ sub DESCRIPTION { "support for building Makefile based packages (make && make install)" } -sub is_buildable { +sub new { + my $cls=shift; + my $self=$cls->SUPER::new(@_); + $self->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make"; + return $self; +} + +sub is_auto_buildable { my $self=shift; my ($action) = @_; + + # Handles build, test, install, clean; configure - next class if (grep /^\Q$action\E$/, qw{build test install clean}) { - # XXX JEH why does get_buildpath need to be used - # here? is_buildable is run at the top of the source - # directory, so -e 'Makefile' should be the same + # This is always called in the source directory, but generally + # Makefiles are created (or live) in the the build directory. return -e $self->get_buildpath("Makefile") || -e $self->get_buildpath("makefile") || -e $self->get_buildpath("GNUmakefile"); - } else { - # XXX JEH why return 1 here? - return 1; } + return 0; } -sub build_impl { +sub build { my $self=shift; - doit(exists $ENV{MAKE} ? $ENV{MAKE} : "make", @_); + $self->doit_in_builddir($self->{makecmd}, @_); } -sub test_impl { +sub test { my $self=shift; - $self->_make_first_existing_target(['test', 'check'], @_); + $self->make_first_existing_target(['test', 'check'], @_); } -sub install_impl { +sub install { my $self=shift; my $destdir=shift; - - # XXX JEH again with the setting the env var, see above.. - $ENV{MAKE}="make" unless exists $ENV{MAKE}; - my @params="DESTDIR=$destdir"; - - # Special case for MakeMaker generated Makefiles. - # XXX JEH This is a really unfortunate breaking of the - # encapsulation of the perl_makefile module. Perhaps it would be - # better for that module to contain some hack that injects that - # test into this one? - if (-e "Makefile" && - system('grep -q "generated automatically by MakeMaker" Makefile') == 0) { - push @params, "PREFIX=/usr"; - } - - $self->_make_first_existing_target(['install'], @params, @_); + $self->make_first_existing_target(['install'], "DESTDIR=$destdir", @_); } -sub clean_impl { +sub clean { my $self=shift; - $self->_make_first_existing_target(['distclean', 'realclean', 'clean'], @_); + if (!$self->clean_builddir()) { + $self->make_first_existing_target(['distclean', 'realclean', 'clean'], @_); + } } 1; diff --git a/Debian/Debhelper/Buildsystem/perl_build.pm b/Debian/Debhelper/Buildsystem/perl_build.pm index a43d65da..9be71a27 100644 --- a/Debian/Debhelper/Buildsystem/perl_build.pm +++ b/Debian/Debhelper/Buildsystem/perl_build.pm @@ -8,26 +8,27 @@ package Debian::Debhelper::Buildsystem::perl_build; use strict; use Debian::Debhelper::Dh_Lib; -use Debian::Debhelper::Dh_Buildsystem_Bases; use base 'Debian::Debhelper::Dh_Buildsystem_Basic'; sub DESCRIPTION { "support for building Perl Build.PL based packages (in-source only)" } -sub is_buildable { +sub is_auto_buildable { my ($self, $action) = @_; - my $ret = (-e "Build.PL"); + + # Handles everything + my $ret = -e "Build.PL"; if ($action ne "configure") { - $ret &= (-e "Build"); + $ret &&= -e "Build"; } return $ret; } -sub invoke_impl { +sub do_perl { my $self=shift; $ENV{MODULEBUILDRC} = "/dev/null"; - return $self->SUPER::invoke_impl(@_); + doit("perl", @_); } sub new { @@ -37,33 +38,31 @@ sub new { return $self; } -sub configure_impl { +sub configure { my $self=shift; - # XXX JEH I think the below comment is inherited from elsewhere; - # doesn't really make sense now. - $ENV{PERL_MM_USE_DEFAULT}=1; # Module::Build can also use this. - doit("perl", "Build.PL", "installdirs=vendor", @_); + $ENV{PERL_MM_USE_DEFAULT}=1; + $self->do_perl("Build.PL", "installdirs=vendor", @_); } -sub build_impl { +sub build { my $self=shift; - doit("perl", "Build", @_); + $self->do_perl("Build", @_); } -sub test_impl { +sub test { my $self=shift; - doit(qw/perl Build test/, @_); + $self->do_perl("Build", "test", @_); } -sub install_impl { +sub install { my $self=shift; my $destdir=shift; - doit("perl", "Build", "install", "destdir=$destdir", "create_packlist=0", @_); + $self->do_perl("Build", "install", "destdir=$destdir", "create_packlist=0", @_); } -sub clean_impl { +sub clean { my $self=shift; - doit("perl", "Build", "--allow_mb_mismatch", 1, "distclean", @_); + $self->do_perl("Build", "--allow_mb_mismatch", 1, "distclean", @_); } 1; diff --git a/Debian/Debhelper/Buildsystem/perl_makefile.pm b/Debian/Debhelper/Buildsystem/perl_makefile.pm deleted file mode 100644 index 67a6f441..00000000 --- a/Debian/Debhelper/Buildsystem/perl_makefile.pm +++ /dev/null @@ -1,38 +0,0 @@ -# A buildsystem plugin for handling Perl Build based projects. -# -# Copyright: © 2008-2009 Joey Hess -# © 2008-2009 Modestas Vainius -# License: GPL-2+ - -package Debian::Debhelper::Buildsystem::perl_makefile; - -use strict; -use Debian::Debhelper::Dh_Lib; -use Debian::Debhelper::Dh_Buildsystem_Bases; -use base 'Debian::Debhelper::Dh_Buildsystem_Basic'; - -sub DESCRIPTION { - "support for building Perl Makefile.PL based packages (in-source only)" -} - -sub is_buildable { - my ($self, $action) = @_; - return ($action eq "configure") && (-e "Makefile.PL"); -} - -sub new { - my $cls=shift; - my $self=$cls->SUPER::new(@_); - $self->enforce_in_source_building(); - return $self; -} - -sub configure_impl { - my $self=shift; - # If set to a true value then MakeMaker's prompt function will - # # always return the default without waiting for user input. - $ENV{PERL_MM_USE_DEFAULT}=1; - doit("perl", "Makefile.PL", "INSTALLDIRS=vendor", @_); -} - -1; diff --git a/Debian/Debhelper/Buildsystem/perl_makemaker.pm b/Debian/Debhelper/Buildsystem/perl_makemaker.pm new file mode 100644 index 00000000..15539588 --- /dev/null +++ b/Debian/Debhelper/Buildsystem/perl_makemaker.pm @@ -0,0 +1,71 @@ +# A buildsystem plugin for handling Perl MakeMaker based projects. +# +# Copyright: © 2008-2009 Joey Hess +# © 2008-2009 Modestas Vainius +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::perl_makemaker; + +use strict; +use Debian::Debhelper::Dh_Lib; +use base 'Debian::Debhelper::Buildsystem::makefile'; + +sub DESCRIPTION { + "support for building Perl MakeMaker based packages (in-source only)" +} + +sub is_auto_buildable { + my ($self, $action)=@_; + + # Handles configure, install; the rest - next class + if ($action eq "install") { + # This hack is needed to keep full 100% compatibility with previous + # debhelper versions. + if (-e "Makefile" && + system('grep -q "generated automatically by MakeMaker" Makefile') == 0) { + return 1; + } + } + elsif ($action eq "configure") { + return -e "Makefile.PL"; + } + else { + return 0; + } +} + +sub new { + my $cls=shift; + my $self=$cls->SUPER::new(@_); + $self->enforce_in_source_building(); + return $self; +} + +sub configure { + my $self=shift; + # If set to a true value then MakeMaker's prompt function will + # # always return the default without waiting for user input. + $ENV{PERL_MM_USE_DEFAULT}=1; + doit("perl", "Makefile.PL", "INSTALLDIRS=vendor", @_); +} + +sub install { + my $self=shift; + my $destdir=shift; + # XXX JEH This is a really unfortunate breaking of the + # encapsulation of the perl_makefile module. Perhaps it would be + # better for that module to contain some hack that injects that + # test into this one? + # XXX MDX Solved. perl_makemaker will need come before makefile in + # @BUILDSYSTEMS. See also hack in is_auto_buildable(). + # This is a safety check needed to keep 100% compatibility with + # earlier debhelper behaviour. This if is very unlikely to be false. + if (-e "Makefile" && + system('grep -q "generated automatically by MakeMaker" Makefile') == 0) { + $self->SUPER::install($destdir, "PREFIX=/usr", @_); + } else { + $self->SUPER::install($destdir, @_); + } +} + +1; diff --git a/Debian/Debhelper/Buildsystem/python_distutils.pm b/Debian/Debhelper/Buildsystem/python_distutils.pm index 2e7eacbb..a69b36f4 100644 --- a/Debian/Debhelper/Buildsystem/python_distutils.pm +++ b/Debian/Debhelper/Buildsystem/python_distutils.pm @@ -9,54 +9,47 @@ package Debian::Debhelper::Buildsystem::python_distutils; use strict; use Debian::Debhelper::Dh_Lib; -use Debian::Debhelper::Dh_Buildsystem_Bases; -use base 'Debian::Debhelper::Dh_Buildsystem_Option'; +use base 'Debian::Debhelper::Dh_Buildsystem_Basic'; sub DESCRIPTION { "support for building Python distutils based packages" } -sub is_buildable { - return -e "setup.py"; +sub is_auto_buildable { + my $self=shift; + my $action=shift; + + # Handle build install clean; the rest - next class + if (grep(/^\Q$action\E$/, qw{build install clean})) { + return -e "setup.py"; + } + return 0; } -sub get_builddir_option { +sub setup_py { my $self=shift; + my $act=shift; + if ($self->get_builddir()) { - return "--build-base=". $self->get_builddir(); + unshift @_, "--build-base=" . $self->get_builddir(); } - return; + doit("python", "setup.py", $act, @_); } -# XXX JEH the default for all these methods is to do nothing successfully. -# So either this, or those default stubs, need to be removed. -sub configure_impl { - # Do nothing - 1; -} - -sub build_impl { +sub build { my $self=shift; - doit("python", "setup.py", "build", @_); -} - -# XXX JEH see anove comment -sub test_impl { - 1; + $self->setup_py("build", @_); } -sub install_impl { +sub install { my $self=shift; my $destdir=shift; - - doit("python", "setup.py", "install", - "--root=$destdir", - "--no-compile", "-O0", @_); + $self->setup_py("install", "--root=$destdir", "--no-compile", "-O0", @_); } -sub clean_impl { +sub clean { my $self=shift; - doit("python", "setup.py", "clean", "-a", @_); + $self->setup_py("clean", "-a", @_); # The setup.py might import files, leading to python creating pyc # files. doit('find', '.', '-name', '*.pyc', '-exec', 'rm', '{}', ';'); -- cgit v1.2.3