]> git.donarmstrong.com Git - debhelper.git/blobdiff - t/buildsystems/buildsystem_tests
Sometimes SIGINTing the test suite leaves Makefile behind.
[debhelper.git] / t / buildsystems / buildsystem_tests
index 2f9a146e6e33e0acf31e2dbcb74391af75a1ce15..1a9e21ca3508b4b81bf160c64dce310d8b1b936d 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-use Test::More tests => 281;
+use Test::More tests => 291;
 
 use strict;
 use warnings;
@@ -204,12 +204,6 @@ $bs = $BS_CLASS->new(builddir => "bld/dir/", sourcedir => "autoconf");
 );
 test_buildsystem_paths_api($bs, "builddir=../bld/dir, sourcedir=autoconf", \%tmp);
 
-### Test if all buildsystems can be loaded
-@bs = load_all_buildsystems([ $INC[0] ]);
-@tmp = map { $_->NAME() } @bs;
-ok(@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS >= 1, "some build systems are built in" );
-is_deeply( \@tmp, \@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS, "load_all_buildsystems() loads all built-in buildsystems" );
-
 ### Test check_auto_buildable() of each buildsystem
 sub test_check_auto_buildable {
        my $bs=shift;
@@ -229,14 +223,8 @@ sub test_check_auto_buildable {
                } elsif (exists $expected->{default}) {
                        $e = $expected->{default};
                }
-               if ($e) {
-                       ok( $bs->check_auto_buildable($step),
-                           $bs->NAME() . "($config): check_auto_buildable($step)" );
-               }
-               else {
-                       ok( ! $bs->check_auto_buildable($step),
-                           $bs->NAME() . "($config): ! check_auto_buildable($step)" );
-               }
+               is( $bs->check_auto_buildable($step), $e,
+                       $bs->NAME() . "($config): check_auto_buildable($step) == $e" );
        }
 }
 
@@ -248,15 +236,21 @@ mkdir $builddir;
        sourcedir => $tmpdir
 );
 
-$bs{autoconf} = load_buildsystem("autoconf", undef, %tmp);
-$bs{cmake} = load_buildsystem("cmake", undef, %tmp);
-$bs{perl_mm} = load_buildsystem("perl_makemaker", undef, %tmp);
-$bs = load_buildsystem("makefile", undef, %tmp);
+# Test if all buildsystems can be loaded
+@bs = load_all_buildsystems([ $INC[0] ], %tmp);
+@tmp = map { $_->NAME() } @bs;
+ok(@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS >= 1, "some build systems are built in" );
+is_deeply( \@tmp, \@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS, "load_all_buildsystems() loads all built-in buildsystems" );
 
-test_check_auto_buildable($bs{autoconf}, "no configure", 0);
-test_check_auto_buildable($bs{cmake}, "no CMakeLists.txt", 0);
-test_check_auto_buildable($bs{perl_mm}, "no Makefile.PL", 0);
-test_check_auto_buildable($bs, "no Makefile", 0);
+# check_auto_buildable() fails with numeric 0
+for $bs (@bs) {
+    test_check_auto_buildable($bs, "fails with numeric 0", 0);
+}
+
+%bs = ();
+for $bs (@bs) {
+    $bs{$bs->NAME()} = $bs;
+}
 
 touch "$tmpdir/configure", 0755;
 test_check_auto_buildable($bs{autoconf}, "configure", { configure => 1 });
@@ -265,54 +259,59 @@ touch "$tmpdir/CMakeLists.txt";
 test_check_auto_buildable($bs{cmake}, "CMakeLists.txt", { configure => 1 });
 
 touch "$tmpdir/Makefile.PL";
-test_check_auto_buildable($bs{perl_mm}, "Makefile.PL",
-    { configure => 1, install => 1 });
+test_check_auto_buildable($bs{perl_makemaker}, "Makefile.PL", { configure => 1 });
 
 # With Makefile
 touch "$builddir/Makefile";
-test_check_auto_buildable($bs, "Makefile", { configure => 0, default => 1 });
+test_check_auto_buildable($bs{makefile}, "Makefile", 1);
 test_check_auto_buildable($bs{autoconf}, "configure+Makefile", { configure => 1 });
 test_check_auto_buildable($bs{cmake}, "CMakeLists.txt+Makefile", 1);
+touch "$builddir/CMakeCache.txt"; # strong evidence that cmake was run
+test_check_auto_buildable($bs{cmake}, "CMakeCache.txt+Makefile", 2);
 
 # Makefile.PL forces in-source
 #(see note in check_auto_buildable() why always 1 here)
 unlink "$builddir/Makefile";
 touch "$tmpdir/Makefile";
-test_check_auto_buildable($bs{perl_mm}, "Makefile.PL+Makefile", 1);
+test_check_auto_buildable($bs{perl_makemaker}, "Makefile.PL+Makefile", 1);
 
 # Perl Build.PL - handles always
-$bs = load_buildsystem("perl_build", undef, %tmp);
-test_check_auto_buildable($bs, "no Build.PL", 0);
+test_check_auto_buildable($bs{perl_build}, "no Build.PL", 0);
 touch "$tmpdir/Build.PL";
-test_check_auto_buildable($bs, "Build.PL", { configure => 1 });
+test_check_auto_buildable($bs{perl_build}, "Build.PL", { configure => 1 });
 touch "$tmpdir/Build"; # forced in source
-test_check_auto_buildable($bs, "Build.PL+Build", 1);
+test_check_auto_buildable($bs{perl_build}, "Build.PL+Build", 1);
 
 # Python Distutils
-$bs = load_buildsystem("python_distutils", undef, %tmp);
-test_check_auto_buildable($bs, "no setup.py", 0);
+test_check_auto_buildable($bs{python_distutils}, "no setup.py", 0);
 touch "$tmpdir/setup.py";
-test_check_auto_buildable($bs, "setup.py", 1);
+test_check_auto_buildable($bs{python_distutils}, "setup.py", 1);
 
 cleandir($tmpdir);
 
 ### Now test if it can autoselect a proper buildsystem for a typical package
 sub test_autoselection {
-       my $system=shift;
+       my $testname=shift;
        my $expected=shift;
+       my %args=@_;
        for my $step (@STEPS) {
                my $bs = load_buildsystem(undef, $step, @_);
                my $e = $expected;
                $e = $expected->{$step} if ref $expected;
                if (defined $bs) {
-                       is( $bs->NAME(), $e, "autoselection($system): $step=".((defined $e)?$e:'undef') );
+                       is( $bs->NAME(), $e, "autoselection($testname): $step=".((defined $e)?$e:'undef') );
                }
                else {
-                       is ( undef, $e, "autoselection($system): $step=".((defined $e)?$e:'undef') );
+                       is ( undef, $e, "autoselection($testname): $step=".((defined $e)?$e:'undef') );
                }
+               &{$args{"code_$step"}}() if exists $args{"code_$step"};
        }
 }
 
+# Auto-select nothing when no supported build system can be found
+# (see #557006).
+test_autoselection("auto-selects nothing", undef, %tmp);
+
 # Autoconf
 touch "$tmpdir/configure", 0755;
 touch "$builddir/Makefile";
@@ -329,8 +328,7 @@ cleandir $tmpdir;
 
 # Makefile
 touch "$builddir/Makefile";
-test_autoselection("makefile", { build => "makefile", test => "makefile",
-               install => "makefile", clean => "makefile" }, %tmp);
+test_autoselection("makefile", "makefile", %tmp);
 cleandir $tmpdir;
 
 # Python Distutils
@@ -345,11 +343,28 @@ test_autoselection("perl_build", "perl_build", %tmp);
 cleandir $tmpdir;
 
 # CMake
+touch "$tmpdir/CMakeLists.txt";
+$tmp = sub {
+       touch "$builddir/Makefile";
+};
+test_autoselection("cmake without CMakeCache.txt",
+       { configure => "cmake", build => "makefile",
+         test => "makefile", install => "makefile", clean => "makefile" }, %tmp,
+       code_configure => $tmp);
+cleandir $tmpdir;
+
+touch "$tmpdir/CMakeLists.txt";
+$tmp = sub {
+       touch "$builddir/Makefile";
+       touch "$builddir/CMakeCache.txt";
+};
+test_autoselection("cmake with CMakeCache.txt",
+       "cmake", %tmp, code_configure => $tmp);
+cleandir $tmpdir;
+
 touch "$tmpdir/CMakeLists.txt";
 touch "$builddir/Makefile";
-test_autoselection("cmake",
-    { configure => "cmake", build => "makefile",
-      test => "makefile", install => "makefile", clean => "makefile" }, %tmp);
+test_autoselection("cmake and existing Makefile", "makefile", %tmp);
 cleandir $tmpdir;
 
 ### Test Buildsystem::rmdir_builddir()
@@ -406,16 +421,16 @@ EOF
 $tmp = Cwd::getcwd();
 # NOTE: disabling parallel building explicitly (it might get automatically
 # enabled if run under dpkg-buildpackage -jX) to make output deterministic.
-is_deeply( process_stdout("$^X -- - --builddirectory='autoconf/bld dir' --sourcedirectory autoconf --parallel=1",
+is_deeply( process_stdout("$^X -- - --builddirectory='autoconf/bld dir' --sourcedirectory autoconf --max-parallel=1",
                           get_load_bs_source(undef, "configure")),
     [ 'NAME=autoconf', 'builddir=autoconf/bld dir', "cwd=$tmp",  'makecmd=make', 'parallel=1', 'sourcedir=autoconf' ],
     "autoconf autoselection and sourcedir/builddir" );
 
-is_deeply( process_stdout("$^X -- - -Sautoconf -D autoconf --parallel=1", get_load_bs_source("autoconf", "build")),
+is_deeply( process_stdout("$^X -- - -Sautoconf -D autoconf --max-parallel=1", get_load_bs_source("autoconf", "build")),
     [ 'NAME=autoconf', 'builddir=undef', "cwd=$tmp", 'makecmd=make', 'parallel=1', 'sourcedir=autoconf' ],
     "forced autoconf and sourcedir" );
 
-is_deeply( process_stdout("$^X -- - -B -Sautoconf --parallel=1", get_load_bs_source("autoconf", "build")),
+is_deeply( process_stdout("$^X -- - -B -Sautoconf --max-parallel=1", get_load_bs_source("autoconf", "build")),
     [ 'NAME=autoconf', "builddir=$default_builddir", "cwd=$tmp", 'makecmd=make', 'parallel=1', 'sourcedir=.' ],
     "forced autoconf and default build directory" );
 
@@ -484,46 +499,46 @@ ok ( ! -e 'bld', "bld got deleted too" );
 #### Test parallel building and related options / routines
 @tmp = ( $ENV{MAKEFLAGS}, $ENV{DEB_BUILD_OPTIONS} );
 
-# Test is_make_jobserver_unavailable and clean_makeflags.
+# Test is_make_jobserver_unavailable and clean_jobserver_makeflags.
 
 $ENV{MAKEFLAGS} = "--jobserver-fds=103,104 -j";
 ok(is_make_jobserver_unavailable(), "unavailable jobserver" );
-clean_makeflags();
+clean_jobserver_makeflags();
 ok(! exists $ENV{MAKEFLAGS}, "unset makeflags");
 
 $ENV{MAKEFLAGS} = "-a --jobserver-fds=103,104 -j -b";
 ok(is_make_jobserver_unavailable(), "unavailable jobserver" );
-clean_makeflags();
+clean_jobserver_makeflags();
 is($ENV{MAKEFLAGS}, "-a -b", "clean makeflags");
 
 $ENV{MAKEFLAGS} = " --jobserver-fds=1,2 -j  ";
 ok(! is_make_jobserver_unavailable(), "available jobserver" );
-clean_makeflags();
+clean_jobserver_makeflags();
 ok(! exists $ENV{MAKEFLAGS}, "unset makeflags");
 
 $ENV{MAKEFLAGS} = "-a -j -b";
 ok(! is_make_jobserver_unavailable(), "no specified jobserver");
-clean_makeflags();
-is($ENV{MAKEFLAGS}, "-a -b", "clean makeflags");
+clean_jobserver_makeflags();
+is($ENV{MAKEFLAGS}, "-a -j -b", "clean makeflags does not remove -j");
 
 $ENV{MAKEFLAGS} = "-a --jobs -b";
 ok(! is_make_jobserver_unavailable(), "no specified jobserver");
-clean_makeflags();
-is($ENV{MAKEFLAGS}, "-a -b", "clean makeflags");
+clean_jobserver_makeflags();
+is($ENV{MAKEFLAGS}, "-a --jobs -b", "clean makeflags does not remove --jobs");
 
 $ENV{MAKEFLAGS} = "-j6";
 ok(! is_make_jobserver_unavailable(), "no specified jobserver");
-clean_makeflags();
-ok(! exists $ENV{MAKEFLAGS}, "unset makeflags");
+clean_jobserver_makeflags();
+is($ENV{MAKEFLAGS}, "-j6", "clean makeflags does not remove -j6");
 
 $ENV{MAKEFLAGS} = "-a -j6 --jobs=7";
 ok(! is_make_jobserver_unavailable(), "no specified jobserver");
-clean_makeflags();
-is($ENV{MAKEFLAGS}, "-a", "clean makeflags");
+clean_jobserver_makeflags();
+is($ENV{MAKEFLAGS}, "-a -j6 --jobs=7", "clean makeflags does not remove -j or --jobs");
 
 $ENV{MAKEFLAGS} = "-j6 --jobserver-fds=5,6 --jobs=8";
 ok(is_make_jobserver_unavailable(), "unavailable jobserver");
-clean_makeflags();
+clean_jobserver_makeflags();
 is($ENV{MAKEFLAGS}, "-j6 --jobs=8", "jobserver options removed");
 
 # Test parallel building with makefile build system.
@@ -557,33 +572,29 @@ sub test_is_parallel {
 
 test_isnt_parallel( do_parallel_mk(),
        "No parallel by default" );
-test_isnt_parallel( do_parallel_mk("--parallel"),
-       "No parallel by default with --parallel" );
 
 $ENV{DEB_BUILD_OPTIONS}="parallel=5";
 test_isnt_parallel( do_parallel_mk(),
-       "DEB_BUILD_OPTIONS=parallel=5 without --parallel" );
-test_is_parallel( do_parallel_mk("--parallel"),
-       "DEB_BUILD_OPTIONS=parallel=5 with --parallel" );
-test_is_parallel( do_parallel_mk("--parallel=2"),
-       "DEB_BUILD_OPTIONS=parallel=5 with --parallel=2" );
-test_isnt_parallel( do_parallel_mk("--parallel=1"),
-       "DEB_BUILD_OPTIONS=parallel=5 with --parallel=1 (off)" );
+       "DEB_BUILD_OPTIONS=parallel=5 without --max-parallel" );
+test_is_parallel( do_parallel_mk("--max-parallel=2"),
+       "DEB_BUILD_OPTIONS=parallel=5 with --max-parallel=2" );
+test_isnt_parallel( do_parallel_mk("--max-parallel=1"),
+       "DEB_BUILD_OPTIONS=parallel=5 with --max-parallel=1 (off)" );
 
 $ENV{MAKEFLAGS} = "--jobserver-fds=105,106 -j";
 $ENV{DEB_BUILD_OPTIONS}="";
-test_isnt_parallel( do_parallel_mk(),
+test_isnt_parallel( do_parallel_mk("--max-parallel=5"),
        "makefile.pm (no parallel): no make warnings about unavailable jobserver" );
 $ENV{DEB_BUILD_OPTIONS}="parallel=5";
-test_is_parallel( do_parallel_mk("--parallel"),
-       "DEB_BUILD_OPTIONS=parallel=5 with --parallel: no make warnings about unavail parent jobserver" );
+test_is_parallel( do_parallel_mk("--max-paralle=5"),
+       "DEB_BUILD_OPTIONS=parallel=5: no make warnings about unavail parent jobserver" );
 
 $ENV{MAKEFLAGS} = "-j2";
 $ENV{DEB_BUILD_OPTIONS}="";
-test_is_parallel( do_parallel_mk(),
-       "MAKEFLAGS=-j2 without --parallel: dh_auto_build honours MAKEFLAGS" );
-test_isnt_parallel( do_parallel_mk("--parallel=1"),
-       "MAKEFLAGS=-j2 with --parallel=1: dh_auto_build enforces -j1" );
+test_isnt_parallel( do_parallel_mk(),
+       "MAKEFLAGS=-j2: dh_auto_build ignores MAKEFLAGS" );
+test_isnt_parallel( do_parallel_mk("--max-parallel=1"),
+       "MAKEFLAGS=-j2 with --max-parallel=1: dh_auto_build enforces -j1" );
 
 # Test dh dpkg-buildpackage -jX detection
 sub do_rules_for_parallel {
@@ -593,113 +604,13 @@ sub do_rules_for_parallel {
                "make -f - $cmdline 2>&1 >/dev/null", $stdin);
 }
 
-# Simulate dpkg-buildpackage -j5
-doit("ln", "-s", "parallel.mk", "Makefile");
-
-sub test_dh_parallel {
-       my $extra_dsc=shift || "";
-       my $debian_rules=shift || "";
-       my $rules;
-       my $tmpfile;
-
-       $ENV{MAKEFLAGS} = "-j5";
-       $ENV{DEB_BUILD_OPTIONS} = "parallel=5";
-
-       # Write debian/rules if requested
-       $tmpfile = write_debian_rules($debian_rules);
-
-       $rules = <<'EOF';
-%:
-       @dh_clean > /dev/null 2>&1
-       @dh --buildsystem=makefile --after=dh_auto_configure --until=dh_auto_build $@
-       @dh_clean > /dev/null 2>&1
-EOF
-       test_is_parallel( do_rules_for_parallel("build", $rules),
-               "dh adds --parallel implicitly under dpkg-buildpackage -j5 $extra_dsc");
-
-       $ENV{MAKEFLAGS} = "";
-       test_isnt_parallel( do_rules_for_parallel("build", $rules),
-               "DEB_BUILD_OPTIONS=parallel=5 without MAKEFLAGS=-jX via dh $extra_dsc" );
-
-       $ENV{MAKEFLAGS} = "-j5";
-       $rules = <<'EOF';
-%:
-       @dh_clean > /dev/null 2>&1
-       @dh -j1 --buildsystem=makefile --after=dh_auto_configure --until=dh_auto_build $@
-       @dh_clean > /dev/null 2>&1
-EOF
-       test_isnt_parallel( do_rules_for_parallel("build", $rules),
-               "dh -j1 disables implicit parallel under dpkg-buildpackage -j5 $extra_dsc");
+doit("ln", "-sf", "parallel.mk", "Makefile");
 
-       $rules = <<'EOF';
-%:
-       @dh_clean > /dev/null 2>&1
-       @dh -j --buildsystem=makefile --after=dh_auto_configure --until=dh_auto_build $@
-       @dh_clean > /dev/null 2>&1
-EOF
-       test_is_parallel( do_rules_for_parallel("build", $rules),
-               "dh -j under dpkg-buildpackage -j5 is parallel $extra_dsc");
-       $ENV{MAKEFLAGS} = "";
-       test_is_parallel( do_rules_for_parallel("build", $rules),
-               "dh -j is parallel only with DEB_BUILD_OPTIONS=parallel=5 $extra_dsc");
-
-       if (defined $tmpfile) {
-               rename($tmpfile, "debian/rules");
-       }
-       elsif ($debian_rules) {
-               unlink("debian/rules");
-       }
-}
-
-# dh should pass the same tests with and without overrides
-test_dh_parallel();
-test_dh_parallel("(with overrides)", <<'EOF');
-#!/usr/bin/make -f
-override_dh_auto_build:
-       @dh_auto_build -- -f parallel.mk
-EOF
-
-# Test if legacy punctuation hacks (+) work as before
+# Test if dh+override+$(MAKE) legacy punctuation hack work as before
 $ENV{MAKEFLAGS} = "-j5";
 $ENV{DEB_BUILD_OPTIONS} = "parallel=5";
-$tmp = write_debian_rules(<<'EOF');
-#!/usr/bin/make -f
-%:
-       @dh_clean > /dev/null 2>&1
-       @+dh --buildsystem=makefile --after=dh_auto_configure --until=dh_auto_build $@
-       @dh_clean > /dev/null 2>&1
-EOF
-test_is_parallel( do_rules_for_parallel("build", "include debian/rules"),
-       "legacy punctuation hacks: +dh, no override" );
-unlink "debian/rules";
 
-write_debian_rules(<<'EOF');
-#!/usr/bin/make -f
-override_dh_auto_build:
-       dh_auto_build
-%:
-       @dh_clean > /dev/null 2>&1
-       @+dh --buildsystem=makefile --after=dh_auto_configure --until=dh_auto_build $@
-       @dh_clean > /dev/null 2>&1
-EOF
-test_isnt_parallel( do_rules_for_parallel("build", "include debian/rules"),
-       "legacy punctuation hacks: +dh, override without +, no parallel, no make warnings" );
-unlink "debian/rules";
-
-write_debian_rules(<<'EOF');
-#!/usr/bin/make -f
-override_dh_auto_build:
-       +dh_auto_build
-%:
-       @dh_clean > /dev/null 2>&1
-       @+dh --buildsystem=makefile --after=dh_auto_configure --until=dh_auto_build $@
-       @dh_clean > /dev/null 2>&1
-EOF
-test_is_parallel( do_rules_for_parallel("build", "include debian/rules"),
-       "legacy punctuation hacks: +dh, override with +" );
-unlink "debian/rules";
-
-write_debian_rules(<<'EOF');
+$tmp = write_debian_rules(<<'EOF');
 #!/usr/bin/make -f
 override_dh_auto_build:
        $(MAKE)