[Bps-public-commit] r10151 - bpsbuilder/BPB/lib/BPB/Script

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Dec 27 04:45:12 EST 2007


Author: sunnavy
Date: Thu Dec 27 04:45:11 2007
New Revision: 10151

Modified:
   bpsbuilder/BPB/lib/BPB/Script/Import.pm

Log:
generate build script when import

Modified: bpsbuilder/BPB/lib/BPB/Script/Import.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Import.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Import.pm	Thu Dec 27 04:45:11 2007
@@ -12,6 +12,7 @@
 use File::Spec;
 use BPB::Config;
 use File::Copy qw/copy/;
+use File::Temp qw/tempdir/;
 
 sub options {
     (
@@ -40,11 +41,22 @@
 
     $self->source( $bpb->source->run );
 
-    copy( $self->build_script, File::Spec->catfile( $self->source, '__build' ) )
-      if $self->build_script;
+    my $script_dir = tempdir( CLEANUP => 1 );
+
+    if ( my $script = $self->build_script ) {
+        copy( $self->build_script,
+            File::Spec->catfile( $script_dir, 'build' ) );
+    }
+    else {
+        $self->generate_build( $self->source, $script_dir, $bpb );
+    }
 
     $self->import_req( $self->source, $bpb );
     $bpb->backend->import( map { $_, $self->$_ } qw/comment source/ );
+    $bpb->backend->import(
+        source       => $self->source,
+        build_script => $script_dir,
+    );
 }
 
 sub import_req {
@@ -85,12 +97,57 @@
                     comment => 'deps for ' . $source,
                     source  => $s,
                 );
+                my $script_dir = tempdir( CLEANUP => 1 );
+                $self->generate_build( $s, $script_dir, $bpb );
+                $bpb->backend->import(
+                    source       => $s,
+                    build_script => $script_dir,
+                );
             }
         }
     }
 
 }
 
+sub generate_build {
+    my $self       = shift;
+    my $source_dir = shift;
+    my $script_dir = shift;
+    my $bpb = shift;
+
+    chdir $source_dir;
+
+    my @commands;
+    if ( -f 'configure' ) {
+        @commands =
+          ( './configure --prefix=%%INSTALL_BASE%%', 'make', 'make install' );
+    }
+    elsif ( -f 'Build.PL' ) {
+        push @commands,
+        $bpb->build->perl .  ' Build.PL --install_base=%%INSTALL_BASE%%';
+        unless ( $bpb->build->skip_test ) {
+            push @commands, "./Build test";
+        }
+        push @commands, "./Build install";
+    }
+    elsif ( -f 'Makefile.PL' ) {
+        push @commands,
+          $bpb->build->perl . ' Makefile.PL INSTALL_BASE=%%INSTALL_BASE%%';
+        unless ( $bpb->build->skip_test ) {
+            push @commands, 'make test';
+        }
+
+        push @commands, "make install";
+    }
+    else {
+        warn "I have no idea how to build this distribution";
+    }
+
+    open my $fh, '>', File::Spec->catfile( $script_dir, 'build' ) or die $@;
+    print $fh $_, "\n" for @commands;
+    close $fh;
+}
+
 sub parent_dir {
     my $source = shift;
     my @dirs   = File::Spec->splitdir($source);



More information about the Bps-public-commit mailing list