summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Debian/Debhelper/Buildsystem.pm38
-rwxr-xr-xt/buildsystems/buildsystem_tests41
2 files changed, 34 insertions, 45 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
index ca43391f..babbd10d 100644
--- a/Debian/Debhelper/Buildsystem.pm
+++ b/Debian/Debhelper/Buildsystem.pm
@@ -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};
diff --git a/t/buildsystems/buildsystem_tests b/t/buildsystems/buildsystem_tests
index a2b451a9..27d7b943 100755
--- a/t/buildsystems/buildsystem_tests
+++ b/t/buildsystems/buildsystem_tests
@@ -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 {