From 64f3a658efc18158258bf1951f8c18ec2e091766 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 30 Dec 2017 20:35:45 +0000 Subject: Buildsystem.pm: Refactor doit_in_foodir{,_noerror} Signed-off-by: Niels Thykier --- lib/Debian/Debhelper/Buildsystem.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index 4d2ee728..7fcd3a3f 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -315,12 +315,19 @@ sub _in_dir { return $code->(@args); } +sub _generic_doit_in_dir { + my ($this, $dir, $sub, @args) = @_; + my %args = ref($args[0]) ? %{$args[0]} : (); + $args{chdir} = $dir; + return $sub->(\%args, @args); +} + # Changes working directory to the source directory (if needed), # calls print_and_doit(@_) and changes working directory back to the # top directory. sub doit_in_sourcedir { my ($this, @args) = @_; - print_and_doit({ chdir => $this->get_sourcedir }, @args); + $this->_generic_doit_in_dir($this->get_sourcedir, \&print_and_doit, @args); return 1; } @@ -329,7 +336,7 @@ sub doit_in_sourcedir { # top directory. Errors are ignored. sub doit_in_sourcedir_noerror { my ($this, @args) = @_; - return print_and_doit_noerror({ chdir => $this->get_sourcedir }, @args); + return $this->_generic_doit_in_dir($this->get_sourcedir, \&print_and_doit_noerror, @args); } # Changes working directory to the build directory (if needed), @@ -337,7 +344,7 @@ sub doit_in_sourcedir_noerror { # top directory. sub doit_in_builddir { my ($this, @args) = @_; - print_and_doit({ chdir => $this->get_buildpath }, @args); + $this->_generic_doit_in_dir($this->get_buildpath, \&print_and_doit, @args); return 1; } @@ -346,7 +353,7 @@ sub doit_in_builddir { # top directory. Errors are ignored. sub doit_in_builddir_noerror { my ($this, @args) = @_; - return print_and_doit_noerror({ chdir => $this->get_buildpath }, @args); + return $this->_generic_doit_in_dir($this->get_buildpath, \&print_and_doit_noerror, @args); } # Changes working directory to the build directory (if needed), -- cgit v1.2.3 From 99fe288eefb5e6f8af0aeba546e0ef8cae759134 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 6 Jan 2018 19:38:09 +0000 Subject: Buildsystem: Fix a bug in _generic_doit_in_dir Signed-off-by: Niels Thykier --- lib/Debian/Debhelper/Buildsystem.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index 7fcd3a3f..a0ce6367 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -317,7 +317,10 @@ sub _in_dir { sub _generic_doit_in_dir { my ($this, $dir, $sub, @args) = @_; - my %args = ref($args[0]) ? %{$args[0]} : (); + my %args; + if (ref($args[0])) { + %args = %{shift(@args)}; + } $args{chdir} = $dir; return $sub->(\%args, @args); } -- cgit v1.2.3 From d3bc4c31453aabea565f8991dcbe1d9e1a0fc737 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Fri, 6 Apr 2018 19:49:20 +0000 Subject: Rewrite build system to support a "target build system" Several of the build systems consists of a configure step that generates a buildscript for another build tool. Notable examples being "cmake" and "meson", which even supports multiple backend tools. This change makes it natively possible for debhelper to support such build systems with multiple backends. Note that only build systems with multiple backends have been rewritten. Signed-off-by: Niels Thykier --- lib/Debian/Debhelper/Buildsystem.pm | 117 +++++++++++++++++++++++++++++- lib/Debian/Debhelper/Buildsystem/cmake.pm | 33 +++++++-- lib/Debian/Debhelper/Buildsystem/meson.pm | 20 ++++- lib/Debian/Debhelper/Buildsystem/ninja.pm | 8 -- lib/Debian/Debhelper/Dh_Buildsystems.pm | 71 +++++++++++++----- t/buildsystems/03-bs-auto-buildable.t | 14 ++-- 6 files changed, 216 insertions(+), 47 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index a0ce6367..6e822c45 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -11,15 +11,26 @@ use warnings; use Cwd (); use File::Spec; use Debian::Debhelper::Dh_Lib; +use Debian::Debhelper::Dh_Buildsystems qw(load_buildsystem); # Build system name. Defaults to the last component of the class # name. Do not override this method unless you know what you are # doing. sub NAME { - my $this=shift; - my $class = ref($this) || $this; + my ($this) = @_; + my $class = ref($this); + my $target_name; + if ($class) { + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $target_name = $this->{'targetbuildsystem'}->NAME; + } + } else { + $class = $this; + } if ($class =~ m/^.+::([^:]+)$/) { - return $1; + my $name = $1; + return "${name}+${target_name}" if defined($target_name); + return $name; } else { error("ınvalid build system class name: $class"); @@ -37,6 +48,43 @@ sub DEFAULT_BUILD_DIRECTORY { "obj-" . dpkg_architecture_value("DEB_HOST_GNU_TYPE"); } +# Return 1 if the build system generator +sub IS_GENERATOR_BUILD_SYSTEM { + return 0; +} + +# Generator build-systems only +# The name of the supported target systems. The first one is +# assumed to be the default if DEFAULT_TARGET_BUILD_SYSTEM is +# not overridden. +sub SUPPORTED_TARGET_BUILD_SYSTEMS { + error("class lacking SUPPORTED_TARGET_BUILD_SYSTEMS"); +} + +# Generator build-systems only +# Name of default target build system if target is unspecified +# (e.g. --buildsystem=cmake instead of cmake+makefile). +sub DEFAULT_TARGET_BUILD_SYSTEM { + my ($this) = @_; + my @targets = $this->SUPPORTED_TARGET_BUILD_SYSTEMS; + # Assume they are listed in order. + return $targets[0]; +} + +# For regular build systems, the same as DESCRIPTION +# For generator based build systems, the DESCRIPTION of the generator build +# system + the target build system. Do not override this method unless you +# know what you are doing. +sub FULL_DESCRIPTION { + my ($this) = @_; + my $description = $this->DESCRIPTION; + return $description if not exists($this->{'targetbuildsystem'}); + my $target_build_system = $this->{'targetbuildsystem'}; + return $description if not defined($target_build_system); + my $target_desc = $target_build_system->FULL_DESCRIPTION; + return "${description} combined with ${target_desc}"; +} + # Constructs a new build system object. Named parameters: # - sourcedir- specifies source directory (relative to the current (top) # directory) where the sources to be built live. If not @@ -46,6 +94,8 @@ sub DEFAULT_BUILD_DIRECTORY { # DEFAULT_BUILD_DIRECTORY directory will be used. # - parallel - max number of parallel processes to be spawned for building # sources (-1 = unlimited; 1 = no parallel) +# - targetbuildsystem - The target build system for generator based build +# systems. Only set for generator build systems. # 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 +108,7 @@ sub new { builddir => undef, parallel => undef, cwd => Cwd::getcwd() }, $class); + my $target_bs_name; if (exists $opts{sourcedir}) { # Get relative sourcedir abs_path (without symlinks) @@ -73,6 +124,19 @@ sub new { if (defined $opts{parallel}) { $this->{parallel} = $opts{parallel}; } + if (exists $opts{targetbuildsystem}) { + $target_bs_name = $opts{targetbuildsystem}; + } + + $target_bs_name //= $this->DEFAULT_TARGET_BUILD_SYSTEM if $this->IS_GENERATOR_BUILD_SYSTEM; + + if (defined($target_bs_name)) { + my %target_opts = %opts; + delete($target_opts{'targetbuildsystem'}); + my $target_system = load_buildsystem($target_bs_name, undef, %target_opts); + $this->set_targetbuildsystem($target_system); + } + return $this; } @@ -104,6 +168,27 @@ sub _set_builddir { return $builddir; } +sub set_targetbuildsystem { + my ($this, $target_system) = @_; + my $ok = 0; + my $target_bs_name = $target_system->NAME; + if (not $this->IS_GENERATOR_BUILD_SYSTEM) { + my $name = $this->NAME; + error("Buildsystem ${name} is not a generator build system"); + } + for my $supported_bs_name ($this->SUPPORTED_TARGET_BUILD_SYSTEMS) { + if ($supported_bs_name eq $target_bs_name) { + $ok = 1; + last; + } + } + if (not $ok) { + my $name = $this->NAME; + error("Buildsystem ${name} does not support ${target_bs_name} as target build system."); + } + $this->{targetbuildsystem} = $target_system +} + # This instance method is called to check if the build system is able # to build a source package. It will be called during the build # system auto-selection process, inside the root directory of the debian @@ -412,6 +497,9 @@ sub pre_building_step { " does not support building out of source tree. In source building enforced."); delete $this->{warn_insource}; } + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->{targetbuildsystem}->pre_building_step(@_); + } } # Instance method that is called after performing any step (see below). @@ -420,6 +508,9 @@ sub pre_building_step { sub post_building_step { my $this=shift; my ($step)=@_; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->{targetbuildsystem}->post_building_step(@_); + } } # The instance methods below provide support for configuring, @@ -430,26 +521,44 @@ sub post_building_step { # implement build system specific steps needed to build the # source. Arbitrary number of custom step arguments might be # passed. Default implementations do nothing. +# +# Note: For generator build systems, the default is to +# delegate the step to the target build system for all +# steps except configure. sub configure { my $this=shift; } sub build { my $this=shift; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->{targetbuildsystem}->build(@_); + } } sub test { my $this=shift; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->{targetbuildsystem}->test(@_); + } } # destdir parameter specifies where to install files. sub install { my $this=shift; - my $destdir=shift; + my ($destdir) = @_; + + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->{targetbuildsystem}->install(@_); + } } sub clean { my $this=shift; + + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->{targetbuildsystem}->clean(@_); + } } 1 diff --git a/lib/Debian/Debhelper/Buildsystem/cmake.pm b/lib/Debian/Debhelper/Buildsystem/cmake.pm index 5e3ce082..a342e436 100644 --- a/lib/Debian/Debhelper/Buildsystem/cmake.pm +++ b/lib/Debian/Debhelper/Buildsystem/cmake.pm @@ -9,7 +9,7 @@ package Debian::Debhelper::Buildsystem::cmake; use strict; use warnings; use Debian::Debhelper::Dh_Lib qw(compat dpkg_architecture_value error is_cross_compiling); -use parent qw(Debian::Debhelper::Buildsystem::makefile); +use parent qw(Debian::Debhelper::Buildsystem); my @STANDARD_CMAKE_FLAGS = qw( -DCMAKE_INSTALL_PREFIX=/usr @@ -31,12 +31,26 @@ sub DESCRIPTION { "CMake (CMakeLists.txt)" } +sub IS_GENERATOR_BUILD_SYSTEM { + return 1; +} + +sub SUPPORTED_TARGET_BUILD_SYSTEMS { + return qw(makefile); +} + sub check_auto_buildable { my $this=shift; my ($step)=@_; if (-e $this->get_sourcepath("CMakeLists.txt")) { my $ret = ($step eq "configure" && 1) || - $this->SUPER::check_auto_buildable(@_); + $this->{targetbuildsystem}->check_auto_buildable(@_); + if ($step eq "clean" && defined($this->get_builddir())) { + # Assume that the package can be cleaned (i.e. the build directory can + # be removed) as long as it is built out-of-source tree and can be + # configured. + $ret++ if not $ret; + } # Existence of CMakeCache.txt indicates cmake has already # been used by a prior build step, so should be used # instead of the parent makefile class. @@ -111,13 +125,16 @@ sub configure { sub test { my $this=shift; - - # Unlike make, CTest does not have "unlimited parallel" setting (-j implies - # -j1). So in order to simulate unlimited parallel, allow to fork a huge - # number of threads instead. - my $parallel = ($this->get_parallel() > 0) ? $this->get_parallel() : 999; + my $target = $this->{targetbuildsystem}; $ENV{CTEST_OUTPUT_ON_FAILURE} = 1; - return $this->SUPER::test(@_, "ARGS+=-j$parallel"); + if ($target->NAME eq 'makefile') { + # Unlike make, CTest does not have "unlimited parallel" setting (-j implies + # -j1). So in order to simulate unlimited parallel, allow to fork a huge + # number of threads instead. + my $parallel = ($this->get_parallel() > 0) ? $this->get_parallel() : 999; + push(@_, "ARGS+=-j$parallel") + } + return $this->SUPER::test(@_); } 1 diff --git a/lib/Debian/Debhelper/Buildsystem/meson.pm b/lib/Debian/Debhelper/Buildsystem/meson.pm index f157296f..91891485 100644 --- a/lib/Debian/Debhelper/Buildsystem/meson.pm +++ b/lib/Debian/Debhelper/Buildsystem/meson.pm @@ -8,12 +8,21 @@ package Debian::Debhelper::Buildsystem::meson; use strict; use warnings; use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value is_cross_compiling doit warning error generated_file); -use parent qw(Debian::Debhelper::Buildsystem::ninja); +use parent qw(Debian::Debhelper::Buildsystem); sub DESCRIPTION { "Meson (meson.build)" } +sub IS_GENERATOR_BUILD_SYSTEM { + return 1; +} + +sub SUPPORTED_TARGET_BUILD_SYSTEMS { + return qw(ninja); +} + + sub check_auto_buildable { my $this=shift; my ($step)=@_; @@ -22,7 +31,14 @@ sub check_auto_buildable { # Handle configure explicitly; inherit the rest return 1 if $step eq "configure"; - return $this->SUPER::check_auto_buildable(@_); + my $ret = $this->{targetbuildsystem}->check_auto_buildable(@_); + if ($ret == 0 and $step eq 'clean' and defined($this->get_builddir())) { + # Assume that the package can be cleaned (i.e. the build directory can + # be removed) as long as it is built out-of-source tree and can be + # configured. + $ret++; + } + return $ret; } sub new { diff --git a/lib/Debian/Debhelper/Buildsystem/ninja.pm b/lib/Debian/Debhelper/Buildsystem/ninja.pm index 8ebc95cd..c08ff166 100644 --- a/lib/Debian/Debhelper/Buildsystem/ninja.pm +++ b/lib/Debian/Debhelper/Buildsystem/ninja.pm @@ -30,14 +30,6 @@ sub check_auto_buildable { # This is always called in the source directory, but generally # Ninja files are created (or live) in the build directory. return 1; - } elsif ($step eq "clean" && defined $this->get_builddir() && - $this->check_auto_buildable("configure")) - { - # Assume that the package can be cleaned (i.e. the build directory can - # be removed) as long as it is built out-of-source tree and can be - # configured. This is useful for derivative buildsystems which - # generate Ninja files. - return 1; } return 0; } diff --git a/lib/Debian/Debhelper/Dh_Buildsystems.pm b/lib/Debian/Debhelper/Dh_Buildsystems.pm index 7d4b421c..7f3a96b4 100644 --- a/lib/Debian/Debhelper/Dh_Buildsystems.pm +++ b/lib/Debian/Debhelper/Dh_Buildsystems.pm @@ -25,11 +25,11 @@ our @BUILDSYSTEMS = ( "makefile", "python_distutils", (compat(7) ? "perl_build" : ()), - "cmake", + "cmake+makefile", "ant", "qmake", "qmake_qt4", - "meson", + "meson+ninja", "ninja", ); @@ -45,13 +45,21 @@ my $opt_list; my $opt_parallel; sub create_buildsystem_instance { - my ($system, $required, %bsopts) = @_; - my $module = "Debian::Debhelper::Buildsystem::$system"; + my ($full_name, $required, %bsopts) = @_; + my @parts = split(m{[+]}, $full_name, 2); + my $name = $parts[0]; + my $module = "Debian::Debhelper::Buildsystem::$name"; + if (@parts > 1) { + if (exists($bsopts{'targetbuildsystem'})) { + error("Conflicting target buildsystem for ${name} (load as ${full_name}, but target configured in bsopts)"); + } + $bsopts{'targetbuildsystem'} = $parts[1]; + } eval "use $module"; if ($@) { return if not $required; - error("unable to load build system class '$system': $@"); + error("unable to load build system class '$name': $@"); } if (!exists $bsopts{builddir} && defined $opt_builddir) { @@ -73,9 +81,15 @@ sub autoselect_buildsystem { my $selected_level = 0; foreach my $inst (@_) { - # Only derived (i.e. more specific) build system can be - # considered beyond the currently selected one. - next if defined $selected && !$inst->isa(ref $selected); + # Only more specific build system can be considered beyond + # the currently selected one. + if (defined($selected)) { + my $ok = $inst->isa(ref($selected)) ? 1 : 0; + if (not $ok and $inst->IS_GENERATOR_BUILD_SYSTEM) { + $ok = 1 if $inst->{targetbuildsystem}->NAME eq $selected->NAME; + } + next if not $ok; + } # If the build system says it is auto-buildable at the current # step and it can provide more specific information about its @@ -121,7 +135,8 @@ sub load_buildsystem { sub load_all_buildsystems { my $incs=shift || \@INC; - my (%buildsystems, @buildsystems); + my %opts = @_; + my (%buildsystems, %genbuildsystems, @buildsystems); foreach my $inc (@$incs) { my $path = File::Spec->catdir($inc, "Debian/Debhelper/Buildsystem"); @@ -129,8 +144,19 @@ sub load_all_buildsystems { foreach my $module_path (glob "$path/*.pm") { my $name = basename($module_path); $name =~ s/\.pm$//; - next if exists $buildsystems{$name}; - $buildsystems{$name} = create_buildsystem_instance($name, 1, @_); + next if exists $buildsystems{$name} or exists $genbuildsystems{$name}; + my $system = create_buildsystem_instance($name, 1, %opts); + if ($system->IS_GENERATOR_BUILD_SYSTEM) { + $genbuildsystems{$name} = 1; + for my $target_name ($system->SUPPORTED_TARGET_BUILD_SYSTEMS) { + my $full_name = "${name}+${target_name}"; + my $full_system = create_buildsystem_instance($name, 1, %opts, + 'targetbuildsystem' => $target_name); + $buildsystems{$full_name} = $full_system; + } + } else { + $buildsystems{$name} = $system; + } } } } @@ -209,22 +235,31 @@ sub buildsystems_list { my @buildsystems = load_all_buildsystems(); my %auto_selectable = map { $_ => 1 } @THIRD_PARTY_BUILDSYSTEMS; my $auto = autoselect_buildsystem($step, grep { ! $_->{thirdparty} || $auto_selectable{$_->NAME} } @buildsystems); - my $specified; + my $specified_text; + + if ($opt_buildsys) { + for my $inst (@buildsystems) { + my $full_name = $inst->NAME; + if ($full_name eq $opt_buildsys) { + $specified_text = $full_name; + } elsif ($inst->IS_GENERATOR_BUILD_SYSTEM and ref($inst)->NAME eq $opt_buildsys) { + my $default = $inst->DEFAULT_TARGET_BUILD_SYSTEM; + $specified_text = "${opt_buildsys}+${default} (default for ${opt_buildsys})"; + } + } + } # List build systems (including auto and specified status) foreach my $inst (@buildsystems) { - if (! defined $specified && defined $opt_buildsys && $opt_buildsys eq $inst->NAME()) { - $specified = $inst; - } - printf("%-20s %s", $inst->NAME(), $inst->DESCRIPTION()); + printf("%-20s %s", $inst->NAME(), $inst->FULL_DESCRIPTION()); print " [3rd party]" if $inst->{thirdparty}; print "\n"; } print "\n"; print "Auto-selected: ", $auto->NAME(), "\n" if defined $auto; - print "Specified: ", $specified->NAME(), "\n" if defined $specified; + print "Specified: ", $specified_text, "\n" if defined $specified_text; print "No system auto-selected or specified\n" - if ! defined $auto && ! defined $specified; + if ! defined $auto && ! defined $specified_text; } sub buildsystems_do { diff --git a/t/buildsystems/03-bs-auto-buildable.t b/t/buildsystems/03-bs-auto-buildable.t index c1229dc9..082e38bf 100755 --- a/t/buildsystems/03-bs-auto-buildable.t +++ b/t/buildsystems/03-bs-auto-buildable.t @@ -90,7 +90,7 @@ sub run_auto_buildable_tests { rm_files("${sourcedir}/configure"); create_empty_file("${sourcedir}/CMakeLists.txt"); - test_check_auto_buildable($bs{cmake}, "CMakeLists.txt", { configure => 1, clean => 1 }); + test_check_auto_buildable($bs{'cmake+makefile'}, "CMakeLists.txt", { configure => 1, clean => 1 }); rm_files("${sourcedir}/CMakeLists.txt"); create_empty_file("${sourcedir}/Makefile.PL"); @@ -98,7 +98,7 @@ sub run_auto_buildable_tests { rm_files("${sourcedir}/Makefile.PL"); create_empty_file("${sourcedir}/meson.build"); - test_check_auto_buildable($bs{meson}, "meson.build", { configure => 1, clean => 1 }); + test_check_auto_buildable($bs{'meson+ninja'}, "meson.build", { configure => 1, clean => 1 }); # Leave meson.build create_empty_file("${builddir}/build.ninja"); @@ -106,7 +106,7 @@ sub run_auto_buildable_tests { # Leave ninja.build # Meson + ninja - test_check_auto_buildable($bs{meson}, "meson.build+build.ninja", { configure => 1, build => 1, clean => 1, install => 1, test => 1 }); + test_check_auto_buildable($bs{'meson+ninja'}, "meson.build+build.ninja", { configure => 1, build => 1, clean => 1, install => 1, test => 1 }); rm_files("${sourcedir}/meson.build", "${builddir}/build.ninja"); # With Makefile @@ -120,9 +120,9 @@ sub run_auto_buildable_tests { # ... +cmake create_empty_file("${sourcedir}/CMakeLists.txt"); - test_check_auto_buildable($bs{cmake}, "CMakeLists.txt+Makefile", 1); + test_check_auto_buildable($bs{'cmake+makefile'}, "CMakeLists.txt+Makefile", 1); create_empty_file("$builddir/CMakeCache.txt"); # strong evidence that cmake was run - test_check_auto_buildable($bs{cmake}, "CMakeCache.txt+Makefile", 2); + test_check_auto_buildable($bs{'cmake+makefile'}, "CMakeCache.txt+Makefile", 2); rm_files("${builddir}/Makefile", "${sourcedir}/CMakeLists.txt"); # Makefile.PL forces in-source @@ -189,7 +189,7 @@ sub run_autoselection_tests { # CMake create_empty_file("${sourcedir}/CMakeLists.txt"); test_autoselection("cmake without CMakeCache.txt", - { configure => "cmake", build => "makefile", + { configure => "cmake+makefile", build => "makefile", test => "makefile", install => "makefile", clean => "makefile" }, @@ -201,7 +201,7 @@ sub run_autoselection_tests { create_empty_file("${sourcedir}/CMakeLists.txt"); test_autoselection("cmake with CMakeCache.txt", - "cmake", + "cmake+makefile", %options, code_configure => sub { create_empty_file("$builddir/Makefile"); -- cgit v1.2.3 From 14f31b2feb385292cfba63abeba542c02def7de3 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 7 Apr 2018 08:44:23 +0000 Subject: Buildsystem.pm: Add a getter for targetbuildsystem Signed-off-by: Niels Thykier --- lib/Debian/Debhelper/Buildsystem.pm | 21 ++++++++++++++------- lib/Debian/Debhelper/Buildsystem/cmake.pm | 6 +++--- lib/Debian/Debhelper/Buildsystem/meson.pm | 2 +- lib/Debian/Debhelper/Dh_Buildsystems.pm | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index 6e822c45..ef1ec5bd 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -186,7 +186,14 @@ sub set_targetbuildsystem { my $name = $this->NAME; error("Buildsystem ${name} does not support ${target_bs_name} as target build system."); } - $this->{targetbuildsystem} = $target_system + $this->{'targetbuildsystem'} = $target_system +} + +# Returns the target build system if it is provided +sub get_targetbuildsystem { + my $this = shift; + return if not exists($this->{'targetbuildsystem'}); + return $this->{'targetbuildsystem'}; } # This instance method is called to check if the build system is able @@ -498,7 +505,7 @@ sub pre_building_step { delete $this->{warn_insource}; } if ($this->IS_GENERATOR_BUILD_SYSTEM) { - $this->{targetbuildsystem}->pre_building_step(@_); + $this->get_targetbuildsystem->pre_building_step(@_); } } @@ -509,7 +516,7 @@ sub post_building_step { my $this=shift; my ($step)=@_; if ($this->IS_GENERATOR_BUILD_SYSTEM) { - $this->{targetbuildsystem}->post_building_step(@_); + $this->get_targetbuildsystem->post_building_step(@_); } } @@ -532,14 +539,14 @@ sub configure { sub build { my $this=shift; if ($this->IS_GENERATOR_BUILD_SYSTEM) { - $this->{targetbuildsystem}->build(@_); + $this->get_targetbuildsystem->build(@_); } } sub test { my $this=shift; if ($this->IS_GENERATOR_BUILD_SYSTEM) { - $this->{targetbuildsystem}->test(@_); + $this->get_targetbuildsystem->test(@_); } } @@ -549,7 +556,7 @@ sub install { my ($destdir) = @_; if ($this->IS_GENERATOR_BUILD_SYSTEM) { - $this->{targetbuildsystem}->install(@_); + $this->get_targetbuildsystem->install(@_); } } @@ -557,7 +564,7 @@ sub clean { my $this=shift; if ($this->IS_GENERATOR_BUILD_SYSTEM) { - $this->{targetbuildsystem}->clean(@_); + $this->get_targetbuildsystem->clean(@_); } } diff --git a/lib/Debian/Debhelper/Buildsystem/cmake.pm b/lib/Debian/Debhelper/Buildsystem/cmake.pm index d9436bae..9c4cdc30 100644 --- a/lib/Debian/Debhelper/Buildsystem/cmake.pm +++ b/lib/Debian/Debhelper/Buildsystem/cmake.pm @@ -49,7 +49,7 @@ sub check_auto_buildable { my ($step)=@_; if (-e $this->get_sourcepath("CMakeLists.txt")) { my $ret = ($step eq "configure" && 1) || - $this->{targetbuildsystem}->check_auto_buildable(@_); + $this->get_targetbuildsystem->check_auto_buildable(@_); if ($step eq "clean" && defined($this->get_builddir())) { # Assume that the package can be cleaned (i.e. the build directory can # be removed) as long as it is built out-of-source tree and can be @@ -76,7 +76,7 @@ sub configure { my $this=shift; # Standard set of cmake flags my @flags = @STANDARD_CMAKE_FLAGS; - my $backend = $this->{targetbuildsystem}->NAME; + my $backend = $this->get_targetbuildsystem->NAME; if (not compat(10)) { push(@flags, '-DCMAKE_INSTALL_RUNSTATEDIR=/run'); @@ -135,7 +135,7 @@ sub configure { sub test { my $this=shift; - my $target = $this->{targetbuildsystem}; + my $target = $this->get_targetbuildsystem; $ENV{CTEST_OUTPUT_ON_FAILURE} = 1; if ($target->NAME eq 'makefile') { # Unlike make, CTest does not have "unlimited parallel" setting (-j implies diff --git a/lib/Debian/Debhelper/Buildsystem/meson.pm b/lib/Debian/Debhelper/Buildsystem/meson.pm index 91891485..d05336ec 100644 --- a/lib/Debian/Debhelper/Buildsystem/meson.pm +++ b/lib/Debian/Debhelper/Buildsystem/meson.pm @@ -31,7 +31,7 @@ sub check_auto_buildable { # Handle configure explicitly; inherit the rest return 1 if $step eq "configure"; - my $ret = $this->{targetbuildsystem}->check_auto_buildable(@_); + my $ret = $this->get_targetbuildsystem->check_auto_buildable(@_); if ($ret == 0 and $step eq 'clean' and defined($this->get_builddir())) { # Assume that the package can be cleaned (i.e. the build directory can # be removed) as long as it is built out-of-source tree and can be diff --git a/lib/Debian/Debhelper/Dh_Buildsystems.pm b/lib/Debian/Debhelper/Dh_Buildsystems.pm index 96c1e57b..59b4a427 100644 --- a/lib/Debian/Debhelper/Dh_Buildsystems.pm +++ b/lib/Debian/Debhelper/Dh_Buildsystems.pm @@ -87,7 +87,7 @@ sub autoselect_buildsystem { if (defined($selected)) { my $ok = $inst->isa(ref($selected)) ? 1 : 0; if (not $ok and $inst->IS_GENERATOR_BUILD_SYSTEM) { - $ok = 1 if $inst->{targetbuildsystem}->NAME eq $selected->NAME; + $ok = 1 if $inst->get_targetbuildsystem->NAME eq $selected->NAME; } next if not $ok; } -- cgit v1.2.3 From f1d6cad9c7a709455acf26887c0263ab96af9772 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 7 Apr 2018 08:54:29 +0000 Subject: Buildsystem.pm: Improve error message Signed-off-by: Niels Thykier --- lib/Debian/Debhelper/Buildsystem.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index ef1ec5bd..cc3634fe 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -174,7 +174,7 @@ sub set_targetbuildsystem { my $target_bs_name = $target_system->NAME; if (not $this->IS_GENERATOR_BUILD_SYSTEM) { my $name = $this->NAME; - error("Buildsystem ${name} is not a generator build system"); + error("Cannot set a target build system: Buildsystem ${name} is not a generator build system"); } for my $supported_bs_name ($this->SUPPORTED_TARGET_BUILD_SYSTEMS) { if ($supported_bs_name eq $target_bs_name) { -- cgit v1.2.3 From 230da7c887bb6ad8827445f86d4f3bbc3a5ee83d Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 8 Apr 2018 07:58:52 +0000 Subject: Buildsystem: Pass more methods to target buildsystems Signed-off-by: Niels Thykier --- debian/changelog | 9 +++++++++ lib/Debian/Debhelper/Buildsystem.pm | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/debian/changelog b/debian/changelog index b26fea92..8e7978e8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +debhelper (11.2.1) UNRELEASED; urgency=medium + + * Buildsystem.pm: Correctly pass build directory values to + target buildsystems. Thanks to Helmut Grohne, Adrian Bunk + and Tobias Frost for the reports and debugging. + (Closes: #895174, #895181) + + -- Niels Thykier Sun, 08 Apr 2018 07:13:22 +0000 + debhelper (11.2) unstable; urgency=medium [ Niels Thykier ] diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index cc3634fe..f546efb0 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -165,6 +165,11 @@ sub _set_builddir { } } $this->{builddir} = $builddir; + # Use get as guard because this method is (also) called from the + # constructor before the target build system is setup. + if ($this->get_targetbuildsystem) { + $this->get_targetbuildsystem->{builddir} = $builddir; + }; return $builddir; } @@ -229,6 +234,11 @@ sub enforce_in_source_building { $this->{warn_insource} = 1; $this->{builddir} = undef; } + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->enforce_in_source_building(@_); + # Only warn in once build system. + delete($this->{warn_insource}); + } } # Derived class can call this method in its constructor to *prefer* @@ -247,6 +257,9 @@ sub prefer_out_of_source_building { error("default build directory is the same as the source directory." . " Please specify a custom build directory"); } + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->prefer_out_of_source_building(@_); + } } } @@ -355,6 +368,9 @@ sub get_parallel { sub disable_parallel { my ($this) = @_; $this->{parallel} = 1; + if ($this->IS_GENERATOR_BUILD_SYSTEM) { + $this->get_targetbuildsystem->disable_parallel; + } } # When given a relative path to the build directory, converts it -- cgit v1.2.3 From 03ac69c9ec0a1ab6539993f1d52644adc639dcb5 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 8 Apr 2018 08:42:45 +0000 Subject: Buildsystems: Avoid picking a redundant build system during clean Signed-off-by: Niels Thykier --- debian/changelog | 7 +++++++ lib/Debian/Debhelper/Buildsystem.pm | 11 +++++++++++ lib/Debian/Debhelper/Buildsystem/cmake.pm | 2 +- lib/Debian/Debhelper/Buildsystem/makefile.pm | 5 ++--- lib/Debian/Debhelper/Buildsystem/meson.pm | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/debian/changelog b/debian/changelog index 8e7978e8..5320f5d1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,13 @@ debhelper (11.2.1) UNRELEASED; urgency=medium target buildsystems. Thanks to Helmut Grohne, Adrian Bunk and Tobias Frost for the reports and debugging. (Closes: #895174, #895181) + * Buildsystems: Avoid choosing a build system for the clean + step if it is not necessary. Previously, debhelper could + choose a "random" build system that would prefer building + in a separate build directory on the basis that the build + directory should be removed. With this, change we only + choose such a build system if there is a build directory + to remove. -- Niels Thykier Sun, 08 Apr 2018 07:13:22 +0000 diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index f546efb0..a9274063 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -399,6 +399,17 @@ sub mkdir_builddir { } } +sub check_auto_buildable_clean_oos_buildir { + my $this = shift; + my ($step) = @_; + # This only applies to clean + return 0 if $step ne 'clean'; + my $builddir = $this->get_builddir; + # If there is no builddir, then this rule does not apply. + return 0 if not defined($builddir) or not -d $builddir; + return 1; +} + sub _cd { my ($this, $dir)=@_; verbose_print("cd $dir"); diff --git a/lib/Debian/Debhelper/Buildsystem/cmake.pm b/lib/Debian/Debhelper/Buildsystem/cmake.pm index 9c4cdc30..bb977e4c 100644 --- a/lib/Debian/Debhelper/Buildsystem/cmake.pm +++ b/lib/Debian/Debhelper/Buildsystem/cmake.pm @@ -50,7 +50,7 @@ sub check_auto_buildable { if (-e $this->get_sourcepath("CMakeLists.txt")) { my $ret = ($step eq "configure" && 1) || $this->get_targetbuildsystem->check_auto_buildable(@_); - if ($step eq "clean" && defined($this->get_builddir())) { + if ($this->check_auto_buildable_clean_oos_buildir(@_)) { # Assume that the package can be cleaned (i.e. the build directory can # be removed) as long as it is built out-of-source tree and can be # configured. diff --git a/lib/Debian/Debhelper/Buildsystem/makefile.pm b/lib/Debian/Debhelper/Buildsystem/makefile.pm index 4443a991..a44fe192 100644 --- a/lib/Debian/Debhelper/Buildsystem/makefile.pm +++ b/lib/Debian/Debhelper/Buildsystem/makefile.pm @@ -134,9 +134,8 @@ sub check_auto_buildable { # This is always called in the source directory, but generally # Makefiles are created (or live) in the build directory. return 1; - } elsif ($step eq "clean" && defined $this->get_builddir() && - $this->check_auto_buildable("configure")) - { + } elsif ($this->check_auto_buildable_clean_oos_buildir(@_) + and $this->check_auto_buildable('configure')) { # Assume that the package can be cleaned (i.e. the build directory can # be removed) as long as it is built out-of-source tree and can be # configured. This is useful for derivative buildsystems which diff --git a/lib/Debian/Debhelper/Buildsystem/meson.pm b/lib/Debian/Debhelper/Buildsystem/meson.pm index d05336ec..c088ae0c 100644 --- a/lib/Debian/Debhelper/Buildsystem/meson.pm +++ b/lib/Debian/Debhelper/Buildsystem/meson.pm @@ -32,7 +32,7 @@ sub check_auto_buildable { # Handle configure explicitly; inherit the rest return 1 if $step eq "configure"; my $ret = $this->get_targetbuildsystem->check_auto_buildable(@_); - if ($ret == 0 and $step eq 'clean' and defined($this->get_builddir())) { + if ($ret == 0 and $this->check_auto_buildable_clean_oos_buildir(@_)) { # Assume that the package can be cleaned (i.e. the build directory can # be removed) as long as it is built out-of-source tree and can be # configured. -- cgit v1.2.3 From aa2b021cc68089efa5e969761eb3b21c74e9d96c Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 8 Apr 2018 09:41:14 +0000 Subject: Buildsystem.pm: Fix use of undefined variable Signed-off-by: Niels Thykier --- debian/changelog | 7 +++++++ lib/Debian/Debhelper/Buildsystem.pm | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/debian/changelog b/debian/changelog index 63a5a93e..874ea54f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +debhelper (11.2.2) UNRELEASED; urgency=medium + + * Buildsystem.pm: Fix use of undefined variable in certain + error conditions. + + -- Niels Thykier Sun, 08 Apr 2018 09:40:32 +0000 + debhelper (11.2.1) unstable; urgency=medium * Buildsystem.pm: Correctly pass build directory values to diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index a9274063..bc4e1b39 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -21,8 +21,10 @@ sub NAME { my $class = ref($this); my $target_name; if ($class) { - if ($this->IS_GENERATOR_BUILD_SYSTEM) { - $target_name = $this->{'targetbuildsystem'}->NAME; + # Do not assume that the target buildsystem has been provided. + # NAME could be called during an error in the constructor. + if ($this->IS_GENERATOR_BUILD_SYSTEM and $this->get_targetbuildsystem) { + $target_name = $this->get_targetbuildsystem->NAME; } } else { $class = $this; -- cgit v1.2.3 From 46fb3c5ba6ba48df2d59f6603d73ad159292d63c Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 8 Apr 2018 10:34:01 +0000 Subject: Buildsystem.pm: Fix typo in comment Signed-off-by: Niels Thykier --- lib/Debian/Debhelper/Buildsystem.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index bc4e1b39..330a2772 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -238,7 +238,7 @@ sub enforce_in_source_building { } if ($this->IS_GENERATOR_BUILD_SYSTEM) { $this->get_targetbuildsystem->enforce_in_source_building(@_); - # Only warn in once build system. + # Only warn in one build system. delete($this->{warn_insource}); } } -- cgit v1.2.3 From 45880bd5f0e94f5c154e1cc293dbcc408c16819d Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 8 Apr 2018 10:36:53 +0000 Subject: Buildsystem.pm: Set target buildsystem earlier Signed-off-by: Niels Thykier --- lib/Debian/Debhelper/Buildsystem.pm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index 330a2772..e7467b72 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -110,7 +110,23 @@ sub new { builddir => undef, parallel => undef, cwd => Cwd::getcwd() }, $class); + + # Setup the target buildsystem early, so e.g. _set_builddir also + # applies to the target build system. Useful if the generator + # and target does not agree on (e.g.) the default build dir. my $target_bs_name; + if (exists $opts{targetbuildsystem}) { + $target_bs_name = $opts{targetbuildsystem}; + } + + $target_bs_name //= $this->DEFAULT_TARGET_BUILD_SYSTEM if $this->IS_GENERATOR_BUILD_SYSTEM; + + if (defined($target_bs_name)) { + my %target_opts = %opts; + delete($target_opts{'targetbuildsystem'}); + my $target_system = load_buildsystem($target_bs_name, undef, %target_opts); + $this->set_targetbuildsystem($target_system); + } if (exists $opts{sourcedir}) { # Get relative sourcedir abs_path (without symlinks) @@ -126,18 +142,6 @@ sub new { if (defined $opts{parallel}) { $this->{parallel} = $opts{parallel}; } - if (exists $opts{targetbuildsystem}) { - $target_bs_name = $opts{targetbuildsystem}; - } - - $target_bs_name //= $this->DEFAULT_TARGET_BUILD_SYSTEM if $this->IS_GENERATOR_BUILD_SYSTEM; - - if (defined($target_bs_name)) { - my %target_opts = %opts; - delete($target_opts{'targetbuildsystem'}); - my $target_system = load_buildsystem($target_bs_name, undef, %target_opts); - $this->set_targetbuildsystem($target_system); - } return $this; } -- cgit v1.2.3 From eccf9c8d3b000dfd059a141a61a34bc44730cc46 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Fri, 18 May 2018 17:48:29 +0000 Subject: Dh_Lib.pm: Remove unused function Signed-off-by: Niels Thykier --- debian/changelog | 2 ++ lib/Debian/Debhelper/Buildsystem.pm | 8 -------- lib/Debian/Debhelper/Dh_Lib.pm | 14 -------------- 3 files changed, 2 insertions(+), 22 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/debian/changelog b/debian/changelog index 14638e48..81a1927e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -51,6 +51,8 @@ debhelper (11.3) UNRELEASED; urgency=medium the empty file on install if absent. Thanks to Rhonda D'Vine for suggesting the improvement. (Closes: #776853) * Dh_Lib.pm: Re-organise exports. + * Dh_Lib.pm: Retract "print_and_complex_doit"; the only potential + consumer went with a different code snippet. [ Dmitry Shachnev ] * qmake.pm: Use ${DEB_HOST_GNU_TYPE}-qmake wrapper for diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index e7467b72..456052c5 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -484,14 +484,6 @@ sub doit_in_builddir_noerror { return $this->_generic_doit_in_dir($this->get_buildpath, \&print_and_doit_noerror, @args); } -# Changes working directory to the build directory (if needed), -# calls print_and_complex_doit(@_) and changes working directory back to the -# top directory. -sub complex_doit_in_builddir { - my ($this, @args) = @_; - return $this->_in_dir($this->get_buildpath, \&print_and_complex_doit, @args); -} - # In case of out of source tree building, whole build directory # gets wiped (if it exists) and 1 is returned. If build directory # had 2 or more levels, empty parent directories are also deleted. diff --git a/lib/Debian/Debhelper/Dh_Lib.pm b/lib/Debian/Debhelper/Dh_Lib.pm index 69c21503..7da49443 100644 --- a/lib/Debian/Debhelper/Dh_Lib.pm +++ b/lib/Debian/Debhelper/Dh_Lib.pm @@ -55,7 +55,6 @@ qw( complex_doit escape_shell - print_and_complex_doit ), # Logging/messaging/error handling qw( @@ -524,19 +523,6 @@ sub complex_doit { } } -# Run a command and display the command to stdout except when quiet -# Use print_and_doit() if you can, instead of this function, because -# this function forks a shell. However, this function can handle more -# complicated stuff like redirection. -sub print_and_complex_doit { - nonquiet_print(join(" ",@_)); - - if (! $dh{NO_ACT}) { - # The join makes system get a scalar so it forks off a shell. - system(join(" ", @_)) == 0 || error_exitcode(join(" ", @_)) - } -} - sub error_exitcode { my $command=shift; -- cgit v1.2.3 From ef037f47be3a820c0df37118a82e8639100a0ebf Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 19 May 2018 09:15:57 +0000 Subject: Make Buildsystem.pm independent of Dh_Buildsystems.pm Signed-off-by: Niels Thykier --- debian/changelog | 4 ++++ lib/Debian/Debhelper/Buildsystem.pm | 24 ++++++++++++++++++++++-- lib/Debian/Debhelper/Dh_Buildsystems.pm | 21 ++------------------- 3 files changed, 28 insertions(+), 21 deletions(-) (limited to 'lib/Debian/Debhelper/Buildsystem.pm') diff --git a/debian/changelog b/debian/changelog index 2fe5caee..02dde1e3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -64,6 +64,10 @@ debhelper (11.3) UNRELEASED; urgency=medium accepts --sourcedir to overrule the default source directory (just like e.g. dh_install). Thanks to Robert Luberda for the suggestion. (Closes: #816332) + * Buildsystem.pm: Move code from Dh_Buildsystems.pm to Buildsystem.pm + to make the latter independent of the former. This makes it possible + to load Buildsystem.pm without debian/control being present. Thanks + to Andreas Tille for the bug report. (Closes: #897026) [ Dmitry Shachnev ] * qmake.pm: Use ${DEB_HOST_GNU_TYPE}-qmake wrapper for diff --git a/lib/Debian/Debhelper/Buildsystem.pm b/lib/Debian/Debhelper/Buildsystem.pm index 456052c5..8176c7bf 100644 --- a/lib/Debian/Debhelper/Buildsystem.pm +++ b/lib/Debian/Debhelper/Buildsystem.pm @@ -11,7 +11,6 @@ use warnings; use Cwd (); use File::Spec; use Debian::Debhelper::Dh_Lib; -use Debian::Debhelper::Dh_Buildsystems qw(load_buildsystem); # Build system name. Defaults to the last component of the class # name. Do not override this method unless you know what you are @@ -124,7 +123,7 @@ sub new { if (defined($target_bs_name)) { my %target_opts = %opts; delete($target_opts{'targetbuildsystem'}); - my $target_system = load_buildsystem($target_bs_name, undef, %target_opts); + my $target_system =_create_buildsystem_instance($target_bs_name, 1, %target_opts); $this->set_targetbuildsystem($target_system); } @@ -593,4 +592,25 @@ sub clean { } } + +sub _create_buildsystem_instance { + my ($full_name, $required, %bsopts) = @_; + my @parts = split(m{[+]}, $full_name, 2); + my $name = $parts[0]; + my $module = "Debian::Debhelper::Buildsystem::$name"; + if (@parts > 1) { + if (exists($bsopts{'targetbuildsystem'})) { + error("Conflicting target buildsystem for ${name} (load as ${full_name}, but target configured in bsopts)"); + } + $bsopts{'targetbuildsystem'} = $parts[1]; + } + + eval "use $module"; + if ($@) { + return if not $required; + error("unable to load build system class '$name': $@"); + } + return $module->new(%bsopts); +} + 1 diff --git a/lib/Debian/Debhelper/Dh_Buildsystems.pm b/lib/Debian/Debhelper/Dh_Buildsystems.pm index 6a008aa9..a386507c 100644 --- a/lib/Debian/Debhelper/Dh_Buildsystems.pm +++ b/lib/Debian/Debhelper/Dh_Buildsystems.pm @@ -8,6 +8,7 @@ package Debian::Debhelper::Dh_Buildsystems; use strict; use warnings; +use Debian::Debhelper::Buildsystem; use Debian::Debhelper::Dh_Lib; use File::Spec; @@ -45,25 +46,7 @@ my $opt_builddir; my $opt_list; my $opt_parallel; -sub create_buildsystem_instance { - my ($full_name, $required, %bsopts) = @_; - my @parts = split(m{[+]}, $full_name, 2); - my $name = $parts[0]; - my $module = "Debian::Debhelper::Buildsystem::$name"; - if (@parts > 1) { - if (exists($bsopts{'targetbuildsystem'})) { - error("Conflicting target buildsystem for ${name} (load as ${full_name}, but target configured in bsopts)"); - } - $bsopts{'targetbuildsystem'} = $parts[1]; - } - - eval "use $module"; - if ($@) { - return if not $required; - error("unable to load build system class '$name': $@"); - } - return $module->new(%bsopts); -} +*create_buildsystem_instance = \&Debian::Debhelper::Buildsystem::_create_buildsystem_instance; sub _insert_cmd_opts { my (%bsopts) = @_; -- cgit v1.2.3