]> git.donarmstrong.com Git - debhelper.git/commitdiff
Drop special handling for build directory ./path.
authorModestas Vainius <modestas@vainius.eu>
Fri, 12 Jun 2009 16:57:35 +0000 (19:57 +0300)
committerModestas Vainius <modestas@vainius.eu>
Sat, 13 Jun 2009 14:03:26 +0000 (17:03 +0300)
Now build directory is always relative to the top directory
(including default build directory) regardless what source
directory is. However, if the build directory is not specified,
it defaults to the source directory (aka in source building).

Signed-off-by: Modestas Vainius <modestas@vainius.eu>
Debian/Debhelper/Buildsystem.pm
t/buildsystems/buildsystem_tests

index ca43391fa607b08d0d2e796ea075dba7cc16c1e3..babbd10d332ab9b5b4ea076e3ac532cef6f12105 100644 (file)
@@ -46,11 +46,8 @@ sub DEFAULT_BUILD_DIRECTORY {
 #                  directory) where the sources to be built live. If not
 #                  specified or empty, defaults to the current directory.
 # - builddir -     specifies build directory to use. Path is relative to the
-#                  source directory unless it starts with ./, then it is
-#                  assumed to be relative to the top directory. If undef or
-#                  empty, DEFAULT_BUILD_DIRECTORY relative to the source
-#                  directory will be used. If not specified, in source build
-#                  will be attempted.
+#                  current (top) directory. If undef or empty,
+#                  DEFAULT_BUILD_DIRECTORY directory will be used. 
 # 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
@@ -83,20 +80,7 @@ sub new {
 sub _set_builddir {
        my $this=shift;
        my $builddir=shift;
-       if ($builddir) {
-               if ($builddir =~ m!^\./(.*)!) {
-                       # Specified as relative to the current directory
-                       $this->{builddir} = $1;
-               }
-               else {
-                       # Specified as relative to the source directory
-                       $this->{builddir} = $this->get_sourcepath($builddir);
-               }
-       }
-       else {
-               # Relative to the source directory by default
-               $this->{builddir} = $this->get_sourcepath($this->DEFAULT_BUILD_DIRECTORY());
-       }
+       $this->{builddir} = ($builddir) ? $builddir : $this->DEFAULT_BUILD_DIRECTORY;
 
        # Canonicalize. If build directory ends up the same as source directory, drop it
        if (defined $this->{builddir}) {
@@ -134,15 +118,18 @@ sub enforce_in_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.
+# out of source building even if the user didn't request it. However,
+# if $builddir is specified, accept it even if it matches the source
+# directory (soft mode).
 sub enforce_out_of_source_building {
        my ($this, $builddir) = @_;
        if (!defined $this->get_builddir()) {
                $this->_set_builddir($builddir);
-               # The build directory might have been dropped if it matched the
-               # source directory. Just set to default in this case.
-               if (!defined $this->get_builddir()) {
-                       $this->_set_builddir();
+               if (!defined $this->get_builddir() && !$builddir) {
+                       # If we are here, DEFAULT_BUILD_DIRECTORY matches
+                       # the source directory, building might fail.
+                       error("default build directory is the same as the source directory." .
+                             " Please specify a custom build directory");
                }
        }
 }
@@ -195,7 +182,8 @@ sub get_sourcepath {
 }
 
 # Get path to the build directory if it was specified
-# (relative to the current (top) directory). undef otherwise.
+# (relative to the current (top) directory). undef if the same
+# as the source directory.
 sub get_builddir {
        my $this=shift;
        return $this->{builddir};
index a2b451a96699f77a7079c1100da94bc0df053235..27d7b943c7cb9cc08b4dddaa373d401be736c188 100755 (executable)
@@ -126,24 +126,24 @@ $bs = $BS_CLASS->new(builddir => undef, sourcedir => "autoconf");
 %tmp = (
        "get_sourcedir()" => "autoconf",
        "get_sourcepath(a/b)" => "autoconf/a/b",
-       "get_builddir()" => "autoconf/$default_builddir",
-       "get_buildpath()" => "autoconf/$default_builddir",
-       "get_buildpath(a/b)" =>  "autoconf/$default_builddir/a/b",
-       "get_source_rel2builddir()" => "..",
-       "get_source_rel2builddir(a/b)" => "../a/b",
-       "get_build_rel2sourcedir()" => "$default_builddir",
-       "get_build_rel2sourcedir(a/b)" => "$default_builddir/a/b",
+       "get_builddir()" => "$default_builddir",
+       "get_buildpath()" => "$default_builddir",
+       "get_buildpath(a/b)" =>  "$default_builddir/a/b",
+       "get_source_rel2builddir()" => "../autoconf",
+       "get_source_rel2builddir(a/b)" => "../autoconf/a/b",
+       "get_build_rel2sourcedir()" => "../$default_builddir",
+       "get_build_rel2sourcedir(a/b)" => "../$default_builddir/a/b",
 );
 test_buildsystem_paths_api($bs, "default builddir, sourcedir=autoconf", \%tmp);
 
-# Enforced out of source tree building
+# Enforce "hard" out of source tree building
 # sourcedir=builddir=autoconf hence default builddir is implied
-$bs = $BS_CLASS->new(builddir => "./autoconf", sourcedir => "autoconf/");
+$bs = $BS_CLASS->new(builddir => "autoconf", sourcedir => "autoconf/");
 $bs->enforce_out_of_source_building();
-test_buildsystem_paths_api($bs, "out of source enforced, sourcedir=autoconf/", \%tmp);
+test_buildsystem_paths_api($bs, "hard out of source enforced, sourcedir=builddir", \%tmp);
 
 # sourcedir=autoconf (builddir should be dropped)
-$bs = $BS_CLASS->new(builddir => ".", sourcedir => "autoconf");
+$bs = $BS_CLASS->new(builddir => "autoconf", sourcedir => "autoconf");
 %tmp = (
        "get_sourcedir()" => "autoconf",
        "get_sourcepath(a/b)" => "autoconf/a/b",
@@ -157,13 +157,18 @@ $bs = $BS_CLASS->new(builddir => ".", sourcedir => "autoconf");
 );
 test_buildsystem_paths_api($bs, "no builddir, sourcedir=autoconf", \%tmp);
 
+# Enforce "soft" out of source tree building when
+# sourcedir=builddir=autoconf hence builddir should be dropped.
+$bs->enforce_out_of_source_building("autoconf");
+test_buildsystem_paths_api($bs, "soft out of source enforced, sourcedir=builddir", \%tmp);
+
 # builddir=bld/dir, sourcedir=autoconf. Should be the same as sourcedir=autoconf.
 $bs = $BS_CLASS->new(builddir => "bld/dir", sourcedir => "autoconf");
 $bs->enforce_in_source_building();
 test_buildsystem_paths_api($bs, "in source enforced, sourcedir=autoconf", \%tmp);
 
-# builddir=../bld/dir (relative to the sourcedir)
-$bs = $BS_CLASS->new(builddir => "../bld/dir/", sourcedir => "autoconf");
+# builddir=../bld/dir (relative to the curdir)
+$bs = $BS_CLASS->new(builddir => "bld/dir/", sourcedir => "autoconf");
 %tmp = (
        "get_sourcedir()" => "autoconf",
        "get_sourcepath(a/b)" => "autoconf/a/b",
@@ -177,10 +182,6 @@ $bs = $BS_CLASS->new(builddir => "../bld/dir/", sourcedir => "autoconf");
 );
 test_buildsystem_paths_api($bs, "builddir=../bld/dir, sourcedir=autoconf", \%tmp);
 
-# Builddir relative to the pwd (same path as above).
-$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;
@@ -220,7 +221,7 @@ $tmpdir = tempdir("tmp.XXXXXX");
 $builddir = "$tmpdir/builddir";
 mkdir $builddir;
 %tmp = (
-       builddir => 'builddir',
+       builddir => "$tmpdir/builddir",
        sourcedir => $tmpdir
 );
 
@@ -349,7 +350,7 @@ if (defined \$bs) {
 EOF
 }
 
-is_deeply( process_stdout("DH_AUTO_OPTIONS='--builddirectory=bld\\ dir --sourcedirectory autoconf' $^X -- -",
+is_deeply( process_stdout("DH_AUTO_OPTIONS='--builddirectory=autoconf/bld\\ dir --sourcedirectory autoconf' $^X -- -",
                           get_load_bs_source(undef, "configure")),
     [ 'NAME=autoconf', 'builddir=autoconf/bld dir', 'makecmd=make', 'sourcedir=autoconf' ],
     "dh_auto_options w/space, autoconf autoselection and sourcedir/builddir" );
@@ -375,7 +376,7 @@ sub dh_auto_do_autoconf {
        if ($builddir) {
                push @dh_auto_args, "-b", $builddir;
                $dh_auto_str .= " -b $builddir";
-               $buildpath .= "/$builddir";
+               $buildpath = $builddir;
        }
 
        my $do_dh_auto = sub {