[Bps-public-commit] r10367 - bpsbuilder/BPB/lib/BPB

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Jan 16 02:17:28 EST 2008


Author: sunnavy
Date: Wed Jan 16 02:17:27 2008
New Revision: 10367

Modified:
   bpsbuilder/BPB/lib/BPB/Backend.pm
   bpsbuilder/BPB/lib/BPB/Build.pm

Log:
not use __build or __test any more

Modified: bpsbuilder/BPB/lib/BPB/Backend.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Backend.pm	Wed Jan 16 02:17:27 2008
@@ -129,61 +129,51 @@
 sub install {
     my $dir = shift;
 
-    copy(
-        File::Spec->catfile( 'scripts', $dir, 'build' ),
-        File::Spec->catfile( 'dists', $dir, '__build' )
-    );
+    my @cmds;
+    {
+        open my $fh, '<', File::Spec->catfile( 'scripts', $dir, 'build' )
+          or die $!;
+        @cmds = <$fh>;
+        close $fh;
+        chomp @cmds;
+        @cmds = map { substitute($_) } @cmds;
+    }
 
     chdir File::Spec->catfile( 'dists', $dir );
 
-
-    if ( !-f '__build' ) {
-        warn "I have no idea how to build this distribution";
-        print $log "build $dir with failure: don't know how to build.\n";
-    }
-    else {
-        substitute('__build');
-        my (@cmds, $error);
-
-        {
-            open my $fh, '<', '__build' or die "can't open __build: $!";
-            @cmds = <$fh>;
-            chomp @cmds;
-        }
-
-        for (@cmds) {
-            my ( $type, $cmd );
-            next unless /\S/;
-
-            if (/^(\S+):\s*(.*)/) {
-                $type = $1;
-                $cmd  = $2;
-            }
-            else {
-                $type = '';
-                $cmd  = $_;
-            }
-
-            if ($args{'skip-test'} && $type eq 'test') {
-                print $log "skip build $type part in $dir\n";
-                next;
-            };
-
-            print $log "build $type part in $dir\n";
-
-            if ( system($cmd) ) {
-                print $log "build $dir with failure when run $type: $!\n";
-                $error = 1;
-            }
+    my $error;
+    for (@cmds) {
+        my ( $type, $cmd );
+        next unless /\S/;
+
+        if (/^(\S+):\s*(.*)/) {
+            $type = $1;
+            $cmd  = $2;
+        }
+        else {
+            $type = '';
+            $cmd  = $_;
         }
 
-        if ($error) {
-            print $log "build $dir with failure!\n";
+        if ( $args{'skip-test'} && $type eq 'test' ) {
+            print $log "skip build $type part in $dir\n";
+            next;
         }
-        else {
-            print $log "build $dir with success!\n";
+
+        print $log "build $type part in $dir\n";
+
+        if ( system($cmd) ) {
+            print $log "build $dir with failure when run $type: $!\n";
+            $error = 1;
         }
     }
+
+    if ($error) {
+        print $log "build $dir with failure!\n";
+    }
+    else {
+        print $log "build $dir with success!\n";
+    }
 }
 
 sub wrap_bin {
@@ -217,24 +207,14 @@
 }
 
 sub substitute {
-    my $file = shift;
-    return unless $file;
+    my $text = shift;
+    return unless $text;
 
-    my $text;
-    {
-        local $/;
-        open my $fh, '<', $file or die $!;
-        $text = <$fh>;
-        close $fh;
-    }
     my $perl         = $args{'perl'};
     my $install_base = $args{'install-base'};
     $text =~ s/%%PERL%%/$perl/g;
     $text =~ s/%%INSTALL_BASE%%/$install_base/g;
-
-    open my $fh, '>', $file or die $!;
-    print $fh $text;
-    close $fh;
+    return $text;
 }
 
 sub parse_order {
@@ -251,15 +231,33 @@
 
 sub test {
 
-    my ( $source, $target ) = (
-        File::Spec->catfile( 't', 'test' ),
-        File::Spec->catfile( 't', '__test' )
-    );
-    copy( $source, $target );
-    chmod 0755, $target;
-    substitute($target);
-    print "run tests: \n";
-    system($target);
+    my @cmds;
+    {
+        open my $fh, '<', File::Spec->catfile( 't', 'test' )
+          or die $!;
+        @cmds = <$fh>;
+        close $fh;
+        chomp @cmds;
+        @cmds = map { substitute($_) } @cmds;
+    }
+
+    for (@cmds) {
+        my ( $type, $cmd );
+        next unless /\S/;
+
+        if (/^(\S+):\s*(.*)/) {
+            $type = $1;
+            $cmd  = $2;
+        }
+        else {
+            $type = '';
+            $cmd  = $_;
+        }
+
+        print "run tests $type: \n";
+        system($cmd);
+    }
+
 }
 
 EOF

Modified: bpsbuilder/BPB/lib/BPB/Build.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Build.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Build.pm	Wed Jan 16 02:17:27 2008
@@ -86,22 +86,14 @@
 sub _install {
     my $self = shift;
     my $dir  = shift;
-    copy(
-        File::Spec->catfile( 'scripts', $dir, 'build' ),
-        File::Spec->catfile( 'dists',   $dir, '__build' )
-    );
 
-    chdir File::Spec->catfile( 'dists', $dir );
-    $self->_substitute('__build');
+    my @cmds = File::Spec->catfile( 'scripts', $dir, 'build' );
+    chomp @cmds;
+    @cmds = map { $self->substitute($_) } @cmds;
 
-    chmod 0755, '__build';
-    my ( @cmds, $error );
+    chdir File::Spec->catfile( 'dists', $dir );
 
-    {
-        open my $fh, '<', '__build' or die "can't open __build: $!";
-        @cmds = <$fh>;
-        chomp @cmds;
-    }
+    my $error;
 
     for (@cmds) {
         my ( $type, $cmd );
@@ -166,30 +158,42 @@
 
 sub _substitute {
     my $self = shift;
-    my $file = shift;
-    return unless $file;
+    my $text = shift;
+
+    return unless $text;
 
-    my $text         = read_file($file);
     my $perl         = $self->perl;
     my $install_base = $self->install_base;
     $text =~ s/%%PERL%%/$perl/g;
     $text =~ s/%%INSTALL_BASE%%/$install_base/g;
-    write_file( $file, $text );
+    return $text;
 }
 
 
 sub test {
     my $self = shift;
 
-    my ( $source, $target ) = (
-        File::Spec->catfile( 't', 'test' ),
-        File::Spec->catfile( 't', '__test' )
-    );
-    copy( $source, $target );
-    chmod 0755, $target;
-    $self->_substitute($target);
+    my @cmds = read_file(
+        File::Spec->catfile( 't', 'test' ));
+    chomp @cmds;
+    @cmds = map { $self->_substitute($_) } @cmds;
     $self->log->info( 'run tests:' );
-    BPB::Util->run( [ $target ] );
+
+    for (@cmds) {
+        my ( $type, $cmd );
+        next unless /\S/;
+
+        if (/^(\S+):\s*(.*)/) {
+            $type = $1;
+            $cmd  = $2;
+        }
+        else {
+            $type = '';
+            $cmd  = $_;
+        }
+        $self->log->info("run tests $type:");
+        system($cmd);
+    }
 }
 
 1;



More information about the Bps-public-commit mailing list