diff options
author | Modestas Vainius <modestas@vainius.eu> | 2009-04-14 15:12:14 +0300 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2009-04-14 14:14:07 -0400 |
commit | 683f6060d8304d6d4e83bd76e5ac624a35b43442 (patch) | |
tree | 12a7a34240e60a52269647584c92c3349c0b2e5a /Debian/Debhelper/Dh_Buildsystems.pm | |
parent | 2b7f42f9ef70c08bb7bc138fb8b24dc993da54ac (diff) |
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 <modestas@vainius.eu>
Diffstat (limited to 'Debian/Debhelper/Dh_Buildsystems.pm')
-rw-r--r-- | Debian/Debhelper/Dh_Buildsystems.pm | 216 |
1 files changed, 92 insertions, 124 deletions
diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm index aa2dff99..676551b9 100644 --- a/Debian/Debhelper/Dh_Buildsystems.pm +++ b/Debian/Debhelper/Dh_Buildsystems.pm @@ -1,4 +1,5 @@ # A module for loading and managing debhelper buildsystem plugins. +# This module is intended to be used by all dh_auto_* helper commands. # # Copyright: © 2009 Modestas Vainius # License: GPL-2+ @@ -9,124 +10,67 @@ use strict; use warnings; use Debian::Debhelper::Dh_Lib; -use Exporter qw( import ); -our @EXPORT_OK = qw( DEFAULT_BUILD_DIRECTORY ); +use base 'Exporter'; +our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem); -# IMPORTANT: more specific buildsystems should go first # XXX JEH as noted, this has to match historical order for back-compat -my @BUILDSYSTEMS = ( +# XXX MDX Current dh_auto_* look like: +# configure: autotools, perl_makemaker, perl_build +# build: makefile, python_distutils, perl_build +# test: makefile, perl_build +# install: makefile (with perl_makermaker) hack, python_distutils, perl_build +# clean: makefile, python_distutils, perl_build +# So historical @BUILDSYSTEMS order (as per autodetection, see +# is_auto_buildable() of the respective classes): +# autotools (+configure; the rest - next class) +# python_distutils (+build +install +clean; the rest - next class) +# perl_makemaker (+configure +install (special hack); the rest - next class) +# makefile (+build +test +install +clean; configure - next class) +# perl_build (handles everything) + +# Historical order must be kept for backwards compatibility. New +# buildsystems MUST be added to the END of the list. +our @BUILDSYSTEMS = ( "autotools", - "cmake", - "perl_build", - "perl_makefile", "python_distutils", + "perl_makemaker", "makefile", + "perl_build", + "cmake", ); -sub DEFAULT_BUILD_DIRECTORY { - return "obj-" . dpkg_architecture_value("DEB_BUILD_GNU_TYPE"); -} - -sub new { - my $cls=shift; - my %opts=@_; - my $self = bless({ - 'o_dir' => undef, - 'o_system' => undef, - 'loaded_buildsystems' => [] }, $cls); - - # XXX JEH AFAICS, these 2 env variables are never used or documented - if (!exists $opts{noenv}) { - if (exists $ENV{DH_AUTO_BUILDDIRECTORY}) { - $self->_set_build_directory_option("env", $ENV{DH_AUTO_BUILDDIRECTORY}); - } - if (exists $ENV{DH_AUTO_BUILDSYSTEM}) { - $self->{o_system} = $ENV{DH_AUTO_BUILDSYSTEM}; - } - } - return $self; -} - -sub get_options { - my $self=shift; - my @options=@_; - - my $set_dir = sub { $self->_set_build_directory_option(@_) }; - my $list_bs = sub { $self->list_buildsystems(@_); exit 0 }; - - push @options, ( - "b:s" => $set_dir, - "build-directory:s" => $set_dir, - "builddirectory:s" => $set_dir, - - "m=s" => \$self->{o_system}, - "build-system=s" => \$self->{o_system}, - "buildsystem=s" => \$self->{o_system}, - - "l" => $list_bs, - "--list" => $list_bs, - ); - my %options = @options; - return \%options; -} - -sub _set_build_directory_option { - # XXX JEH option argument is not used, would be less confusing to - # not pass extra getopt value in - my ($self, $option, $value) = @_; - if (!$value || $value eq "auto") { - # Autogenerate build directory name - $self->{o_dir} = DEFAULT_BUILD_DIRECTORY; - } - else { - $self->{o_dir} = $value; - } -} +sub create_buildsystem_instance { + my $system=shift; + my %bsopts=@_; + my $module = "Debian::Debhelper::Buildsystem::$system"; -# XXX JEH this sub is not used -sub _dump_options { - my $self=shift; - for my $opt (qw(o_dir o_system)) { - if (defined $self->{$opt}) { - print $opt, ": ", $self->{$opt}, "\n"; - } + eval "use $module"; + if ($@) { + error("unable to load buildsystem class '$system': $@"); } -} - -sub _get_buildsystem_module { - my ($self, $system) = @_; - my $module = "Debian::Debhelper::Buildsystem::$system"; - if (grep $module, @{$self->{loaded_buildsystems}} == 0) { - eval "use $module"; - if ($@) { - error("Unable to load buildsystem '$system': $@"); - } - push @{$self->{loaded_buildsystems}}, $module; + if (!exists $bsopts{builddir} && exists $dh{BUILDDIR}) { + $bsopts{builddir} = $dh{BUILDDIR}; } - return $module; + return $module->new(%bsopts); } sub load_buildsystem { # XXX JEH the $system param is never passed # by any call to this function - my ($self, $action, $system) = @_; - - if (!defined $system) { - $system = $self->{o_system}; - } + # XXX MDX Yes, it was sort of redudant. But see buildsystems_do() now. + my ($action, $system)=@_; if (defined $system) { - my $module = $self->_get_buildsystem_module($system); - verbose_print("Selected buildsystem (specified): ".$module->NAME()); - return $module->new($self->{o_dir}); + my $inst = create_buildsystem_instance($system); + verbose_print("Selected buildsystem (specified): ".$inst->NAME()); + return $inst; } else { # Try to determine build system automatically for $system (@BUILDSYSTEMS) { - my $module = $self->_get_buildsystem_module($system); - my $inst = $module->new($self->{o_dir}); - if ($inst->is_buildable($action)) { - verbose_print("Selected buildsystem (auto): ".$module->NAME()); + my $inst = create_buildsystem_instance($system, is_auto=>1); + if ($inst->is_auto_buildable($action)) { + verbose_print("Selected buildsystem (auto): ". $inst->NAME()); return $inst; } } @@ -134,48 +78,67 @@ sub load_buildsystem { return; } -sub load_all_buildsystems { - my $self=shift; +sub list_buildsystems { for my $system (@BUILDSYSTEMS) { - $self->_get_buildsystem_module($system); + my $inst = create_buildsystem_instance($system); + printf("%s - %s.\n", $inst->NAME(), $inst->DESCRIPTION()); } - return @{$self->{loaded_buildsystems}}; } -sub list_buildsystems { - my $self=shift; - for my $system ($self->load_all_buildsystems()) { - printf("%s - %s.\n", $system->NAME(), $system->DESCRIPTION()); +sub buildsystems_init { + my %args=@_; + + # XXX JEH AFAICS, these 2 env variables are never used or documented + # XXX MDX They are used (see below), not documented though. + # TODO: Not documented in the manual pages yet. + # Initialize options from environment variables + if (exists $ENV{DH_AUTO_BUILDDIRECTORY}) { + $dh{BUILDDIR} = $ENV{DH_AUTO_BUILDDIRECTORY}; } -} + if (exists $ENV{DH_AUTO_BUILDSYSTEM}) { + $dh{BUILDSYS} = $ENV{DH_AUTO_BUILDSYSTEM}; + } + + # Available command line options + my $list_bs = sub { list_buildsystems(); exit 0 }; + my $set_builddir = sub { $dh{BUILDDIR} = $_[1] }; + my %options = ( + "b:s" => $set_builddir, + "build-directory:s" => $set_builddir, + "builddirectory:s" => $set_builddir, -sub init_dh_auto_tool { - my $self=shift; + "m=s" => \$dh{BUILDSYS}, + "build-system=s" => \$dh{BUILDSYS}, + "buildsystem=s" => \$dh{BUILDSYS}, - Debian::Debhelper::Dh_Lib::init( - options => $self->get_options(@_)); - $self->{initialized}=1; + "l" => $list_bs, + "--list" => $list_bs, + ); + map { $args{options}{$_} = $options{$_} } keys(%options); + Debian::Debhelper::Dh_Lib::init(%args); } -sub run_dh_auto_tool { - my $self=shift; - my $toolname = basename($0); - my $buildsystem; +sub buildsystems_do { + my $action=shift; - # XXX JEH does this if ever not fire? - if (!exists $self->{initialized}) { - $self->init_dh_auto_tool(); + if (!defined $action) { + $action = basename($0); + $action =~ s/^dh_auto_//; } - # Guess action from the dh_auto_* name - $toolname =~ s/^dh_auto_//; - if (grep(/^\Q$toolname\E$/, qw{configure build test install clean}) == 0) { - error("Unrecognized dh auto tool: ".basename($0)); + # XXX JEH does this if ever not fire? + # XXX MDX See dh_auto_install. I'm removing this anyway + # and making buildsystem_init() call in dh_auto_* mandatory. + + if (grep(/^\Q$action\E$/, qw{configure build test install clean}) == 0) { + error("unrecognized auto action: ".basename($0)); } - $buildsystem = $self->load_buildsystem($toolname); + my $buildsystem = load_buildsystem($action, $dh{BUILDSYS}); if (defined $buildsystem) { - return $buildsystem->$toolname(@_, @{$dh{U_PARAMS}}); + $buildsystem->pre_action($action); + $buildsystem->$action(@_, @{$dh{U_PARAMS}}); + $buildsystem->post_action($action); } return 0; } @@ -186,5 +149,10 @@ sub run_dh_auto_tool { # that parses the command line, loads the specified system, and uses it, # passing it the build directory. It would be both shorter and easier to # understand. +# XXX I refactored this into a module rather than OO class. I do not agree +# about a single sub though as it is more complicated than that and +# I think it is more clear to have the code segmented a bit. See also +# dh_auto_install why both buildsystems_init() and buildsystems_do() +# are needed. 1; |