Hello,

On penktadienis 13 Lapkritis 2009 13:12:36 Modestas Vainius wrote:
> On penktadienis 13 Lapkritis 2009 11:52:30 Modestas Vainius wrote:
> > On ketvirtadienis 12 Lapkritis 2009 22:47:57 Joey Hess wrote:
> > > Obviously yes, but I hope reordering (implicitly or explicitly) the
> > > build systems is not the only way to accomplish that.
> > >
> > > We could store the build system used for configure in
> > > debian/buildsystem.debhelper and have that override autodetection for
> > > the other steps.
> >
> > Yeah it would be, but... unfortunately that's not less troublesome
> > because:
> >
> > 1) dh_auto_configure might be called more than once with different --
> > sourcedirectory/--builddirectory options;
> > 2) dh_auto_configure might not be called at all (i.e. overrided);
> > 3) some build systems do not use configure step. So we would have to log
> >  build system usage at each step somehow.
> 
> Actually, I think I got a bit better idea which is a mix of yours and mine.
>  I will post a patch in ~6 hours from now but in short, auto-selection
>  process would look like:
> 
> 1) Do a simple check_auto_buildable() test (exactly like it is now - the
>  first check_auto_buildable() (based on the @BUILDSYSTEMS order) build
>  system is selected) for current step. If found it becomes the base one. If
>  not found, NO build system could be auto-selected, the process terminates.
> 
> 2) Then do the same simple check_auto_buildable() for all steps before
>  current one. E.g. if we are at dh_auto_install, collect
>  check_auto_buildable() results for "configure" and "build"
> 
> 3) Test all build systems found in 2) for isa() relationship against the
>  base one found in 1). The first one for which condition is true is assumed
>  to be auto-selected for current step. If the condition isn't true for
>  either, the base build system (found in 2) ) is assumed to be
>  auto-selected for current step.

The patch is attached. It is an optimized version of the same algorithm as 
written above with an additional condition in 3) (i.e. both isa(base) and 
check_auto_buildable(currentstep) must be true for a candidate build system). 
Read a patch header / code for a reworded description.

I hope you like it. I don't see how more safely we could do this.

-- 
Modestas Vainius <[email protected]>
From: Modestas Vainius <[email protected]>
Subject: [PATCH] Improve build system auto-selection process

This patch replaces current build system auto-selection process with the
following:

1) Find the first (in @BUILDSYSTEMS order) auto-buildable build system in
the current build step. If found, it becomes the base one. Otherwise,
auto-selection process fails.

2) Look for a more specific (i.e. deeper in the inheritance tree) build system
that is both auto-selectable in any build step coming before the current one
and auto-buildable in current one. If such a build system is found, auto-select
it for current step as well. Otherwise, auto-select the base build system found
in 1). Auto-selection process succeeds.

The patch implements optimized version of the algorithm above.

Signed-off-by: Modestas Vainius <[email protected]>

---
 Debian/Debhelper/Dh_Buildsystems.pm |   51 ++++++++++++++++++++++++++++++++--
 t/buildsystems/buildsystem_tests    |    4 +--
 2 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm
index a9a13a2..3172f9d 100644
--- a/Debian/Debhelper/Dh_Buildsystems.pm
+++ b/Debian/Debhelper/Dh_Buildsystems.pm
@@ -14,6 +14,8 @@ use File::Spec;
 use base 'Exporter';
 our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem &load_all_buildsystems);
 
+use constant BUILD_STEPS => qw(configure build test install clean);
+
 # Historical order must be kept for backwards compatibility. New
 # build systems MUST be added to the END of the list.
 our @BUILDSYSTEMS = (
@@ -54,6 +56,16 @@ sub create_buildsystem_instance {
 	return $module->new(%bsopts);
 }
 
+sub get_or_create_buildsystem_instance {
+	my $cache=shift;
+	my $system=shift;
+
+	if (!exists $cache->{$system}) {
+		$cache->{$system} = create_buildsystem_instance($system, @_);
+	}
+	return $cache->{$system};
+}
+
 # Similar to create_build system_instance(), but it attempts to autoselect
 # a build system if none was specified. In case autoselection fails, undef
 # is returned.
@@ -66,12 +78,45 @@ sub load_buildsystem {
 	}
 	else {
 		# Try to determine build system automatically
+		my $cache = {};
+		my $base;
+
+		# First of all, determine a base build system for this $step.
 		for $system (@BUILDSYSTEMS) {
-			my $inst = create_buildsystem_instance($system, @_);
+			my $inst = get_or_create_buildsystem_instance($cache, $system, @_);
 			if ($inst->check_auto_buildable($step)) {
-				return $inst;
+				$base = $inst;
+				last;
 			}
 		}
+
+		# Now look for a more specific build system that is auto-buildable in
+		# any previous and current steps.
+		if ($base) {
+			for my $prevstep (BUILD_STEPS) {
+				last if ($prevstep eq $step);
+
+				# Find the first build system that is auto-buildable in $prevstep.
+				my $cand;
+				for $system (@BUILDSYSTEMS) {
+					my $inst = get_or_create_buildsystem_instance($cache, $system, @_);
+					if ($inst->check_auto_buildable($prevstep)) {
+						$cand = $inst;
+						last;
+					}
+				}
+
+				# If a candidate build system is both more specific than the
+				# base build system, and auto-buildable in current step, it's
+				# the one we are looking for.
+				if ($cand && $cand->isa(ref $base) && $cand->check_auto_buildable($step)) {
+					$base = $cand;
+					last;
+				}
+			}
+		}
+
+		return $base;
 	}
 	return;
 }
@@ -189,7 +234,7 @@ sub buildsystems_do {
 		$step =~ s/^dh_auto_//;
 	}
 
-	if (grep(/^\Q$step\E$/, qw{configure build test install clean}) == 0) {
+	if (grep(/^\Q$step\E$/, BUILD_STEPS) == 0) {
 		error("unrecognized build step: " . $step);
 	}
 
diff --git a/t/buildsystems/buildsystem_tests b/t/buildsystems/buildsystem_tests
index 0465a93..fa6891e 100755
--- a/t/buildsystems/buildsystem_tests
+++ b/t/buildsystems/buildsystem_tests
@@ -347,9 +347,7 @@ cleandir $tmpdir;
 # CMake
 touch "$tmpdir/CMakeLists.txt";
 touch "$builddir/Makefile";
-test_autoselection("cmake",
-    { configure => "cmake", build => "makefile",
-      test => "makefile", install => "makefile", clean => "makefile" }, %tmp);
+test_autoselection("cmake", "cmake", %tmp);
 cleandir $tmpdir;
 
 ### Test Buildsystem::rmdir_builddir()
-- 
tg: (1679f2e..) patch/improved_bs_autoselection (depends on: master)

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to